Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2261)

Unified Diff: base/files/file_util.h

Issue 2678813003: Disable fd/handle sharing in base::ReadFileToString. (Closed)
Patch Set: comment tweaks Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/files/file_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_util.h
diff --git a/base/files/file_util.h b/base/files/file_util.h
index 77a87e7dade7df8db204dfd33aaafe7209c8a06b..06f3fc1e2c11e7156e029b82547172bd75c57427 100644
--- a/base/files/file_util.h
+++ b/base/files/file_util.h
@@ -35,6 +35,22 @@
#include "base/posix/eintr_wrapper.h"
#endif
+// fopen() takes a mode string that is typically something along the lines of
+// "r" or "w+". By default, files opened via fopen() are opened such that they
+// spill into child processes via the normal platform features (e.g., the file
+// is opened with bInheritHandle=TRUE in its security descriptor on Windows).
+// The character for a mode string to disable this spillage is not consistent
+// across platforms. Define the macro FONE (i.e., "fopen 'N' or 'e'") for use in
+// cross platform code that calls base::OpenFile (or calls fopen directly).
+#if defined(OS_WIN)
+// "N" specifies that the underlying handle is not inherited by child processes
+// (bInheritHandle=FALSE).
+#define FONE "N"
+#else // defined(OS_WIN)
+// "e" specifies that the underlying descriptor is closed on exec (FD_CLOEXEC).
+#define FONE "e"
+#endif // defined(OS_WIN)
+
namespace base {
class Environment;
@@ -307,7 +323,9 @@ BASE_EXPORT bool TouchFile(const FilePath& path,
const Time& last_accessed,
const Time& last_modified);
-// Wrapper for fopen-like calls. Returns non-NULL FILE* on success.
+// Wrapper for fopen-like calls. Returns non-NULL FILE* on success. By default,
+// opened files will be inheritable by child processes. Append the FONE macro
+// (defined above) when composing a |mode| string to disable this.
BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode);
// Closes file opened by OpenFile. Returns true on success.
« no previous file with comments | « no previous file | base/files/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698