-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdate.c
More file actions
39 lines (36 loc) · 769 Bytes
/
date.c
File metadata and controls
39 lines (36 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "util.h"
int
main(int argc, char *argv[])
{
char buf[BUFSIZ], c;
char *fmt = "%c";
struct tm *now = NULL;
struct tm *(*tztime)(const time_t *) = localtime;
const char *tz = "local";
time_t t;
t = time(NULL);
while((c = getopt(argc, argv, "d:u")) != -1)
switch(c) {
case 'd':
t = estrtol(optarg, 0);
break;
case 'u':
tztime = gmtime;
tz = "gm";
break;
default:
exit(EXIT_FAILURE);
}
if(optind < argc && argv[optind][0] == '+')
fmt = &argv[optind][1];
if(!(now = tztime(&t)))
eprintf("%stime failed\n", tz);
strftime(buf, sizeof buf, fmt, now);
puts(buf);
return EXIT_SUCCESS;
}