summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/open.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2013-08-01 12:14:57 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2013-08-01 12:14:57 +0000
commit1c58683353103cab7835e94d24baa33bd6c931ba (patch)
treeb6be10a3b1b00ee1a7a0b7c523fea4fa9d8da4b7 /otherlibs/win32unix/open.c
parent5e78d37215f673f0b8d90ee760206f8f169b1b7d (diff)
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
Diffstat (limited to 'otherlibs/win32unix/open.c')
-rw-r--r--otherlibs/win32unix/open.c21
1 files changed, 13 insertions, 8 deletions
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 <fcntl.h>
-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,