summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-19 15:02:03 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-19 15:02:03 +0000
commit67080cec2558a32ce3a50bc505e2197bc947b6a6 (patch)
tree859864110273006fe26da2a5800e29ca96ca3474 /llvm/lib/Support/Unix
parent84ab9b3b8fcf4a2ac671050959f43950a108a19b (diff)
downloadbcm5719-llvm-67080cec2558a32ce3a50bc505e2197bc947b6a6.tar.gz
bcm5719-llvm-67080cec2558a32ce3a50bc505e2197bc947b6a6.zip
Split openFileForWrite into windows and unix versions.
It is similar to 186511, but for creating files for writing. llvm-svn: 186679
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r--llvm/lib/Support/Unix/Path.inc25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 89440089704..ccd60e5fbd1 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -766,6 +766,31 @@ error_code openFileForRead(const Twine &Name, int &ResultFD) {
return error_code::success();
}
+error_code openFileForWrite(const Twine &Name, int &ResultFD,
+ sys::fs::OpenFlags Flags, unsigned Mode) {
+ // Verify that we don't have both "append" and "excl".
+ assert((!(Flags & sys::fs::F_Excl) || !(Flags & sys::fs::F_Append)) &&
+ "Cannot specify both 'excl' and 'append' file creation flags!");
+
+ int OpenFlags = O_WRONLY | O_CREAT;
+
+ if (Flags & F_Append)
+ OpenFlags |= O_APPEND;
+ else
+ OpenFlags |= O_TRUNC;
+
+ if (Flags & F_Excl)
+ OpenFlags |= O_EXCL;
+
+ SmallString<128> Storage;
+ StringRef P = Name.toNullTerminatedStringRef(Storage);
+ while ((ResultFD = open(P.begin(), OpenFlags, Mode)) < 0) {
+ if (errno != EINTR)
+ return error_code(errno, system_category());
+ }
+ return error_code::success();
+}
+
} // end namespace fs
} // end namespace sys
} // end namespace llvm
OpenPOWER on IntegriCloud