]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rev: allow zero-byte as separator
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 12 Nov 2022 04:32:33 +0000 (05:32 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 13 Nov 2022 01:45:41 +0000 (02:45 +0100)
Fixes #1868

tests/expected/misc/rev
tests/ts/misc/rev
text-utils/rev.1.adoc
text-utils/rev.c

index 638747637957bff74fa87e81c5e2d186b09fa374..bd8f465987d10f7403c337033a3362e4f7281bef 100644 (file)
@@ -1,4 +1,5 @@
 53bbf0d98205319cee2ba589e205c68b
 35484965b7a2fd45a471c0d80cb9752c
 cba
-321
\ No newline at end of file
+321
+cba|321
index 0b3b64c09d6a25199e074c30aa61d3e3994acf5e..5e849f14ac365bb0e9dedbe8a0551d1d6f5f4887 100755 (executable)
@@ -27,5 +27,8 @@ for I in {0..512}; do printf "%s " {a..z}; done | \
                                    $TS_CMD_REV | "$TS_HELPER_MD5" >> $TS_OUTPUT 2>> $TS_ERRLOG
 
 printf "abc\n123" | $TS_CMD_REV >> $TS_OUTPUT 2>> $TS_ERRLOG
+echo >> $TS_OUTPUT
+printf "abc\000123" | $TS_CMD_REV -0 | tr '\0' '|' >> $TS_OUTPUT 2>> $TS_ERRLOG
+echo >> $TS_OUTPUT
 
 ts_finalize
index 9076a7d37416c600b16e09a5de82f880aa2c8f69..3d40273900e4a3a52cfb94a021c8c298ac5609da 100644 (file)
@@ -58,6 +58,9 @@ This utility is a line-oriented tool and it uses in-memory allocated buffer for
 
 include::man-common/help-version.adoc[]
 
+*-0*, *--zero*::
+_Zero termination_. Use the byte '\0' as line separator.
+
 == SEE ALSO
 
 *tac*(1)
index f69e47ef7b49ddfcebf9c260fab0d21f153b4ebc..fbf04d1a64418f7ceb33cf45a3d07dc524d9f93f 100644 (file)
@@ -127,6 +127,7 @@ int main(int argc, char *argv[])
        uintmax_t line;
 
        static const struct option longopts[] = {
+               { "zero",       no_argument,       NULL, '0' },
                { "version",    no_argument,       NULL, 'V' },
                { "help",       no_argument,       NULL, 'h' },
                { NULL,         0, NULL, 0 }
@@ -140,8 +141,11 @@ int main(int argc, char *argv[])
        signal(SIGINT, sig_handler);
        signal(SIGTERM, sig_handler);
 
-       while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+       while ((ch = getopt_long(argc, argv, "Vh0", longopts, NULL)) != -1)
                switch(ch) {
+               case '0':
+                       sep = L'\0';
+                       break;
                case 'V':
                        print_version(EXIT_SUCCESS);
                case 'h':