From 521a4d6351b6dadd0a9ebe2db9acf78d4df322af Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 4 Oct 2013 18:45:42 +0200 Subject: timeadd: Adds a timestamp before every line --- timeadd.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 timeadd.c (limited to 'timeadd.c') 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 + * Date: 2013-10-04 + */ +#include +#include +#include +#include + +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; +} -- cgit v1.2.1