diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2017-01-19 17:08:43 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2017-01-19 17:08:43 +0000 |
commit | 337b912b1629923596361c535306302b507bfbbf (patch) | |
tree | 627dab22a63cdb474256482756cef782dd74c856 | |
parent | 4b728c68f3744629640dbbc93189b831529a5678 (diff) |
Fix -L/-I processing in -0 mode so that NUL-delimited entries are
treated as "lines". From FreeBSD.
-rwxr-xr-x | regress/usr.bin/xargs/xargs-L.sh | 16 | ||||
-rw-r--r-- | usr.bin/xargs/xargs.c | 15 |
2 files changed, 19 insertions, 12 deletions
diff --git a/regress/usr.bin/xargs/xargs-L.sh b/regress/usr.bin/xargs/xargs-L.sh index b95aadd505c..295e691ee4e 100755 --- a/regress/usr.bin/xargs/xargs-L.sh +++ b/regress/usr.bin/xargs/xargs-L.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: xargs-L.sh,v 1.1 2010/03/25 01:43:47 schwarze Exp $ +# $OpenBSD: xargs-L.sh,v 1.2 2017/01/19 17:08:42 millert Exp $ # # written by Ingo Schwarze <schwarze@openbsd.org> 2010 # and placed in the public domain @@ -76,18 +76,18 @@ test_xargs 'a \\\nb' '-0' 'a \\\nb|' test_xargs 'a\\\n b' '-0' 'a\\\n b|' test_xargs 'a \\\n b' '-0' 'a \\\n b|' -test_xargs 'a b\0c' '-0 -L 1' 'a b|c|' -test_xargs 'a b\0c' '-0 -L 1' 'a b|c|' +test_xargs 'a b\0c' '-0 -L 1' 'a b|\nc|' +test_xargs 'a b\0c' '-0 -L 1' 'a b|\nc|' test_xargs 'a\nb\0c' '-0 -L 1' 'a\nb|\nc|' test_xargs 'a\n\nb\0c' '-0 -L 1' 'a\n\nb|\nc|' -test_xargs 'a \nb\0c' '-0 -L 1' 'a \nb|c|' +test_xargs 'a \nb\0c' '-0 -L 1' 'a \nb|\nc|' test_xargs 'a\n b\0c' '-0 -L 1' 'a\n b|\nc|' -test_xargs 'a \n b\0c' '-0 -L 1' 'a \n b|c|' +test_xargs 'a \n b\0c' '-0 -L 1' 'a \n b|\nc|' test_xargs 'a\n \nb\0c' '-0 -L 1' 'a\n \nb|\nc|' -test_xargs 'a \n\nb\0c' '-0 -L 1' 'a \n\nb|c|' +test_xargs 'a \n\nb\0c' '-0 -L 1' 'a \n\nb|\nc|' -test_xargs 'a\\ b\0c' '-0 -L 1' 'a\\ b|c|' -test_xargs 'a\\ \nb\0c' '-0 -L 1' 'a\\ \nb|c|' +test_xargs 'a\\ b\0c' '-0 -L 1' 'a\\ b|\nc|' +test_xargs 'a\\ \nb\0c' '-0 -L 1' 'a\\ \nb|\nc|' test_xargs 'a\n\\ b\0c' '-0 -L 1' 'a\n\\ b|\nc|' test_xargs 'a\\\nb\0c' '-0 -L 1' 'a\\\nb|\nc|' diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index 6c1c31b1fea..d32364b16f1 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xargs.c,v 1.31 2015/12/09 19:29:49 mmcc Exp $ */ +/* $OpenBSD: xargs.c,v 1.32 2017/01/19 17:08:41 millert Exp $ */ /* $FreeBSD: xargs.c,v 1.51 2003/05/03 19:09:11 obrien Exp $ */ /*- @@ -278,15 +278,22 @@ parse_input(int argc, char *argv[]) } goto arg1; case '\0': - if (zflag) + if (zflag) { + /* + * Increment 'count', so that nulls will be treated + * as end-of-line, as well as end-of-argument. This + * is needed so -0 works properly with -I and -L. + */ + count++; goto arg2; + } goto addch; case '\n': + if (zflag) + goto addch; hasblank = 1; if (hadblank == 0) count++; - if (zflag) - goto addch; /* Quotes do not escape newlines. */ arg1: if (insingle || indouble) |