]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_time.c
Properly output JSON with libyajl
[i3/i3status] / src / print_time.c
index 2cf2ab3ad22e8bb73f69f0b6865cf6af0d1ea5c1..a1bb34cdf3e089d0a4fef62cd0c3bea05b274910 100644 (file)
@@ -2,18 +2,16 @@
 #include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <yajl/yajl_gen.h>
 
-void print_time(const char *format) {
-        static char part[512];
-        /* Get date & time */
-        time_t current_time = time(NULL);
-        if (current_time == (time_t) -1) {
-                return;
-        }
-        struct tm *current_tm = localtime(&current_time);
-        if (current_tm == NULL) {
+#include "i3status.h"
+
+void print_time(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm) {
+        char *outwalk = buffer;
+        if (current_tm == NULL)
                 return;
-        }
-        (void)strftime(part, sizeof(part), format, current_tm);
-        printf("%s", part);
+        /* Get date & time */
+        outwalk += strftime(outwalk, 4095, format, current_tm);
+        *outwalk = '\0';
+        OUTPUT_FULL_TEXT(buffer);
 }