From: Christopher Dykes Date: Wed, 3 Aug 2016 22:09:29 +0000 (-0700) Subject: Fix the mode being used in the implementation of open in the Fcntl portability header X-Git-Tag: v2016.08.08.00~26 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=a0f8eed7f6e9a75451d0b7e7436e998ffeaea112;p=folly.git 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 --- diff --git a/folly/portability/Fcntl.cpp b/folly/portability/Fcntl.cpp index be0a428e..e02a767c 100755 --- a/folly/portability/Fcntl.cpp +++ b/folly/portability/Fcntl.cpp @@ -18,6 +18,7 @@ #ifdef _WIN32 #include +#include #include namespace folly { @@ -80,7 +81,17 @@ int fcntl(int fd, int cmd, ...) { int open(char const* fn, int of, int pm) { 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; }