This patch makes `xargs -0` behave like `xargs` in the example below: $ echo -ne "\0\0\0" | xargs -0 -n1 | wc -l 3 $ echo -ne "\n\n\n" | xargs -n1 | wc -l 1 This was rejected, as that behaviour was seen as POSIX compatibility only. I disagree, because of the asymmetry/inconsistency. diff -aruN -x *.o findutils-4.1.7/xargs/xargs.1 findutils-pb/xargs/xargs.1 --- findutils-4.1.7/xargs/xargs.1 Sun Feb 4 20:35:11 1996 +++ findutils-pb/xargs/xargs.1 Sat Jun 16 17:02:32 2001 @@ -41,7 +41,8 @@ whitespace, and the quotes and backslash are not special (every character is taken literally). Disables the end of file string, which is treated like any other argument. Useful when arguments might -contain white space, quote marks, or backslashes. The GNU find +contain white space, quote marks, or backslashes. Redundant null +characters (initial or adjacent) on the input are ignored. The GNU find \-print0 option produces input suitable for this mode. .TP .I "\-\-eof[=eof-str], \-e[eof-str]" diff -aruN -x *.o findutils-4.1.7/xargs/xargs.c findutils-pb/xargs/xargs.c --- findutils-4.1.7/xargs/xargs.c Tue Oct 10 00:40:41 2000 +++ findutils-pb/xargs/xargs.c Sat Jun 16 17:16:52 2001 @@ -563,7 +563,7 @@ } /* Read a null-terminated string from stdin and add it to the list of - arguments to pass to the command. + arguments to pass to the command. Ignore initial and adjacent NULs. Return -1 if eof (either physical or logical) is reached, otherwise the length of the string read (including the null). */ @@ -572,6 +572,7 @@ { static boolean eof = false; int len; + int pc = '\0'; char *p = linebuf; /* Including the NUL, the args must not grow past this point. */ char *endbuf = linebuf + arg_max - initial_argv_chars - 1; @@ -594,7 +595,9 @@ } if (c == '\0') { - lineno++; /* For -l. */ + if (pc == '\0') + continue; /* skip redundant NULs */ + lineno++; /* For -l. */ *p++ = '\0'; len = p - linebuf; if (!replace_pat) @@ -604,6 +607,7 @@ if (p >= endbuf) error (1, 0, _("argument line too long")); *p++ = c; + pc = c; } } diff -aruN -x *.o findutils-4.1.7/xargs/testsuite/inputs/files00.xi findutils-pb/xargs/testsuite/inputs/files00.xi --- findutils-4.1.7/xargs/testsuite/inputs/files00.xi Thu Jan 1 01:00:00 1970 +++ findutils-pb/xargs/testsuite/inputs/files00.xi Sat Jun 16 19:18:24 2001 @@ -0,0 +1 @@ +=00/src/gnu/autoconf-1.11=00=00/src/gnu/autoconf-1.11/README=00/src/gnu/autoconf-1.11/Makefile.in=00=00 \ No newline at end of file diff -aruN -x *.o findutils-4.1.7/xargs/testsuite/xargs.gnu/redundant0.exp findutils-pb/xargs/testsuite/xargs.gnu/redundant0.exp --- findutils-4.1.7/xargs/testsuite/xargs.gnu/redundant0.exp Thu Jan 1 01:00:00 1970 +++ findutils-pb/xargs/testsuite/xargs.gnu/redundant0.exp Sat Jun 16 18:57:14 2001 @@ -0,0 +1 @@ +xargs_start p {-0} files00.xi diff -aruN -x *.o findutils-4.1.7/xargs/testsuite/xargs.gnu/redundant0.xo findutils-pb/xargs/testsuite/xargs.gnu/redundant0.xo --- findutils-4.1.7/xargs/testsuite/xargs.gnu/redundant0.xo Thu Jan 1 01:00:00 1970 +++ findutils-pb/xargs/testsuite/xargs.gnu/redundant0.xo Sat Jun 16 19:18:49 2001 @@ -0,0 +1 @@ +/src/gnu/autoconf-1.11 /src/gnu/autoconf-1.11/README /src/gnu/autoconf-1.11/Makefile.in