]> git.scottworley.com Git - tl-append/blobdiff - common.c
test: factor out verify_line()
[tl-append] / common.c
index ffa4b5a8f056a2dd6604cf885441507db64b9db9..1bc1102c001aa023d4eea1e9ebc0dda0ff516d05 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1,3 +1,6 @@
+#define _POSIX_C_SOURCE 2
+#include "common.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -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;
+}