]> git.scottworley.com Git - tl-append/blob - common.c
88e7b73d0e5d893104c76edf108526d0f79f88de
[tl-append] / common.c
1 #define _POSIX_C_SOURCE 2
2 #include "common.h"
3
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 const char *const FILENAME = "tl.log";
8
9 void die(const char *message) {
10 fputs(message, stderr);
11 fputc('\n', stderr);
12 exit(1);
13 }
14
15 void die_err(const char *message) {
16 perror(message);
17 exit(1);
18 }
19
20 char *encode_time(time_t t) {
21 struct tm tm;
22 localtime_r(&t, &tm);
23 const size_t size = 20;
24 char *out = (char *)malloc(size);
25 if (strftime(out, size, "%Y %m %d %H %M %S", &tm) != size - 1)
26 die("Couldn't format time");
27 return out;
28 }