1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00

Make xargs run [utility] program even when zero arguements are provided,

makes xargs POSIX compliant.

Original diff from jason@, better diff provided by millert@

Resolves PR 4262

ok deraadt@ millert@
This commit is contained in:
brad 2005-09-10 23:00:29 +00:00
parent 202a2b76c3
commit 3e7336d9d7
2 changed files with 20 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: xargs.1,v 1.13 2003/06/12 17:55:01 jmc Exp $
.\" $OpenBSD: xargs.1,v 1.14 2005/09/10 23:00:29 brad Exp $
.\" $FreeBSD: xargs.1,v 1.30 2003/05/21 21:07:28 ru Exp $$
.\"
.\" Copyright (c) 1990, 1991, 1993
@ -43,7 +43,7 @@
.Sh SYNOPSIS
.Nm xargs
.Bk -words
.Op Fl 0opt
.Op Fl 0oprt
.Op Fl E Ar eofstr
.Oo
.Fl I Ar replstr
@ -74,7 +74,8 @@ upon each invocation, followed by some number of the arguments read
from standard input.
The
.Ar utility
is repeatedly executed until standard input is exhausted.
is repeatedly executed one or more times until standard input
is exhausted.
.Pp
Spaces, tabs and newlines may be embedded in arguments using single
.Pq Ql '
@ -222,6 +223,10 @@ will do replacement in.
If
.Ar replacements
is negative, the number of arguments in which to replace is unbounded.
.It Fl r
Do not run the command if there are no arguments.
Normally the command is executed at least once
even if there are no arguments.
.It Fl s Ar size
Set the maximum number of bytes for the command line length provided to
.Ar utility .
@ -311,9 +316,9 @@ utility is expected to be
.St -p1003.2
compliant.
The
.Fl J , o , P
.Fl J , o , P , R
and
.Fl R
.Fl r
options are non-standard
extensions which may not be available on other operating systems.
.Pp

View File

@ -1,4 +1,4 @@
/* $OpenBSD: xargs.c,v 1.20 2005/06/20 18:52:19 millert Exp $ */
/* $OpenBSD: xargs.c,v 1.21 2005/09/10 23:00:29 brad Exp $ */
/* $FreeBSD: xargs.c,v 1.51 2003/05/03 19:09:11 obrien Exp $ */
/*-
@ -45,7 +45,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93";
#else
static const char rcsid[] = "$OpenBSD: xargs.c,v 1.20 2005/06/20 18:52:19 millert Exp $";
static const char rcsid[] = "$OpenBSD: xargs.c,v 1.21 2005/09/10 23:00:29 brad Exp $";
#endif
#endif /* not lint */
@ -79,7 +79,7 @@ static char **av, **bxp, **ep, **endxp, **xp;
static char *argp, *bbp, *ebp, *inpline, *p, *replstr;
static const char *eofstr;
static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
static int cnt, Iflag, jfound, Lflag, wasquoted, xflag;
static int cnt, Iflag, jfound, Lflag, wasquoted, xflag, runeof = 1;
static int curprocs, maxprocs;
static size_t inpsize;
@ -122,7 +122,7 @@ main(int argc, char *argv[])
nline -= strlen(*ep++) + 1 + sizeof(*ep);
}
maxprocs = 1;
while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:tx")) != -1)
while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:rs:tx")) != -1)
switch (ch) {
case 'E':
eofstr = optarg;
@ -156,6 +156,9 @@ main(int argc, char *argv[])
case 'p':
pflag = 1;
break;
case 'r':
runeof = 0;
break;
case 'R':
Rflag = strtol(optarg, &endptr, 10);
if (*endptr != '\0')
@ -257,6 +260,8 @@ parse_input(int argc, char *argv[])
case EOF:
/* No arguments since last exec. */
if (p == bbp) {
if (runeof)
prerun(0, av);
waitchildren(*argv, 1);
exit(rval);
}
@ -404,6 +409,7 @@ prerun(int argc, char *argv[])
int repls;
repls = Rflag;
runeof = 0;
if (argc == 0 || repls == 0) {
*xp = NULL;