From ab3a0ff7212753b5df32b7afc836bb367fef6de0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 17 Apr 2020 19:08:56 -0700 Subject: open-file: fix broken append mode. * stream.c (w_fopen_mode): Add O_APPEND flag if m.append is set. (do_parse_mode): Set m.notrunc flag for append mode, so O_TRUNC won't be added in w_fopen_mode. --- stream.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stream.c b/stream.c index ce3f02b9..ae8f384e 100644 --- a/stream.c +++ b/stream.c @@ -1092,6 +1092,7 @@ static FILE *w_fopen_mode(const wchar_t *wname, const wchar_t *mode, if3(m.read && !m.write, O_RDONLY, 0) | if3(!m.read && m.write, if3(!m.notrunc, O_TRUNC, 0) | O_WRONLY | O_CREAT, 0) | + if3(m.append, O_APPEND, 0) | if3(m.nonblock, O_NONBLOCK, 0)); char *stkname = coerce(char *, alloca(nsiz)); int fd; @@ -1418,6 +1419,7 @@ static struct stdio_mode do_parse_mode(val mode_str, struct stdio_mode m_dfl) ms++; m.write = 1; m.append = 1; + m.notrunc = 1; break; case 'm': ms++; -- cgit v1.2.3