diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-10-06 23:44:31 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-10-06 23:44:31 +0000 |
commit | fe0a954c8f4957c00d2ce0eb0d36b5962553f86e (patch) | |
tree | daa2204523e57e4cc96b35520e26dd1fd528586d /usr.bin | |
parent | ac2d335dd66ff41035a0c27f01979ae78a035f33 (diff) |
Convert strtol to strtonum, eliminating errno misusage.
OK dhill@, jaredy@, and moritz@.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/head/head.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c index d1eaffc040e..f16de6438c2 100644 --- a/usr.bin/head/head.c +++ b/usr.bin/head/head.c @@ -1,4 +1,4 @@ -/* $OpenBSD: head.c,v 1.11 2003/06/10 22:20:47 deraadt Exp $ */ +/* $OpenBSD: head.c,v 1.12 2006/10/06 23:44:30 ray Exp $ */ /* * Copyright (c) 1980, 1987 Regents of the University of California. @@ -37,7 +37,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)head.c 5.5 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$OpenBSD: head.c,v 1.11 2003/06/10 22:20:47 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: head.c,v 1.12 2006/10/06 23:44:30 ray Exp $"; #endif /* not lint */ #include <stdio.h> @@ -62,18 +62,18 @@ main(int argc, char *argv[]) long cnt; int ch, firsttime; long linecnt = 10; - char *inval = NULL, *p = NULL; + char *p = NULL; /* handle obsolete -number syntax */ if (argc > 1 && argv[1][0] == '-' && isdigit(argv[1][1])) { - linecnt = strtol((p = argv[1] + 1), &inval, 10); + p = argv[1] + 1; argc--; argv++; } while ((ch = getopt (argc, argv, "n:")) != -1) switch (ch) { case 'n': - linecnt = strtol((p = optarg), &inval, 10); + p = optarg; break; default: usage(); @@ -81,11 +81,11 @@ main(int argc, char *argv[]) argc -= optind, argv += optind; if (p) { - if ((linecnt == LONG_MIN || linecnt == LONG_MAX) && - errno == ERANGE) - err(1, "illegal line count -- %s", p); - else if (linecnt <= 0 || *inval) - errx(1, "illegal line count -- %s", p); + const char *errstr; + + linecnt = strtonum(p, 1, LONG_MAX, &errstr); + if (errstr) + errx(1, "line count %s: %s", errstr, p); } /* setlinebuf(stdout); */ |