diff options
author | Zachary Turner <zturner@google.com> | 2018-06-04 19:38:11 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-06-04 19:38:11 +0000 |
commit | 63db25ba0d5eaba5fb18816a970750e23420fd03 (patch) | |
tree | 99f4c7b7ab1f96bde8e1f83c773d5eab0b0c7ad6 /llvm/lib/Support/Unix/Path.inc | |
parent | 95ed88a1a93cdc15cf02e25849a6b5a8c2be3bb8 (diff) | |
download | bcm5719-llvm-63db25ba0d5eaba5fb18816a970750e23420fd03.tar.gz bcm5719-llvm-63db25ba0d5eaba5fb18816a970750e23420fd03.zip |
[Support] Add functions that operate on native file handles on Windows.
Windows' CRT has a limit of 512 open file descriptors, and fds which are
generated by converting a HANDLE via _get_osfhandle count towards this
limit as well.
Regardless, often you find yourself marshalling back and forth between
native HANDLE objects and fds anyway. If we know from the getgo that
we're going to need to work directly with the handle, we can cut out the
marshalling layer while also not contributing to filling up the CRT's
very limited handle table.
On Unix these functions just delegate directly to the existing set of
functions since an fd *is* the native file type. It would be nice, very
long term, if we could convert most uses of fds to file_t.
Differential Revision: https://reviews.llvm.org/D47688
llvm-svn: 333945
Diffstat (limited to 'llvm/lib/Support/Unix/Path.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index f9778321dd2..fbfbed66fbc 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -93,6 +93,9 @@ using namespace llvm; namespace llvm { namespace sys { namespace fs { + +const file_t kInvalidFile = -1; + #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \ defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) @@ -761,6 +764,15 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD, return std::error_code(); } +Expected<file_t> openNativeFileForRead(const Twine &Name, + SmallVectorImpl<char> *RealPath) { + file_t ResultFD; + std::error_code EC = openFileForRead(Name, ResultFD, RealPath); + if (EC) + return errorCodeToError(EC); + return ResultFD; +} + std::error_code openFileForWrite(const Twine &Name, int &ResultFD, sys::fs::OpenFlags Flags, unsigned Mode) { // Verify that we don't have both "append" and "excl". @@ -798,6 +810,20 @@ std::error_code openFileForWrite(const Twine &Name, int &ResultFD, return std::error_code(); } +Expected<file_t> openNativeFileForWrite(const Twine &Name, OpenFlags Flags, + unsigned Mode) { + file_t ResultFD; + std::error_code EC = openFileForWrite(Name, ResultFD, Flags, Mode); + if (EC) + return errorCodeToError(EC); + return ResultFD; +} + +void closeFile(file_t &F) { + ::close(F); + F = kInvalidFile; +} + template <typename T> static std::error_code remove_directories_impl(const T &Entry, bool IgnoreErrors) { |