status-time/time.c
author Stiletto <blasux@blasux.ru>
Thu, 23 Oct 2014 19:32:57 +0400
changeset 8 028758fdeab2
parent 1 3e9290bf7249
child 10 442bed4a072e
permissions -rw-r--r--
Added tag 0.03 for changeset c0ca2b08f061

#define _DEFAULT_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <sys/time.h>
#include <errno.h>
#include <time.h>

#include "config.h"

int
main(void)
{
    char buf[129];
    time_t tim;
    struct tm *timtm;

    setenv("TZ", TIMEZONE, 1);

    while (1) {
        bzero(buf, sizeof(buf));
	tim = time(NULL);
	timtm = localtime(&tim);
	if (timtm == NULL) {
		perror("localtime");
		exit(1);
	}

	if (!strftime(buf, sizeof(buf)-1, TIMEFORMAT, timtm)) {
		fprintf(stderr, "strftime == 0\n");
		exit(1);
	}
	printf("%s\n", buf);
	fflush(stdout);
	sleep(UPDATE_PERIOD);
    }
}