author | Stiletto <blasux@blasux.ru> |
Sat, 17 Aug 2019 15:27:14 +0400 | |
changeset 19 | bf780d158f3e |
parent 17 | 5b6294779007 |
permissions | -rw-r--r-- |
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 |
|
17
5b6294779007
[status-time] Support NOT changing timezone
Stiletto <blasux@blasux.ru>
parents:
10
diff
changeset
|
25 |
#ifdef TIMEZONE |
1 | 26 |
setenv("TZ", TIMEZONE, 1); |
17
5b6294779007
[status-time] Support NOT changing timezone
Stiletto <blasux@blasux.ru>
parents:
10
diff
changeset
|
27 |
#endif |
1 | 28 |
|
29 |
while (1) { |
|
30 |
bzero(buf, sizeof(buf)); |
|
31 |
tim = time(NULL); |
|
32 |
timtm = localtime(&tim); |
|
33 |
if (timtm == NULL) { |
|
34 |
perror("localtime"); |
|
35 |
exit(1); |
|
36 |
} |
|
37 |
||
38 |
if (!strftime(buf, sizeof(buf)-1, TIMEFORMAT, timtm)) { |
|
39 |
fprintf(stderr, "strftime == 0\n"); |
|
40 |
exit(1); |
|
41 |
} |
|
42 |
printf("%s\n", buf); |
|
43 |
fflush(stdout); |
|
44 |
sleep(UPDATE_PERIOD); |
|
45 |
} |
|
46 |
} |