diff options
author | Paul A. Patience <paul@apatience.com> | 2021-08-29 03:52:44 -0400 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-08-29 08:06:39 -0700 |
commit | 083c746fe7c9b0b4d7b87eadf204483b10f750be (patch) | |
tree | 04a430ba738a4b73e95976617f3bfe92e63fde20 | |
parent | 75528b512fe6cf45a8bb20c2d4c171701da034f2 (diff) | |
download | txr-083c746fe7c9b0b4d7b87eadf204483b10f750be.tar.gz txr-083c746fe7c9b0b4d7b87eadf204483b10f750be.tar.bz2 txr-083c746fe7c9b0b4d7b87eadf204483b10f750be.zip |
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.
-rw-r--r-- | stream.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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)); |