status-time/time.c
changeset 1 3e9290bf7249
child 10 442bed4a072e
equal deleted inserted replaced
0:a22a319f5129 1:3e9290bf7249
       
     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"
       
    11 
       
    12 int
       
    13 main(void)
       
    14 {
       
    15     char buf[129];
       
    16     time_t tim;
       
    17     struct tm *timtm;
       
    18 
       
    19     setenv("TZ", TIMEZONE, 1);
       
    20 
       
    21     while (1) {
       
    22         bzero(buf, sizeof(buf));
       
    23 	tim = time(NULL);
       
    24 	timtm = localtime(&tim);
       
    25 	if (timtm == NULL) {
       
    26 		perror("localtime");
       
    27 		exit(1);
       
    28 	}
       
    29 
       
    30 	if (!strftime(buf, sizeof(buf)-1, TIMEFORMAT, timtm)) {
       
    31 		fprintf(stderr, "strftime == 0\n");
       
    32 		exit(1);
       
    33 	}
       
    34 	printf("%s\n", buf);
       
    35 	fflush(stdout);
       
    36 	sleep(UPDATE_PERIOD);
       
    37     }
       
    38 }