free -c option uses strutils

The handling of the -c (count) option in free uses the standard string
handling and error utils.  The program also checks for negative counts
and errors on these.
This commit is contained in:
Craig Small 2012-01-04 09:53:51 +11:00
parent f776e59123
commit 223c95c95d
2 changed files with 8 additions and 4 deletions

View File

@ -70,6 +70,7 @@ skill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
snice_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c
pkill_SOURCES = pgrep.c
free_SOURCES = free.c $(top_srcdir)/lib/strutils.c
vmstat_SOURCES = vmstat.c $(top_srcdir)/lib/strutils.c
sysconf_DATA = sysctl.conf

11
free.c
View File

@ -12,10 +12,12 @@
* Copyright 2004 Albert Cahalan
*/
#include "config.h"
#include "proc/sysinfo.h"
#include "proc/version.h"
#include "c.h"
#include "nls.h"
#include "strutils.h"
#include <locale.h>
#include <errno.h>
@ -255,10 +257,11 @@ int main(int argc, char **argv)
case 'c':
flags |= FREE_REPEAT;
flags |= FREE_REPEATCOUNT;
args.repeat_counter = strtoul(optarg, &endptr, 10);
if (errno || optarg == endptr || (endptr && *endptr))
xerrx(EXIT_FAILURE, _("count argument `%s' failed"), optarg);
args.repeat_counter = strtol_or_err(optarg,
_("failed to parse count argument"));
if (args.repeat_counter > ULONG_MAX/2)
error(EXIT_FAILURE, ERANGE,
_("failed to parse count argument: '%s'"), optarg);
break;
case HELP_OPTION:
usage(stdout);