1
|
1 |
#define _DEFAULT_SOURCE
|
|
2 |
#include <stdio.h>
|
|
3 |
#include <stdlib.h>
|
|
4 |
#include <unistd.h>
|
|
5 |
#include <strings.h>
|
|
6 |
#include <sys/time.h>
|
|
7 |
#include <errno.h>
|
|
8 |
#include <time.h>
|
|
9 |
|
|
10 |
#include "config.h"
|
10
|
11 |
#ifdef LOCALE
|
|
12 |
#include <locale.h>
|
|
13 |
#endif
|
1
|
14 |
|
|
15 |
int
|
|
16 |
main(void)
|
|
17 |
{
|
|
18 |
char buf[129];
|
|
19 |
time_t tim;
|
|
20 |
struct tm *timtm;
|
10
|
21 |
#ifdef LOCALE
|
|
22 |
setlocale(LC_TIME, LOCALE);
|
|
23 |
#endif
|
1
|
24 |
|
|
25 |
setenv("TZ", TIMEZONE, 1);
|
|
26 |
|
|
27 |
while (1) {
|
|
28 |
bzero(buf, sizeof(buf));
|
|
29 |
tim = time(NULL);
|
|
30 |
timtm = localtime(&tim);
|
|
31 |
if (timtm == NULL) {
|
|
32 |
perror("localtime");
|
|
33 |
exit(1);
|
|
34 |
}
|
|
35 |
|
|
36 |
if (!strftime(buf, sizeof(buf)-1, TIMEFORMAT, timtm)) {
|
|
37 |
fprintf(stderr, "strftime == 0\n");
|
|
38 |
exit(1);
|
|
39 |
}
|
|
40 |
printf("%s\n", buf);
|
|
41 |
fflush(stdout);
|
|
42 |
sleep(UPDATE_PERIOD);
|
|
43 |
}
|
|
44 |
}
|