From 1c58683353103cab7835e94d24baa33bd6c931ba Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 1 Aug 2013 12:14:57 +0000 Subject: PR#5568: add O_CLOEXEC flag to Unix.openfile, so that the returned file descriptor is created in close-on-exec mode. (Reflecting commit r13961 on version/4.01) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13962 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- otherlibs/win32unix/open.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'otherlibs/win32unix/open.c') diff --git a/otherlibs/win32unix/open.c b/otherlibs/win32unix/open.c index 40ea34b63..a2ffa4e1e 100644 --- a/otherlibs/win32unix/open.c +++ b/otherlibs/win32unix/open.c @@ -16,22 +16,26 @@ #include "unixsupport.h" #include -static int open_access_flags[13] = { +static int open_access_flags[14] = { GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static int open_create_flags[13] = { - 0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 0, 0, 0, 0, 0 +static int open_create_flags[14] = { + 0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 0, 0, 0, 0, 0, 0 }; -static int open_share_flags[13] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FILE_SHARE_DELETE +static int open_share_flags[14] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FILE_SHARE_DELETE, 0 +}; + +static int open_cloexec_flags[14] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; CAMLprim value unix_open(value path, value flags, value perm) { - int fileaccess, createflags, fileattrib, filecreate, sharemode; + int fileaccess, createflags, fileattrib, filecreate, sharemode, cloexec; SECURITY_ATTRIBUTES attr; HANDLE h; @@ -55,9 +59,10 @@ CAMLprim value unix_open(value path, value flags, value perm) else fileattrib = FILE_ATTRIBUTE_NORMAL; + cloexec = convert_flag_list(flags, open_cloexec_flags); attr.nLength = sizeof(attr); attr.lpSecurityDescriptor = NULL; - attr.bInheritHandle = TRUE; + attr.bInheritHandle = cloexec ? FALSE : TRUE; h = CreateFile(String_val(path), fileaccess, sharemode, &attr, -- cgit v1.2.3-70-g09d2