diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 1996-09-09 15:02:35 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 1996-09-09 15:02:35 +0000 |
commit | 4a6ea1c013f5f3b742f91d4a9ccae59853c8d58c (patch) | |
tree | 6eca4dd6fc474941e351f84823a94ae63e9765da /otherlibs/win32unix/close_on.c | |
parent | 607ae44a56d0579f6f812be6026f31c16ccdeb00 (diff) |
Makefile.nt: MAJ.
close_on.c: autre implementation qui marche peut-etre sous 95.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@978 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix/close_on.c')
-rw-r--r-- | otherlibs/win32unix/close_on.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/otherlibs/win32unix/close_on.c b/otherlibs/win32unix/close_on.c index 70bb9d0e2..ba32350a2 100644 --- a/otherlibs/win32unix/close_on.c +++ b/otherlibs/win32unix/close_on.c @@ -15,6 +15,8 @@ #include <windows.h> #include "unixsupport.h" +#if 0 + /* This works only under Windows NT, but not 95 */ value win_set_close_on_exec(fd) /* ML */ @@ -27,7 +29,7 @@ value win_set_close_on_exec(fd) /* ML */ ! SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0)) { _dosmaperr(GetLastError()); uerror("set_close_on_exec", Nothing); - }; + } return Val_unit; } @@ -39,8 +41,50 @@ value win_clear_close_on_exec(fd) /* ML */ if (h == (HANDLE) -1 || ! SetHandleInformation(h, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) { _dosmaperr(GetLastError()); + uerror("clear_close_on_exec", Nothing); + } + return Val_unit; +} + +#else + +extern int _set_osfhnd(int fd, long value); + +static int win_realloc_handle(fd, inherit) + int fd; + BOOL inherit; +{ + HANDLE oldh, newh; + + oldh = (HANDLE) _get_osfhandle(fd); + if (oldh == (HANDLE) -1) return -1; + if (! DuplicateHandle(GetCurrentProcess(), oldh, + GetCurrentProcess(), &newh, + 0L, inherit, DUPLICATE_SAME_ACCESS)) { + _dosmaperr(GetLastError()); + return -1; + } + _close(fd); + _set_osfhnd(fd, (long) newh); + return 0; +} + +value win_set_close_on_exec(fd) /* ML */ + value fd; +{ + if (win_realloc_handle(Int_val(fd), FALSE) == -1) { uerror("set_close_on_exec", Nothing); - }; + } + return Val_unit; +} + +value win_clear_close_on_exec(fd) /* ML */ + value fd; +{ + if (win_realloc_handle(Int_val(fd), TRUE) == -1) { + uerror("clear_close_on_exec", Nothing); + } return Val_unit; } +#endif |