tdate.c - spoon - [fork] customized build of spoon, the dwm status utility
(HTM) git clone git://src.adamsgaard.dk/spoon
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
tdate.c (516B)
---
1 #include <sys/types.h>
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <time.h>
6
7 #include "types.h"
8
9 int
10 dateread(void *arg, char *buf, size_t len)
11 {
12 struct datearg *datearg = arg;
13 struct tm *now;
14 char *oldtz;
15 time_t t;
16
17 oldtz = getenv("TZ");
18 if (datearg->tz != NULL && setenv("TZ", datearg->tz, 1) == 0)
19 tzset();
20 t = time(NULL);
21 now = localtime(&t);
22 if (oldtz != NULL)
23 setenv("TZ", oldtz, 1);
24 else
25 unsetenv("TZ");
26 if (now == NULL)
27 return -1;
28 strftime(buf, len, datearg->fmt, now);
29 return 0;
30 }