From 72afa0779d02188c90f322d9b8546f22c4ff99d7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 28 Jul 2020 10:41:30 +0200 Subject: fixup adjust for windows open(), close fd if fdopen fails --- src/tool_cb_wrt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/tool_cb_wrt.c') 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 */ -- cgit v1.2.1