summaryrefslogtreecommitdiffstats
path: root/usr.bin/xargs
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2003-02-26 22:44:32 +0000
committerjmallett <jmallett@FreeBSD.org>2003-02-26 22:44:32 +0000
commitc350585bc92efaf445e425df456ba5de1113b40d (patch)
tree4b1d452404f0fffbfd12afd91b7dd078d75bdc70 /usr.bin/xargs
parent9d4ea753fbb2cc6302c9a0705f06fd6983dbf5e0 (diff)
downloadFreeBSD-src-c350585bc92efaf445e425df456ba5de1113b40d.zip
FreeBSD-src-c350585bc92efaf445e425df456ba5de1113b40d.tar.gz
Extend our -R extension which sets the number of arguments in which -I will
replace to support magic values less than zero, which mean to just go nuts and expand as many as we want. MFC after: 2 weeks
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 bba7aa2..7c2f70b 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 7dc859c..ec15af7 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");
OpenPOWER on IntegriCloud