static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
static int cnt, Iflag, jfound, Lflag, wasquoted, xflag;
static int curprocs, maxprocs;
+static size_t pad9314053;
static volatile int childerr;
main(int argc, char *argv[])
{
long arg_max;
- int ch, Jflag, nargs, nflag, nline;
+ int ch, Jflag, nflag, nline;
+ size_t nargs;
size_t linelen;
char *endptr;
nargs = 5000;
if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
errx(1, "sysconf(_SC_ARG_MAX) failed");
- nline = arg_max - 4 * 1024;
+ nline = arg_max - MAXPATHLEN; /* for argv[0] from execvp() */
+ pad9314053 = sizeof(char *); /* reserve for string area rounding */
while (*ep != NULL) {
/* 1 byte for each '\0' */
nline -= strlen(*ep++) + 1 + sizeof(*ep);
}
+ nline -= pad9314053;
maxprocs = 1;
while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:tx")) != -1)
switch(ch) {
break;
case 'n':
nflag = 1;
- if ((nargs = atoi(optarg)) <= 0)
+ if ((nargs = strtol(optarg, NULL, 10)) <= 0)
errx(1, "illegal argument count");
if (COMPAT_MODE("bin/xargs", "Unix2003")) {
Lflag = 0; /* Override */
break;
case 's':
nline = atoi(optarg);
+ pad9314053 = 0; /* assume the -s value is valid */
break;
case 't':
tflag = 1;
* arguments.
*/
if (*argv == NULL)
- cnt = strlen(*bxp++ = echo);
+ cnt = strlen(*bxp++ = echo) + pad9314053;
else {
do {
if (Jflag && strcmp(*argv, replstr) == 0) {
jfound = 1;
argv++;
for (avj = argv; *avj; avj++)
- cnt += strlen(*avj) + 1;
+ cnt += strlen(*avj) + 1 + pad9314053;
break;
}
- cnt += strlen(*bxp++ = *argv) + 1;
+ cnt += strlen(*bxp++ = *argv) + 1 + pad9314053;
} while (*++argv != NULL);
}
foundeof = *eofstr != '\0' &&
strcmp(argp, eofstr) == 0;
+#ifdef __APPLE__
+ /* 6591323: -I specifies that it processes the entire line,
+ * so only recognize eofstr at the end of a line. */
+ if (Iflag && !last_was_newline)
+ foundeof = 0;
+
+ /* 6591323: Essentially the same as the EOF handling above. */
+ if (foundeof && (p - strlen(eofstr) == bbp)) {
+ waitchildren(*argv, 1);
+ exit(rval);
+ }
+#endif
+
/* Do not make empty args unless they are quoted */
if ((argp != p || wasquoted) && !foundeof) {
*p++ = '\0';
* of input lines, as specified by -L is the same as
* maxing out on arguments.
*/
- if (xp == endxp || p > ebp || ch == EOF ||
+ if (xp == endxp || p + (count * pad9314053) > ebp || ch == EOF ||
(Lflag <= count && xflag) || foundeof) {
- if (xflag && xp != endxp && p > ebp)
+ if (xflag && xp != endxp && p + (count * pad9314053) > ebp)
errx(1, "insufficient space for arguments");
if (jfound) {
for (avj = argv; *avj; avj++)