[Toybox] [PATCH] sort: Make -z give null-terminated output (like GNU)

Kylie McClain somasissounds at gmail.com
Sat Jul 4 22:08:27 PDT 2015


This makes the `sort` implementation act like the GNU implementation,
and changes -z to use \0 terminated input and output rather than just
take \0 terminated input.
---
 toys/posix/sort.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/toys/posix/sort.c b/toys/posix/sort.c
index b7e16c9..ecbda0f 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 input/output
     -k	sort by "key" (see below)
     -t	use a key separator other than whitespace
     -o	output to FILE instead of stdout
@@ -386,7 +386,8 @@ void sort_main(void)
     char *s = TT.lines[idx];
     xwrite(fd, s, strlen(s));
     if (CFG_TOYBOX_FREE) free(s);
-    xwrite(fd, "\n", 1);
+    if (CFG_SORT_BIG && (toys.optflags&FLAG_z)) xwrite(fd, "\0", 1);
+    else xwrite(fd, "\n", 1);
   }
 
 exit_now:
-- 
2.4.5


 1436072907.0


More information about the Toybox mailing list