Mercurial > hg > toybox
changeset 1621:53bfe8ac762b draft
sed 'r' didn't work right.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 22 Dec 2014 13:45:35 -0600 |
parents | 6f7ed6316d90 |
children | 45fb262230c9 |
files | toys/posix/sed.c |
diffstat | 1 files changed, 8 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/posix/sed.c Sun Dec 21 23:17:06 2014 -0600 +++ b/toys/posix/sed.c Mon Dec 22 13:45:35 2014 -0600 @@ -364,7 +364,7 @@ if (c=='a' || c=='r') { struct append *a = xzalloc(sizeof(struct append)); a->str = logrus->arg1+(char *)logrus; - a->file = c== 'r'; + a->file = c=='r'; dlist_add_nomalloc((void *)&append, (void *)a); } else if (c=='b' || c=='t' || c=='T') { int t = tea; @@ -627,12 +627,15 @@ struct append *a = append->next; if (append->file) { - int fd = xopen(append->str, O_RDONLY); + int fd = open(append->str, O_RDONLY); // Force newline if noeol pending - emit(0, 0, 0); - xsendfile(fd, TT.fdout); - close(fd); + if (fd != -1) { + if (TT.noeol) xwrite(TT.fdout, "\n", 1); + TT.noeol = 0; + xsendfile(fd, TT.fdout); + close(fd); + } } else emit(append->str, strlen(append->str), 1); free(append); append = a;