Fix tac to handle the "abc\ndef" case properly

This commit is contained in:
Elie De Brauwer 2012-12-22 11:50:11 +01:00
parent 7a78d92da7
commit de08aef53c
2 changed files with 4 additions and 4 deletions

View File

@ -17,8 +17,7 @@ testing "tac file1 notfound file2" \
"tac file1 notfound file2 2>stderr && echo ok ; tac stderr; rm stderr" \ "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" "" "" "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 -" "defabc\n" "" "abc\ndef"
testing "tac no trailing newline" "tac -" "def\nabc\n" "" "abc\ndef"
# xputs used by tac does not propagate this error condition properly. # xputs used by tac does not propagate this error condition properly.
#testing "tac > /dev/full" \ #testing "tac > /dev/full" \

View File

@ -23,8 +23,9 @@ void do_tac(int fd, char *name)
// Read in lines // Read in lines
for (;;) { for (;;) {
struct arg_list *temp; 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 = xmalloc(sizeof(struct arg_list));
temp->next = list; temp->next = list;
@ -35,7 +36,7 @@ void do_tac(int fd, char *name)
// Play them back. // Play them back.
while (list) { while (list) {
struct arg_list *temp = list->next; struct arg_list *temp = list->next;
xputs(list->arg); xprintf("%s", list->arg);
free(list->arg); free(list->arg);
free(list); free(list);
list = temp; list = temp;