diff options
author | Russell Belfer <rb@github.com> | 2014-05-16 10:42:17 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-16 10:42:17 -0700 |
commit | adebcb1645f7bd652ff4449ecf41c39ded12d0c7 (patch) | |
tree | d09e1c3cbad4f2defe7c740ce1f88f18f44e7618 | |
parent | 228272ef5828e1e6d42f48acad3a557b340ddc90 (diff) | |
parent | f0b820dd67ee6ac53bf6bebd84dfa5c709c4b499 (diff) | |
download | libgit2-adebcb1645f7bd652ff4449ecf41c39ded12d0c7.tar.gz |
Merge pull request #2360 from phkelley/noinherit
Win32: Supply _O_NOINHERIT when calling _wopen
-rw-r--r-- | src/win32/posix_w32.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 0d070f6b5..73bf92572 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -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); @@ -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) @@ -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) |