Expose a single global file open function.
This one allows much more flexibility than the standard
openFileForRead / openFileForWrite functions. Since there is now
just one "real" function that does the work, all other implementations
simply delegate to this one.
llvm-svn: 334246
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 59d2cb5..c4c4cfc 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -759,9 +759,9 @@
return Result;
}
-static std::error_code openFile(const Twine &Name, int &ResultFD,
- CreationDisposition Disp, FileAccess Access,
- OpenFlags Flags, unsigned Mode) {
+std::error_code openFile(const Twine &Name, int &ResultFD,
+ CreationDisposition Disp, FileAccess Access,
+ OpenFlags Flags, unsigned Mode) {
int OpenFlags = nativeOpenFlags(Disp, Flags, Access);
SmallString<128> Storage;
@@ -777,6 +777,17 @@
return std::error_code();
}
+Expected<int> openNativeFile(const Twine &Name, CreationDisposition Disp,
+ FileAccess Access, OpenFlags Flags,
+ unsigned Mode) {
+
+ int FD;
+ std::error_code EC = openFile(Name, FD, Disp, Access, Flags, Mode);
+ if (EC)
+ return errorCodeToError(EC);
+ return FD;
+}
+
std::error_code openFileForRead(const Twine &Name, int &ResultFD,
OpenFlags Flags,
SmallVectorImpl<char> *RealPath) {
@@ -824,38 +835,6 @@
return ResultFD;
}
-std::error_code openFileForWrite(const Twine &Name, int &ResultFD,
- CreationDisposition Disp, OpenFlags Flags,
- unsigned Mode) {
- return openFile(Name, ResultFD, Disp, FA_Write, Flags, Mode);
-}
-
-Expected<file_t> openNativeFileForWrite(const Twine &Name,
- CreationDisposition Disp,
- OpenFlags Flags, unsigned Mode) {
- file_t ResultFD;
- std::error_code EC = openFileForWrite(Name, ResultFD, Disp, Flags, Mode);
- if (EC)
- return errorCodeToError(EC);
- return ResultFD;
-}
-
-std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD,
- CreationDisposition Disp, OpenFlags Flags,
- unsigned Mode) {
- return openFile(Name, ResultFD, Disp, FA_Read | FA_Write, Flags, Mode);
-}
-
-Expected<file_t> openNativeFileForReadWrite(const Twine &Name,
- CreationDisposition Disp,
- OpenFlags Flags, unsigned Mode) {
- file_t ResultFD;
- std::error_code EC = openFileForReadWrite(Name, ResultFD, Disp, Flags, Mode);
- if (EC)
- return errorCodeToError(EC);
- return ResultFD;
-}
-
void closeFile(file_t &F) {
::close(F);
F = kInvalidFile;