1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

tool_cb_wrt: fix outfile mode flags for Windows

- Use S_IREAD and S_IWRITE mode permission flags to create the file
  on Windows instead of S_IRUSR, S_IWUSR, etc.

Windows only accepts a combination of S_IREAD and S_IWRITE. It does not
acknowledge other combinations, for which it may generate an assertion.

This is a follow-up to 81b4e99 from yesterday, which improved the
existing file check with -J.

Ref: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/open-wopen#remarks
Ref: https://github.com/curl/curl/pull/5731

Closes https://github.com/curl/curl/pull/5742
This commit is contained in:
Jay Satiro 2020-07-29 03:21:57 -04:00
parent 2f72ad44fc
commit 5f79891658

View File

@ -26,6 +26,8 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#include <sys/stat.h>
#define ENABLE_CURLX_PRINTF #define ENABLE_CURLX_PRINTF
/* use our own printf() functions */ /* use our own printf() functions */
#include "curlx.h" #include "curlx.h"
@ -57,9 +59,10 @@ bool tool_create_output_file(struct OutStruct *outs,
#define O_BINARY 0 #define O_BINARY 0
#endif #endif
int fd = open(outs->filename, O_CREAT | O_WRONLY | O_EXCL | O_BINARY, int fd = open(outs->filename, O_CREAT | O_WRONLY | O_EXCL | O_BINARY,
S_IRUSR | S_IWUSR #ifdef WIN32
#ifdef S_IRGRP S_IREAD | S_IWRITE
| S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH #else
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
#endif #endif
); );
if(fd != -1) { if(fd != -1) {