From 083c746fe7c9b0b4d7b87eadf204483b10f750be Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Sun, 29 Aug 2021 03:52:44 -0400 Subject: open-file: fix broken file-creation modes. The "w+", "m+" and "a+" modes wouldn't create the file. * stream.c (w_fopen_mode): Add O_TRUNC and O_CREAT flags if m.create or m.append is set, rather than if m.read is unset and m.write is set. --- stream.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stream.c b/stream.c index f2ff72e2..f055a987 100644 --- a/stream.c +++ b/stream.c @@ -1126,8 +1126,9 @@ static FILE *w_fopen_mode(const wchar_t *wname, const wchar_t *mode, size_t nsiz = strlen(name) + 1; int flags = (if3(m.read && m.write, O_RDWR, 0) | 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.read && m.write, O_WRONLY, 0) | + if3(m.create || m.append, + if3(!m.notrunc, O_TRUNC, 0) | O_CREAT, 0) | if3(m.append, O_APPEND, 0) | if3(m.nonblock, O_NONBLOCK, 0)); char *stkname = coerce(char *, alloca(nsiz)); -- cgit v1.2.3