2011-05-23 18:00:31 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2011-05-24 00:13:34 +00:00
|
|
|
#include <unistd.h>
|
2011-05-23 18:00:31 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2011-05-24 00:13:34 +00:00
|
|
|
char buf[BUFSIZ], c;
|
2011-05-23 18:00:31 +00:00
|
|
|
char *fmt = "%c";
|
|
|
|
struct tm *now = NULL;
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
t = time(NULL);
|
2011-05-24 00:13:34 +00:00
|
|
|
while((c = getopt(argc, argv, "d:")) != -1)
|
|
|
|
switch(c) {
|
|
|
|
case 'd':
|
|
|
|
t = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if(optind < argc && argv[optind][0] == '+')
|
|
|
|
fmt = &argv[optind][1];
|
|
|
|
if(!(now = localtime(&t)))
|
2011-05-23 18:00:31 +00:00
|
|
|
eprintf("localtime failed\n");
|
|
|
|
|
|
|
|
strftime(buf, sizeof buf, fmt, now);
|
|
|
|
puts(buf);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|