We cannot use eprintf() without first initializing argv0
This commit is contained in:
parent
04a30829a2
commit
faf12794db
18
last.c
18
last.c
@ -12,11 +12,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fputs("last [user]\n", stderr);
|
eprintf("usage: %s [user]\n", argv0);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -27,18 +26,23 @@ main(int argc, char **argv)
|
|||||||
char *user, *file, *prog;
|
char *user, *file, *prog;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
|
ARGBEGIN {
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
} ARGEND;
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 1:
|
case 0:
|
||||||
user = NULL;
|
user = NULL;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 1:
|
||||||
user = argv[1];
|
user = argv[0];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
prog = basename(argv[0]);
|
prog = basename(argv0);
|
||||||
file = (!strcmp(prog, "last")) ? WTMP_PATH : BTMP_PATH;
|
file = (!strcmp(prog, "last")) ? WTMP_PATH : BTMP_PATH;
|
||||||
if ((fp = fopen(file, "r")) == NULL)
|
if ((fp = fopen(file, "r")) == NULL)
|
||||||
eprintf("fopen %s:", file);
|
eprintf("fopen %s:", file);
|
||||||
|
Loading…
Reference in New Issue
Block a user