Add a Windows version of SetCloseOnExec()
authorQingning Huo <qingninghuo@gmail.com>
Tue, 13 Mar 2012 23:28:44 +0000 (23:28 +0000)
committerQingning Huo <qingninghuo@gmail.com>
Tue, 13 Mar 2012 23:28:44 +0000 (23:28 +0000)
src/util.cc

index 02be994b0ce0cd24c731dddf4ffd16798ad17894..4d9adf3f5b4ffe78a694f4702ddd919ced071304 100644 (file)
@@ -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
 }