aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-12-22 13:45:35 -0600
committerRob Landley <rob@landley.net>2014-12-22 13:45:35 -0600
commitea8be3d41f1b818081012c79c0935f9c2173924d (patch)
tree896ddc7b8df240699c22bb8bd151e852e5c8a8f6 /toys
parentc09b79dc71d986213d37805131b89a135202263e (diff)
downloadtoybox-ea8be3d41f1b818081012c79c0935f9c2173924d.tar.gz
sed 'r' didn't work right.
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/sed.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index 65a6fe0f..e9f76d86 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -364,7 +364,7 @@ static void walk_pattern(char **pline, long plen)
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 @@ done:
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;