aboutsummaryrefslogtreecommitdiffstats
path: root/timeprefix.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-12-09 18:03:21 +0100
committerMattias Andrée <maandree@kth.se>2017-12-09 18:03:21 +0100
commit0aa122af455ab6f27f2917e2ab25a09ce79f25a9 (patch)
treefcadb51f46043a71d59fa7bccb4de5e16b33e464 /timeprefix.c
parentm (diff)
downloadtimeprefix-0aa122af455ab6f27f2917e2ab25a09ce79f25a9.tar.gz
timeprefix-0aa122af455ab6f27f2917e2ab25a09ce79f25a9.tar.bz2
timeprefix-0aa122af455ab6f27f2917e2ab25a09ce79f25a9.tar.xz
Cleanup, improve makefile, and change license
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'timeprefix.c')
-rw-r--r--timeprefix.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/timeprefix.c b/timeprefix.c
new file mode 100644
index 0000000..1b2544b
--- /dev/null
+++ b/timeprefix.c
@@ -0,0 +1,39 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+static void
+printline(const char *line)
+{
+ static struct timespec boottime;
+ time_t realtime;
+ struct tm *utctime;
+
+ clock_gettime(CLOCK_BOOTTIME, &boottime);
+ realtime = time(NULL);
+ utctime = gmtime(&realtime);
+
+ printf("[%010lu.%04lu %i-%02i-%02i %02i:%02i:%02i UTC] %s",
+ boottime.tv_sec, boottime.tv_nsec / 100000,
+ utctime->tm_year + 1900, utctime->tm_mon + 1, utctime->tm_mday,
+ utctime->tm_hour, utctime->tm_min, utctime->tm_sec,
+ line);
+
+ fflush(stdout);
+}
+
+int
+main(void)
+{
+ char *buf = NULL;
+ size_t siz = 0;
+
+ printline("--- Program started ---\n");
+ while (getline(&buf, &siz, stdin) != -1)
+ printline(buf);
+ printline("--- Program exited ---\n");
+
+ free(buf);
+ return 0;
+}