[hackers] [sbase] Audit date(1) || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 3 Mar 2015 14:32:26 +0100 (CET)

commit 17f05000df49a245582eeee0c1ea70260532271e
Author: FRIGN <dev_AT_frign.de>
Date: Mon Mar 2 15:12:19 2015 +0100

    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.

diff --git a/README b/README
index 136a2b7..ce1e072 100644
--- a/README
+++ b/README
_AT_@ -23,7 +23,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 = cp yes none (-i)
 =* cron non-posix none
 #* cut yes none
-=* date yes -u
+=*| date yes none
 =*| dirname yes none
 =* du yes none
 =*| echo yes none
diff --git a/date.c b/date.c
index fb7e8e5..a3cd313 100644
--- a/date.c
+++ b/date.c
_AT_@ -8,20 +8,19 @@
 static void
 usage(void)
 {
- eprintf("usage: %s [-u] [-d format] [+FORMAT]\n", argv0);
+ eprintf("usage: %s [-u] [-d time] [+format]\n", argv0);
 }
 
 int
 main(int argc, char *argv[])
 {
- char buf[BUFSIZ];
- char *fmt = "%c";
- struct tm *now = NULL;
+ struct tm *now;
         struct tm *(*tztime)(const time_t *) = localtime;
- const char *tz = "local";
         time_t t;
+ char buf[BUFSIZ], *fmt = "%c", *tz = "local";
 
         t = time(NULL);
+
         ARGBEGIN {
         case 'd':
                 t = estrtonum(EARGF(usage()), 0, LLONG_MAX);
_AT_@ -34,8 +33,12 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- if (argc > 0 && argv[0][0] == '+')
- fmt = &argv[0][1];
+ if (argc) {
+ if (argc != 1 || argv[0][0] != '+')
+ usage();
+ else
+ fmt = &argv[0][1];
+ }
         if (!(now = tztime(&t)))
                 eprintf("%stime failed\n", tz);
 
Received on Tue Mar 03 2015 - 14:32:26 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 03 2015 - 14:36:23 CET