diff options
author | Zachary Turner <zturner@google.com> | 2018-06-07 23:25:13 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-06-07 23:25:13 +0000 |
commit | 9d2cfa6cccbe710f724f1a94cb65df9787c8f077 (patch) | |
tree | c1e7aa1f44776badff9d3d13717f929b644c5889 /llvm/lib/Support/Unix | |
parent | f0f51755182f6935f44b5f247ad45e38c1130d21 (diff) | |
download | bcm5719-llvm-9d2cfa6cccbe710f724f1a94cb65df9787c8f077.tar.gz bcm5719-llvm-9d2cfa6cccbe710f724f1a94cb65df9787c8f077.zip |
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
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 59d2cb58cf0..c4c4cfc3afe 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -759,9 +759,9 @@ static int nativeOpenFlags(CreationDisposition Disp, OpenFlags Flags, 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 @@ static std::error_code openFile(const Twine &Name, int &ResultFD, 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 @@ Expected<file_t> openNativeFileForRead(const Twine &Name, OpenFlags Flags, 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; |