Commit a0f8eed7 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 4

Fix the mode being used in the implementation of open in the Fcntl portability header

Summary: The mode parameter to `open` under MSVC is not the same as the mode parameter everywhere else, so we need to do a bit of translation.

Reviewed By: yfeldblum

Differential Revision: D3651218

fbshipit-source-id: 80df1e15f34b8d66533256107d8c9218f757fde2
parent abb963a0
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <folly/portability/Sockets.h> #include <folly/portability/Sockets.h>
#include <folly/portability/SysStat.h>
#include <folly/portability/Windows.h> #include <folly/portability/Windows.h>
namespace folly { namespace folly {
...@@ -80,7 +81,17 @@ int fcntl(int fd, int cmd, ...) { ...@@ -80,7 +81,17 @@ int fcntl(int fd, int cmd, ...) {
int open(char const* fn, int of, int pm) { int open(char const* fn, int of, int pm) {
int fh; int fh;
errno_t res = _sopen_s(&fh, fn, of, _SH_DENYNO, pm); int realMode = _S_IREAD;
if ((of & _O_RDWR) == _O_RDWR) {
realMode = _S_IREAD | _S_IWRITE;
} else if ((of & _O_WRONLY) == _O_WRONLY) {
realMode = _S_IWRITE;
} else if ((of & _O_RDONLY) != _O_RDONLY) {
// One of these needs to be present, just fail if
// none are.
return -1;
}
errno_t res = _sopen_s(&fh, fn, of, _SH_DENYNO, realMode);
return res ? -1 : fh; return res ? -1 : fh;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment