Skip to content

Commit

Permalink
Merge pull request libgit2#2360 from phkelley/noinherit
Browse files Browse the repository at this point in the history
Win32: Supply _O_NOINHERIT when calling _wopen
  • Loading branch information
arrbee committed May 16, 2014
2 parents 228272e + f0b820d commit adebcb1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/win32/posix_w32.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
# define FILE_NAME_NORMALIZED 0
#endif

/* Options which we always provide to _wopen.
*
* _O_BINARY - Raw access; no translation of CR or LF characters
* _O_NOINHERIT - Do not mark the created handle as inheritable by child processes.
* The Windows default is 'not inheritable', but the CRT's default (following
* POSIX convention) is 'inheritable'. We have no desire for our handles to be
* inheritable on Windows, so specify the flag to get default behavior back. */
#define STANDARD_OPEN_FLAGS (_O_BINARY | _O_NOINHERIT)

/* GetFinalPathNameByHandleW signature */
typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);

Expand Down Expand Up @@ -317,7 +326,7 @@ int p_open(const char *path, int flags, ...)
va_end(arg_list);
}

return _wopen(buf, flags | _O_BINARY, mode);
return _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode);
}

int p_creat(const char *path, mode_t mode)
Expand All @@ -327,7 +336,7 @@ int p_creat(const char *path, mode_t mode)
if (utf8_to_16_with_errno(buf, path) < 0)
return -1;

return _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | _O_BINARY, mode);
return _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | STANDARD_OPEN_FLAGS, mode);
}

int p_getcwd(char *buffer_out, size_t size)
Expand Down

0 comments on commit adebcb1

Please sign in to comment.