summaryrefslogtreecommitdiffstats
path: root/src/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc16
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.