[hackers] [ubase] We cannot use eprintf() without first initializing argv0 || sin

From: <git_AT_suckless.org>
Date: Thu, 16 Oct 2014 12:41:37 +0200

commit faf12794db27bf3ea86faf70c3467a21b2ac19d9
Author: sin <sin_AT_2f30.org>
Date: Thu Oct 16 11:40:57 2014 +0100

    We cannot use eprintf() without first initializing argv0

diff --git a/last.c b/last.c
index 14fb386..5aeeb8f 100644
--- a/last.c
+++ b/last.c
_AT_@ -12,11 +12,10 @@
 #include "config.h"
 #include "util.h"
 
-void
+static void
 usage(void)
 {
- fputs("last [user]\n", stderr);
- exit(1);
+ eprintf("usage: %s [user]\n", argv0);
 }
 
 int
_AT_@ -27,18 +26,23 @@ main(int argc, char **argv)
         char *user, *file, *prog;
         time_t t;
 
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
         switch (argc) {
- case 1:
+ case 0:
                 user = NULL;
                 break;
- case 2:
- user = argv[1];
+ case 1:
+ user = argv[0];
                 break;
         default:
                 usage();
         }
 
- prog = basename(argv[0]);
+ prog = basename(argv0);
         file = (!strcmp(prog, "last")) ? WTMP_PATH : BTMP_PATH;
         if ((fp = fopen(file, "r")) == NULL)
                 eprintf("fopen %s:", file);
Received on Thu Oct 16 2014 - 12:41:37 CEST

This archive was generated by hypermail 2.3.0 : Thu Oct 16 2014 - 12:48:09 CEST