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:
parent
f776e59123
commit
223c95c95d
@ -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
11
free.c
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user