[PATCH] D28894: [Support] Use O_CLOEXEC only when declared
Michał Górny via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 19 01:33:34 PST 2017
mgorny created this revision.
Use the O_CLOEXEC flag only when it is available. Some old systems (e.g.
SLES10) do not support this flag. POSIX explicitly guarantees that this
flag can be checked for using #if, so there is no need for a CMake
check.
Repository:
rL LLVM
https://reviews.llvm.org/D28894
Files:
lib/Support/Unix/Path.inc
Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -577,7 +577,11 @@
SmallVectorImpl<char> *RealPath) {
SmallString<128> Storage;
StringRef P = Name.toNullTerminatedStringRef(Storage);
- while ((ResultFD = open(P.begin(), O_RDONLY | O_CLOEXEC)) < 0) {
+ int OpenFlags = O_RDONLY;
+#ifdef O_CLOEXEC
+ OpenFlags |= O_CLOEXEC;
+#endif
+ while ((ResultFD = open(P.begin(), OpenFlags)) < 0) {
if (errno != EINTR)
return std::error_code(errno, std::generic_category());
}
@@ -614,7 +618,11 @@
assert((!(Flags & sys::fs::F_Excl) || !(Flags & sys::fs::F_Append)) &&
"Cannot specify both 'excl' and 'append' file creation flags!");
- int OpenFlags = O_CREAT | O_CLOEXEC;
+ int OpenFlags = O_CREAT;
+
+#ifdef O_CLOEXEC
+ OpenFlags |= O_CLOEXEC;
+#endif
if (Flags & F_RW)
OpenFlags |= O_RDWR;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28894.84948.patch
Type: text/x-patch
Size: 981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170119/52514524/attachment.bin>
More information about the llvm-commits
mailing list