Mercurial > hg > toybox
changeset 758:54d248b907ed
Fix tac to handle the "abc\ndef" case properly
author | Elie De Brauwer <eliedebrauwer@gmail.com> |
---|---|
date | Sat, 22 Dec 2012 11:50:11 +0100 |
parents | 4094f14c47a2 |
children | 143a9729fec8 |
files | scripts/test/tac.test toys/other/tac.c |
diffstat | 2 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/test/tac.test Sun Dec 23 00:37:42 2012 -0600 +++ b/scripts/test/tac.test Sat Dec 22 11:50:11 2012 +0100 @@ -17,8 +17,7 @@ "tac file1 notfound file2 2>stderr && echo ok ; tac stderr; rm stderr" \ "one-B\none-A\ntwo-B\ntwo-A\ntac: notfound: No such file or directory\n" "" "" -# echo -ne "abc\ndef" | tac actually gives "defabc\n" -testing "tac no trailing newline" "tac -" "def\nabc\n" "" "abc\ndef" +testing "tac no trailing newline" "tac -" "defabc\n" "" "abc\ndef" # xputs used by tac does not propagate this error condition properly. #testing "tac > /dev/full" \
--- a/toys/other/tac.c Sun Dec 23 00:37:42 2012 -0600 +++ b/toys/other/tac.c Sat Dec 22 11:50:11 2012 +0100 @@ -23,8 +23,9 @@ // Read in lines for (;;) { struct arg_list *temp; + long len; - if (!(c = get_line(fd))) break; + if (!(c = get_rawline(fd, &len, '\n'))) break; temp = xmalloc(sizeof(struct arg_list)); temp->next = list; @@ -35,7 +36,7 @@ // Play them back. while (list) { struct arg_list *temp = list->next; - xputs(list->arg); + xprintf("%s", list->arg); free(list->arg); free(list); list = temp;