diff options
author | Rob Landley <rob@landley.net> | 2015-07-05 02:36:51 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-07-05 02:36:51 -0500 |
commit | 137ac1f8000b1c50b2485912de6e8f553a498230 (patch) | |
tree | 9fae0590ff1ab5d3a548491ada510891f9329f28 /toys | |
parent | 671146c3b41460ec3ad25f64f1269be0f3924b27 (diff) | |
download | toybox-137ac1f8000b1c50b2485912de6e8f553a498230.tar.gz toybox-137ac1f8000b1c50b2485912de6e8f553a498230.tar.bz2 toybox-137ac1f8000b1c50b2485912de6e8f553a498230.zip |
Kylie McClain pointed out that -z affects both input and output.
Can't say I'm happy with the API (-z and -Z to keep them independent would
be nice), but compatibility with what exists trumps having a good API...
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/sort.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/toys/posix/sort.c b/toys/posix/sort.c index b7e16c9..49e68c7 100644 --- a/toys/posix/sort.c +++ b/toys/posix/sort.c @@ -33,7 +33,7 @@ config SORT_BIG -M month sort (jan, feb, etc). -x Hexadecimal numerical sort -s skip fallback sort (only sort with keys) - -z zero (null) terminated input + -z zero (null) terminated lines -k sort by "key" (see below) -t use a key separator other than whitespace -o output to FILE instead of stdout @@ -384,9 +384,11 @@ void sort_main(void) // Output result for (idx = 0; idx<TT.linecount; idx++) { char *s = TT.lines[idx]; - xwrite(fd, s, strlen(s)); + int i = strlen(s); + + if (!(toys.optflags&FLAG_z)) s[i] = '\n'; + xwrite(fd, s, i+1); if (CFG_TOYBOX_FREE) free(s); - xwrite(fd, "\n", 1); } exit_now: |