aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/xargs
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r--usr.bin/xargs/xargs.13
-rw-r--r--usr.bin/xargs/xargs.c9
2 files changed, 9 insertions, 3 deletions
diff --git a/usr.bin/xargs/xargs.1 b/usr.bin/xargs/xargs.1
index bba7aa24ecbe..7c2f70bd3959 100644
--- a/usr.bin/xargs/xargs.1
+++ b/usr.bin/xargs/xargs.1
@@ -211,6 +211,9 @@ No commands are executed if the process is not attached to a terminal.
Specify the maximum number of arguments that
.Fl I
will do replacement in.
+If
+.Ar replacements
+is negative, the number of arguments in which to replace is unbounded.
.It Fl s Ar size
Set the maximum number of bytes for the command line length provided to
.Ar utility .
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c
index 7dc859cee8b4..ec15af7555bc 100644
--- a/usr.bin/xargs/xargs.c
+++ b/usr.bin/xargs/xargs.c
@@ -96,6 +96,7 @@ main(int argc, char *argv[])
long arg_max;
int ch, Jflag, nargs, nflag, nline;
size_t linelen;
+ char *endptr;
inpline = replstr = NULL;
ep = environ;
@@ -158,8 +159,9 @@ main(int argc, char *argv[])
pflag = 1;
break;
case 'R':
- if ((Rflag = atoi(optarg)) <= 0)
- errx(1, "illegal number of replacements");
+ Rflag = strtol(optarg, &endptr, 10);
+ if (*endptr != '\0')
+ errx(1, "replacements must be a number");
break;
case 's':
nline = atoi(optarg);
@@ -444,7 +446,8 @@ prerun(int argc, char *argv[])
*tmp = *avj++;
if (repls && strstr(*tmp, replstr) != NULL) {
strnsubst(tmp++, replstr, inpline, (size_t)255);
- repls--;
+ if (repls > 0)
+ repls--;
} else {
if ((*tmp = strdup(*tmp)) == NULL)
errx(1, "strdup failed");