X-Git-Url: http://git.scottworley.com/tl-append/blobdiff_plain/d522116b5fdc09e3f83fe4f88515dec52a3e0462..8559ce1136794185462cc2c374e4c6844a19f865:/common.c?ds=sidebyside diff --git a/common.c b/common.c index ffa4b5a..747111b 100644 --- a/common.c +++ b/common.c @@ -1,7 +1,10 @@ +#define _POSIX_C_SOURCE 2 +#include "common.h" + #include #include -const char *FILENAME = "tl.log"; +const char *const FILENAME = "tl.log"; void die(const char *message) { fputs(message, stderr); @@ -13,3 +16,13 @@ void die_err(const char *message) { 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; +}