From 4548ee03f1e6495751dfe31fa2bf416819257ce4 Mon Sep 17 00:00:00 2001 From: Qingning Huo Date: Tue, 13 Mar 2012 23:28:44 +0000 Subject: Add a Windows version of SetCloseOnExec() --- src/util.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/util.cc b/src/util.cc index 02be994..4d9adf3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -197,9 +197,10 @@ void SetCloseOnExec(int fd) { perror("fcntl(F_SETFD)"); } #else - // On Windows, handles must be explicitly marked to be passed to a - // spawned process, so there's nothing to do here. - NINJA_UNUSED_ARG(fd); + HANDLE hd = (HANDLE) _get_osfhandle(fd); + if (! SetHandleInformation(hd, HANDLE_FLAG_INHERIT, 0)) { + fprintf(stderr, "SetHandleInformation(): %s", GetLastErrorString().c_str()); + } #endif // ! _WIN32 } -- cgit v0.12