aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-07-05 02:36:51 -0500
committerRob Landley <rob@landley.net>2015-07-05 02:36:51 -0500
commit137ac1f8000b1c50b2485912de6e8f553a498230 (patch)
tree9fae0590ff1ab5d3a548491ada510891f9329f28
parent671146c3b41460ec3ad25f64f1269be0f3924b27 (diff)
downloadtoybox-137ac1f8000b1c50b2485912de6e8f553a498230.tar.gz
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...
-rw-r--r--toys/posix/sort.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/toys/posix/sort.c b/toys/posix/sort.c
index b7e16c97..49e68c74 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: