diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-19 15:02:03 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-19 15:02:03 +0000 |
commit | b1a003f37725a31e5e744c46112b628c5e0aeb8a (patch) | |
tree | 836521091143142749d41ea9cb7a14c3d62e3a21 /lib/Support/Unix/Path.inc | |
parent | c9c9825c93791e0b1c0055e1d47ad2e6a703931e (diff) | |
download | llvm-b1a003f37725a31e5e744c46112b628c5e0aeb8a.tar.gz llvm-b1a003f37725a31e5e744c46112b628c5e0aeb8a.tar.bz2 llvm-b1a003f37725a31e5e744c46112b628c5e0aeb8a.tar.xz |
Split openFileForWrite into windows and unix versions.
It is similar to 186511, but for creating files for writing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186679 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Unix/Path.inc')
-rw-r--r-- | lib/Support/Unix/Path.inc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 8944008970..ccd60e5fbd 100644 --- a/lib/Support/Unix/Path.inc +++ b/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 |