817bdca13e367ea3ad7ba767bea2b3f913720380
[trex.git] /
1 # NOTE: win32 support is currently experimental, and not recommended
2 # for production use.
3
4
5 from __future__ import absolute_import, division, print_function, with_statement
6 import ctypes
7 import ctypes.wintypes
8
9 # See: http://msdn.microsoft.com/en-us/library/ms724935(VS.85).aspx
10 SetHandleInformation = ctypes.windll.kernel32.SetHandleInformation
11 SetHandleInformation.argtypes = (ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD)
12 SetHandleInformation.restype = ctypes.wintypes.BOOL
13
14 HANDLE_FLAG_INHERIT = 0x00000001
15
16
17 def set_close_exec(fd):
18     success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
19     if not success:
20         raise ctypes.GetLastError()