From b607b5790992e29f93e6140ba9d8e7f3ed17b3ce Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 20 Jan 2022 13:30:45 -0600 Subject: [PATCH] Fix sed bug with multiple w to same file. --- tests/sed.test | 3 +++ toys/posix/sed.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/sed.test b/tests/sed.test index fd3b2057..5035478b 100755 --- a/tests/sed.test +++ b/tests/sed.test @@ -195,6 +195,9 @@ testing 'megabyte s/x/y/g (20 sec timeout)' \ '138c1fa7c3f64186203b0192fb4abdb33cb4e98a -\n' '' "$X\n" unset X Y +testing "w doesn't blank" "sed -e 'w one' -e 'w one' -e d; cat one" \ + 'hello\nhello\n' '' 'hello\n' + testing 's i and I' 'sed s/o/0/ig' "f00l F00L" "" "fool FOOL" # -i with $ last line test diff --git a/toys/posix/sed.c b/toys/posix/sed.c index d5a4a833..cea12ea5 100644 --- a/toys/posix/sed.c +++ b/toys/posix/sed.c @@ -881,7 +881,7 @@ writenow: for (cc = line; *cc; cc++) if (*cc == '\\' && cc[1] == ';') break; delim = *cc; *cc = 0; - fd = xcreate(line, O_WRONLY|O_CREAT|O_TRUNC, 0644); + fd = xcreate(line, O_WRONLY|O_CREAT|O_TRUNC|O_APPEND, 0644); *cc = delim; command->w = reg - (char *)command; -- 2.39.2