diff options
author | Evan Martin <martine@danga.com> | 2011-10-31 22:30:29 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-10-31 22:39:53 (GMT) |
commit | a6212990930c1ca85488bada1936ce41aac34364 (patch) | |
tree | e1c84770f336b6ce3cd2671473709580374e7ebe /src/util.cc | |
parent | afbe2185a3bbd2453d6b1c27ee8f7c1cce6371a3 (diff) | |
download | Ninja-a6212990930c1ca85488bada1936ce41aac34364.zip Ninja-a6212990930c1ca85488bada1936ce41aac34364.tar.gz Ninja-a6212990930c1ca85488bada1936ce41aac34364.tar.bz2 |
move SetCloseOnExec to util
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index e2b20d6..f386a8c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -19,6 +19,7 @@ #endif #include <errno.h> +#include <fcntl.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -158,6 +159,21 @@ int ReadFile(const string& path, string* contents, string* err) { return 0; } +void SetCloseOnExec(int fd) { +#ifndef _WIN32 + int flags = fcntl(fd, F_GETFD); + if (flags < 0) { + perror("fcntl(F_GETFD)"); + } else { + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) + 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. +#endif // WIN32 +} + int64_t GetTimeMillis() { #ifdef _WIN32 // GetTickCount64 is only available on Vista or later. |