+#define _POSIX_C_SOURCE 2
+#include "common.h"
+
#include <stdio.h>
#include <stdlib.h>
-const char *FILENAME = "tl.log";
+const char *const FILENAME = "tl.log";
void die(const char *message) {
fputs(message, stderr);
perror(message);
exit(1);
}
+
+const char *encode_time(time_t t) {
+ struct tm tm;
+ localtime_r(&t, &tm);
+ const size_t size = 20;
+ char *out = (char *)malloc(size);
+ if (strftime(out, size, "%Y %m %d %H %M %S", &tm) != size - 1)
+ die("Couldn't format time");
+ return out;
+}