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
|
snice_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
|
||||||
tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c
|
tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c
|
||||||
pkill_SOURCES = pgrep.c
|
pkill_SOURCES = pgrep.c
|
||||||
|
free_SOURCES = free.c $(top_srcdir)/lib/strutils.c
|
||||||
vmstat_SOURCES = vmstat.c $(top_srcdir)/lib/strutils.c
|
vmstat_SOURCES = vmstat.c $(top_srcdir)/lib/strutils.c
|
||||||
|
|
||||||
sysconf_DATA = sysctl.conf
|
sysconf_DATA = sysctl.conf
|
||||||
|
11
free.c
11
free.c
@ -12,10 +12,12 @@
|
|||||||
* Copyright 2004 Albert Cahalan
|
* Copyright 2004 Albert Cahalan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "proc/sysinfo.h"
|
#include "proc/sysinfo.h"
|
||||||
#include "proc/version.h"
|
#include "proc/version.h"
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
#include "nls.h"
|
#include "nls.h"
|
||||||
|
#include "strutils.h"
|
||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -255,10 +257,11 @@ int main(int argc, char **argv)
|
|||||||
case 'c':
|
case 'c':
|
||||||
flags |= FREE_REPEAT;
|
flags |= FREE_REPEAT;
|
||||||
flags |= FREE_REPEATCOUNT;
|
flags |= FREE_REPEATCOUNT;
|
||||||
args.repeat_counter = strtoul(optarg, &endptr, 10);
|
args.repeat_counter = strtol_or_err(optarg,
|
||||||
if (errno || optarg == endptr || (endptr && *endptr))
|
_("failed to parse count argument"));
|
||||||
xerrx(EXIT_FAILURE, _("count argument `%s' failed"), optarg);
|
if (args.repeat_counter > ULONG_MAX/2)
|
||||||
|
error(EXIT_FAILURE, ERANGE,
|
||||||
|
_("failed to parse count argument: '%s'"), optarg);
|
||||||
break;
|
break;
|
||||||
case HELP_OPTION:
|
case HELP_OPTION:
|
||||||
usage(stdout);
|
usage(stdout);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user