]> git.scottworley.com Git - tl-append/blobdiff - common.c
Release 1.0.1
[tl-append] / common.c
index ffa4b5a8f056a2dd6604cf885441507db64b9db9..5f4d9936c09bd4e9e6af81a3c5b1d3f8c6712184 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1,7 +1,27 @@
+/*
+ * tl-append: time-logger appending shell
+ * Copyright (C) 2023  Scott Worley <scottworley@scottworley.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#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);
@@ -13,3 +33,13 @@ void die_err(const char *message) {
   perror(message);
   exit(1);
 }
+
+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;
+}