Audit date(1)

1) Update usage as already done in the manpage
2) group and sort local variable declarations
3) Be pedantic about the number of options. Don't just ignore it
   if argc > 1.
This commit is contained in:
FRIGN 2015-03-02 15:12:19 +01:00
parent 27656a0cbc
commit e50ee15a9c
2 changed files with 11 additions and 8 deletions

2
README
View File

@ -23,7 +23,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
= cp yes none (-i) = cp yes none (-i)
=* cron non-posix none =* cron non-posix none
#* cut yes none #* cut yes none
=* date yes -u =*| date yes none
=*| dirname yes none =*| dirname yes none
=* du yes none =* du yes none
=*| echo yes none =*| echo yes none

15
date.c
View File

@ -8,20 +8,19 @@
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-u] [-d format] [+FORMAT]\n", argv0); eprintf("usage: %s [-u] [-d time] [+format]\n", argv0);
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char buf[BUFSIZ]; struct tm *now;
char *fmt = "%c";
struct tm *now = NULL;
struct tm *(*tztime)(const time_t *) = localtime; struct tm *(*tztime)(const time_t *) = localtime;
const char *tz = "local";
time_t t; time_t t;
char buf[BUFSIZ], *fmt = "%c", *tz = "local";
t = time(NULL); t = time(NULL);
ARGBEGIN { ARGBEGIN {
case 'd': case 'd':
t = estrtonum(EARGF(usage()), 0, LLONG_MAX); t = estrtonum(EARGF(usage()), 0, LLONG_MAX);
@ -34,8 +33,12 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc > 0 && argv[0][0] == '+') if (argc) {
if (argc != 1 || argv[0][0] != '+')
usage();
else
fmt = &argv[0][1]; fmt = &argv[0][1];
}
if (!(now = tztime(&t))) if (!(now = tztime(&t)))
eprintf("%stime failed\n", tz); eprintf("%stime failed\n", tz);