status-time/time.c
changeset 1 3e9290bf7249
child 10 442bed4a072e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/status-time/time.c	Mon Oct 20 22:59:08 2014 +0400
@@ -0,0 +1,38 @@
+#define _DEFAULT_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <strings.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <time.h>
+
+#include "config.h"
+
+int
+main(void)
+{
+    char buf[129];
+    time_t tim;
+    struct tm *timtm;
+
+    setenv("TZ", TIMEZONE, 1);
+
+    while (1) {
+        bzero(buf, sizeof(buf));
+	tim = time(NULL);
+	timtm = localtime(&tim);
+	if (timtm == NULL) {
+		perror("localtime");
+		exit(1);
+	}
+
+	if (!strftime(buf, sizeof(buf)-1, TIMEFORMAT, timtm)) {
+		fprintf(stderr, "strftime == 0\n");
+		exit(1);
+	}
+	printf("%s\n", buf);
+	fflush(stdout);
+	sleep(UPDATE_PERIOD);
+    }
+}