Skip to content

Commit

Permalink
Fix Flags in NS_open
Browse files Browse the repository at this point in the history
- Handle the O_CREATE | O_TRUNC case
- Read only should be set it _write_ permissions are not set
  • Loading branch information
gmittert committed Jun 11, 2019
1 parent e1071a9 commit 442a91e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CoreFoundation/Base.subproj/CFPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <Security.h>

#define getcwd _NS_getcwd
#define open _NS_open

#endif

Expand Down Expand Up @@ -901,6 +902,9 @@ CF_EXPORT int _NS_open(const char *name, int oflag, int pmode) {

DWORD dwCreationDisposition;
switch (oflag & (O_CREAT | O_EXCL | O_TRUNC)) {
case O_CREAT | O_TRUNC:
dwCreationDisposition = CREATE_ALWAYS;
break;
case O_CREAT:
dwCreationDisposition = OPEN_ALWAYS;
break;
Expand All @@ -916,7 +920,7 @@ CF_EXPORT int _NS_open(const char *name, int oflag, int pmode) {

// Backup semantics are required to receive a handle to a directory
DWORD dwFlagsAndAttributes = FILE_FLAG_BACKUP_SEMANTICS;
if (pmode & _S_IREAD) {
if (!(pmode & _S_IWRITE)) {
dwFlagsAndAttributes |= FILE_ATTRIBUTE_READONLY;
}

Expand Down

0 comments on commit 442a91e

Please sign in to comment.