Xinqi Bao's Git

fflush(stdout) to print line by line if stdout is not a tty
[slstatus.git] / components / datetime.c
1 /* See LICENSE file for copyright and license details. */
2 #include <stdio.h>
3 #include <time.h>
4
5 #include "../util.h"
6
7 const char *
8 datetime(const char *fmt)
9 {
10 time_t t;
11
12 t = time(NULL);
13 if (!strftime(buf, sizeof(buf), fmt, localtime(&t))) {
14 fprintf(stderr, "strftime: Result string exceeds buffer size\n");
15 return NULL;
16 }
17
18 return buf;
19 }