summaryrefslogtreecommitdiff
path: root/usr.bin/last/last.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2005-07-01 02:10:25 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2005-07-01 02:10:25 +0000
commit90fddac1ecf803ca16f41612c08f58c63ef38720 (patch)
tree2ebe69ed747c18a4e5022792d48b2d8ad250d4a5 /usr.bin/last/last.c
parent82b65f207e81d439b91b93976b8976f6a2f18b91 (diff)
Replace numeric argument handling (e.g. last -30) with something that
can deal with mixer number and normal arguments, adapted from my code in diff(1). OK deraadt@
Diffstat (limited to 'usr.bin/last/last.c')
-rw-r--r--usr.bin/last/last.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c
index 928353b3b6d..bc73b74d0de 100644
--- a/usr.bin/last/last.c
+++ b/usr.bin/last/last.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: last.c,v 1.31 2004/06/16 22:30:08 millert Exp $ */
+/* $OpenBSD: last.c,v 1.32 2005/07/01 02:10:24 millert Exp $ */
/* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */
/*
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94";
#endif
-static char rcsid[] = "$OpenBSD: last.c,v 1.31 2004/06/16 22:30:08 millert Exp $";
+static char rcsid[] = "$OpenBSD: last.c,v 1.32 2005/07/01 02:10:24 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -111,11 +111,14 @@ main(int argc, char *argv[])
{
const char *errstr;
char *p;
- int ch;
+ int ch, lastch, newarg, prevoptind;
maxrec = -1;
snaptime = 0;
- while ((ch = getopt(argc, argv, "0123456789cf:h:n:st:d:T")) != -1)
+ lastch = '\0';
+ newarg = 1;
+ prevoptind = 1;
+ while ((ch = getopt(argc, argv, "0123456789cf:h:n:st:d:T")) != -1) {
switch (ch) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
@@ -123,15 +126,11 @@ main(int argc, char *argv[])
* kludge: last was originally designed to take
* a number after a dash.
*/
- if (maxrec == -1) {
- p = argv[optind - 1];
- if (p[0] == '-' && p[1] == ch && !p[2])
- maxrec = atol(++p);
- else
- maxrec = atol(argv[optind] + 1);
- if (maxrec == 0)
- exit(0);
- }
+ if (newarg || !isdigit(lastch))
+ maxrec = 0;
+ else if (maxrec > INT_MAX / 10)
+ usage();
+ maxrec = (maxrec * 10) + (ch - '0');
break;
case 'c':
calculate++;
@@ -163,10 +162,15 @@ main(int argc, char *argv[])
case 'T':
fulltime = 1;
break;
- case '?':
default:
usage();
}
+ lastch = ch;
+ newarg = optind != prevoptind;
+ prevoptind = optind;
+ }
+ if (maxrec == 0)
+ exit(0);
if (argc) {
setlinebuf(stdout);