summaryrefslogtreecommitdiff
path: root/usr.bin/top
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2007-02-27 16:27:40 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2007-02-27 16:27:40 +0000
commit86d3801e3ad70705583784371c58b673d02ffcc8 (patch)
treea5d373cfea4a7b8ccd46092c83f5721b733aff64 /usr.bin/top
parent27e274a15e45efa24ea2f78fc1d4f48209a1aab7 (diff)
an atoi() -> strtonum() conversion from Mark Lumsden; ok simon@ ray@
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/top.c6
-rw-r--r--usr.bin/top/utils.c12
2 files changed, 11 insertions, 7 deletions
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index 8f7ede47972..88eb3fc6102 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.c,v 1.48 2007/02/04 19:23:27 otto Exp $ */
+/* $OpenBSD: top.c,v 1.49 2007/02/27 16:27:39 otto Exp $ */
/*
* Top users/processes display for Unix
@@ -251,8 +251,8 @@ parseargs(int ac, char **av)
/* get count of top processes to display (if any) */
if (optind < ac) {
if ((topn = atoiwi(av[optind])) == Invalid) {
- warnx("warning: process display count should "
- "be non-negative -- using default");
+ warnx("warning: process count should "
+ "be a non-negative number -- using default");
warnings++;
topn = Infinity;
}
diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c
index 38e4dd5577b..f0ae82d5b04 100644
--- a/usr.bin/top/utils.c
+++ b/usr.bin/top/utils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utils.c,v 1.16 2005/06/08 22:36:43 millert Exp $ */
+/* $OpenBSD: utils.c,v 1.17 2007/02/27 16:27:39 otto Exp $ */
/*
* Top users/processes display for Unix
@@ -48,6 +48,8 @@ int
atoiwi(char *str)
{
size_t len;
+ const char *errstr;
+ int i;
len = strlen(str);
if (len != 0) {
@@ -55,10 +57,12 @@ atoiwi(char *str)
strncmp(str, "all", len) == 0 ||
strncmp(str, "maximum", len) == 0) {
return (Infinity);
- } else if (str[0] == '-')
+ }
+ i = (int)strtonum(str, 0, INT_MAX, &errstr);
+ if (errstr) {
return (Invalid);
- else
- return (atoi(str));
+ } else
+ return (i);
}
return (0);
}