summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul A. Patience <paul@apatience.com>2021-08-29 03:52:44 -0400
committerKaz Kylheku <kaz@kylheku.com>2021-08-29 08:06:39 -0700
commit702d02d7958a20e8cd0e6872ca12540c84cdca55 (patch)
tree04a430ba738a4b73e95976617f3bfe92e63fde20
parentb293cebe662de083d0925f0238b7a81a35b9eb3c (diff)
downloadtxr-702d02d7958a20e8cd0e6872ca12540c84cdca55.tar.gz
txr-702d02d7958a20e8cd0e6872ca12540c84cdca55.tar.bz2
txr-702d02d7958a20e8cd0e6872ca12540c84cdca55.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.c5
1 files 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));