diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-07-28 10:41:30 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-07-28 10:41:30 +0200 |
commit | 72afa0779d02188c90f322d9b8546f22c4ff99d7 (patch) | |
tree | 3c0ce33ddc3dcc29fd3b38e89a451dfa04042aec | |
parent | 159b011425eeaa96ff25fbb9bd298ded11307c35 (diff) | |
download | curl-bagder/curl-cd-overwrite-check.tar.gz |
fixup adjust for windows open(), close fd if fdopen failsbagder/curl-cd-overwrite-check
-rw-r--r-- | src/tool_cb_wrt.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/tool_cb_wrt.c b/src/tool_cb_wrt.c index 8e9ee55aa..e0742630b 100644 --- a/src/tool_cb_wrt.c +++ b/src/tool_cb_wrt.c @@ -53,9 +53,20 @@ bool tool_create_output_file(struct OutStruct *outs, if(outs->is_cd_filename) { /* don't overwrite existing files */ - int fd = open(outs->filename, O_CREAT | O_WRONLY | O_EXCL, 0666); - if(fd != -1) +#ifndef O_BINARY +#define O_BINARY 0 +#endif + int fd = open(outs->filename, O_CREAT | O_WRONLY | O_EXCL | O_BINARY, + S_IRUSR | S_IWUSR +#ifdef S_IRGRP + | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH +#endif + ); + if(fd != -1) { file = fdopen(fd, "wb"); + if(!file) + close(fd); + } } else /* open file for writing */ |