summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/build_log.cc19
-rw-r--r--src/util.cc16
-rw-r--r--src/util.h3
3 files changed, 21 insertions, 17 deletions
diff --git a/src/build_log.cc b/src/build_log.cc
index 79143bf..43d5f01 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -15,13 +15,13 @@
#include "build_log.h"
#include <errno.h>
-#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "build.h"
#include "graph.h"
+#include "util.h"
// Implementation details:
// Each run's log appends to the log file.
@@ -35,21 +35,6 @@ namespace {
const char kFileSignature[] = "# ninja log v2\n";
const int kCurrentVersion = 2;
-void SetCloseOnExec(FILE* file) {
-#ifndef _WIN32
- int flags = fcntl(fileno(file), F_GETFD);
- if (flags < 0) {
- perror("fcntl(F_GETFD)");
- } else {
- if (fcntl(fileno(file), 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
-}
-
}
BuildLog::BuildLog()
@@ -71,7 +56,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) {
return false;
}
setvbuf(log_file_, NULL, _IOLBF, BUFSIZ);
- SetCloseOnExec(log_file_);
+ SetCloseOnExec(fileno(log_file_));
if (ftell(log_file_) == 0) {
if (fwrite(kFileSignature, sizeof(kFileSignature) - 1, 1, log_file_) < 1) {
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.
diff --git a/src/util.h b/src/util.h
index c9e06f4..d66bd84 100644
--- a/src/util.h
+++ b/src/util.h
@@ -41,6 +41,9 @@ int MakeDir(const string& path);
/// Returns -errno and fills in \a err on error.
int ReadFile(const string& path, string* contents, string* err);
+/// Mark a file descriptor to not be inherited on exec()s.
+void SetCloseOnExec(int fd);
+
/// Get the current time as relative to some epoch.
/// Epoch varies between platforms; only useful for measuring elapsed
/// time.