From 86d3801e3ad70705583784371c58b673d02ffcc8 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 27 Feb 2007 16:27:40 +0000 Subject: an atoi() -> strtonum() conversion from Mark Lumsden; ok simon@ ray@ --- usr.bin/top/top.c | 6 +++--- usr.bin/top/utils.c | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'usr.bin/top') 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); } -- cgit v1.2.3