From 4fb4946cc302c2d78f47c4f78afa093df6ce7017 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 29 Aug 2021 08:22:44 -0700 Subject: open-file: improvement: "a" mode sets create flag. * stream.c (w_fopen_mode): Only test the m.create flag as the basis for O_CREAT, not m.append. (do_parse_mode): In the 'a' case, set m.create = 1, since all variants of append mode create the file. --- stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stream.c b/stream.c index 1183f7f5..9db94380 100644 --- a/stream.c +++ b/stream.c @@ -1127,8 +1127,7 @@ static FILE *w_fopen_mode(const wchar_t *wname, const wchar_t *mode, int flags = (if3(m.read && m.write, O_RDWR, 0) | if3(m.read && !m.write, O_RDONLY, 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.create, if3(!m.notrunc, O_TRUNC, 0) | O_CREAT, 0) | if3(m.append, O_APPEND, 0) | if3(m.excl, O_EXCL, 0) | if3(m.nonblock, O_NONBLOCK, 0)); @@ -1459,6 +1458,7 @@ static struct stdio_mode do_parse_mode(val mode_str, struct stdio_mode m_dfl, case 'a': ms++; m.write = 1; + m.create = 1; m.append = 1; m.notrunc = 1; break; -- cgit v1.2.3