1 /**************************************************************************/
2 /* */
3 /* OCaml */
4 /* */
5 /* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */
6 /* */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. */
9 /* */
10 /* All rights reserved. This file is distributed under the terms of */
11 /* the GNU Lesser General Public License version 2.1, with the */
12 /* special exception on linking described in the file LICENSE. */
13 /* */
14 /**************************************************************************/
15
16 #include <caml/mlvalues.h>
17 #include "unixsupport.h"
18 #include <windows.h>
19
win_set_inherit(value fd,BOOL inherit)20 int win_set_inherit(value fd, BOOL inherit)
21 {
22 /* According to the MSDN, SetHandleInformation may not work
23 for console handles on WinNT4 and earlier versions. */
24 if (! SetHandleInformation(Handle_val(fd),
25 HANDLE_FLAG_INHERIT,
26 inherit ? HANDLE_FLAG_INHERIT : 0)) {
27 win32_maperr(GetLastError());
28 return -1;
29 }
30 return 0;
31 }
32
win_set_close_on_exec(value fd)33 CAMLprim value win_set_close_on_exec(value fd)
34 {
35 if (win_set_inherit(fd, FALSE) == -1) uerror("set_close_on_exec", Nothing);
36 return Val_unit;
37 }
38
win_clear_close_on_exec(value fd)39 CAMLprim value win_clear_close_on_exec(value fd)
40 {
41 if (win_set_inherit(fd, TRUE) == -1) uerror("clear_close_on_exec", Nothing);
42 return Val_unit;
43 }
44