xargs: Consistently use strtonum() to parse arguments.
MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D40425
This commit is contained in:
parent
e730066a64
commit
fbc445addf
@ -124,7 +124,6 @@ main(int argc, char *argv[])
|
||||
int ch, Jflag, nargs, nflag, nline;
|
||||
size_t linelen;
|
||||
struct rlimit rl;
|
||||
char *endptr;
|
||||
const char *errstr;
|
||||
|
||||
inpline = replstr = NULL;
|
||||
@ -175,23 +174,23 @@ main(int argc, char *argv[])
|
||||
replstr = optarg;
|
||||
break;
|
||||
case 'L':
|
||||
Lflag = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
Lflag = (int)strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr)
|
||||
errx(1, "-L %s: %s", optarg, errstr);
|
||||
errx(1, "-%c %s: %s", ch, optarg, errstr);
|
||||
break;
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
nargs = strtonum(optarg, 1, INT_MAX, &errstr);
|
||||
nargs = (int)strtonum(optarg, 1, INT_MAX, &errstr);
|
||||
if (errstr)
|
||||
errx(1, "-n %s: %s", optarg, errstr);
|
||||
errx(1, "-%c %s: %s", ch, optarg, errstr);
|
||||
break;
|
||||
case 'o':
|
||||
oflag = 1;
|
||||
break;
|
||||
case 'P':
|
||||
maxprocs = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
maxprocs = (int)strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr)
|
||||
errx(1, "-P %s: %s", optarg, errstr);
|
||||
errx(1, "-%c %s: %s", ch, optarg, errstr);
|
||||
if (getrlimit(RLIMIT_NPROC, &rl) != 0)
|
||||
errx(1, "getrlimit failed");
|
||||
if (maxprocs == 0 || maxprocs > rl.rlim_cur)
|
||||
@ -201,22 +200,22 @@ main(int argc, char *argv[])
|
||||
pflag = 1;
|
||||
break;
|
||||
case 'R':
|
||||
Rflag = strtol(optarg, &endptr, 10);
|
||||
if (*endptr != '\0')
|
||||
errx(1, "replacements must be a number");
|
||||
Rflag = (int)strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr)
|
||||
errx(1, "-%c %s: %s", ch, optarg, errstr);
|
||||
break;
|
||||
case 'r':
|
||||
/* GNU compatibility */
|
||||
break;
|
||||
case 'S':
|
||||
Sflag = strtoul(optarg, &endptr, 10);
|
||||
if (*endptr != '\0')
|
||||
errx(1, "replsize must be a number");
|
||||
Sflag = (int)strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr)
|
||||
errx(1, "-%c %s: %s", ch, optarg, errstr);
|
||||
break;
|
||||
case 's':
|
||||
nline = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
nline = (int)strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr)
|
||||
errx(1, "-s %s: %s", optarg, errstr);
|
||||
errx(1, "-%c %s: %s", ch, optarg, errstr);
|
||||
break;
|
||||
case 't':
|
||||
tflag = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user