summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-10-04 18:45:42 +0200
committerPeter Wu <lekensteyn@gmail.com>2013-10-04 18:45:42 +0200
commit521a4d6351b6dadd0a9ebe2db9acf78d4df322af (patch)
tree13289b1d9c20c85676af283ea1d6d32161593390
parent94510035fe0b45f6c2fb0b6d3b195f2c4fefe8b6 (diff)
downloadc-files-521a4d6351b6dadd0a9ebe2db9acf78d4df322af.tar.gz
timeadd: Adds a timestamp before every line
-rw-r--r--Makefile2
-rw-r--r--timeadd.c31
2 files changed, 32 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 41c3812..c5daf30 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ xcbviewfs: xcbviewfs.c colorlookup.c
$(CC) $(XCBV_CFLAGS) -o $@ $< colorlookup.c $(XCBV_LDFLAGS)
%: %.c
- $(CC) -g -Wall -Werror -Wextra -o $(OUTDIR)$@ $<
+ $(CC) -g -Wall -Werror -Wextra $(CFLAGS) -o $(OUTDIR)$@ $<
colorlookup.c: $(RGB_TXT) colorlookupgen
./colorlookupgen $(RGB_TXT) > $@
diff --git a/timeadd.c b/timeadd.c
new file mode 100644
index 0000000..061a0ae
--- /dev/null
+++ b/timeadd.c
@@ -0,0 +1,31 @@
+/*
+ * Adds a timestamp before every line.
+ *
+ * Author: Peter Wu <lekensteyn@gmail.com>
+ * Date: 2013-10-04
+ */
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+#include <stdlib.h>
+
+int main() {
+ char buf[4096];
+
+ while (fgets(buf, sizeof(buf), stdin) != NULL) {
+ char *newline = strrchr(buf, '\n');
+ struct timespec tp;
+
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+
+ if (newline)
+ *newline = '\0';
+
+ printf("[%5llu.%06lu] %s\n",
+ (long long) tp.tv_sec,
+ tp.tv_nsec / 1000,
+ buf);
+ }
+
+ return 0;
+}