diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 03:20:13 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 03:20:13 +0000 |
commit | 87be8d353b3454383940ce5abc1a176268a33d33 (patch) | |
tree | 840a6a2944fa7116a5a27670fa3f23d1565d6822 /lib/Support/Windows/Path.inc | |
parent | 3a101048affcb00654b85558157150ad270fc46d (diff) | |
download | external_llvm-87be8d353b3454383940ce5abc1a176268a33d33.zip external_llvm-87be8d353b3454383940ce5abc1a176268a33d33.tar.gz external_llvm-87be8d353b3454383940ce5abc1a176268a33d33.tar.bz2 |
Add a version of sys::fs::status that uses fstat.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Windows/Path.inc')
-rw-r--r-- | lib/Support/Windows/Path.inc | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index 1ecd803..5787636 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -598,6 +598,35 @@ static bool isReservedName(StringRef path) { return false; } +static error_code getStatus(HANDLE FileHandle, file_status &Result) { + if (FileHandle == INVALID_HANDLE_VALUE) + goto handle_status_error; + + BY_HANDLE_FILE_INFORMATION Info; + if (!::GetFileInformationByHandle(FileHandle, &Info)) + goto handle_status_error; + + Result = file_status( + file_type::regular_file, Info.ftLastWriteTime.dwHighDateTime, + Info.ftLastWriteTime.dwLowDateTime, Info.dwVolumeSerialNumber, + Info.nFileSizeHigh, Info.nFileSizeLow, Info.nFileIndexHigh, + Info.nFileIndexLow); + return error_code::success(); + +handle_status_error: + error_code EC = windows_error(::GetLastError()); + if (EC == windows_error::file_not_found || + EC == windows_error::path_not_found) + Result = file_status(file_type::file_not_found); + else if (EC == windows_error::sharing_violation) + Result = file_status(file_type::type_unknown); + else { + Result = file_status(file_type::status_error); + return EC; + } + return error_code::success(); +} + error_code status(const Twine &path, file_status &result) { SmallString<128> path_storage; SmallVector<wchar_t, 128> path_utf16; @@ -613,7 +642,7 @@ error_code status(const Twine &path, file_status &result) { DWORD attr = ::GetFileAttributesW(path_utf16.begin()); if (attr == INVALID_FILE_ATTRIBUTES) - goto handle_status_error; + return getStatus(INVALID_HANDLE_VALUE, result); // Handle reparse points. if (attr & FILE_ATTRIBUTE_REPARSE_POINT) { @@ -626,7 +655,7 @@ error_code status(const Twine &path, file_status &result) { FILE_FLAG_BACKUP_SEMANTICS, 0)); if (!h) - goto handle_status_error; + return getStatus(INVALID_HANDLE_VALUE, result); } if (attr & FILE_ATTRIBUTE_DIRECTORY) @@ -641,32 +670,19 @@ error_code status(const Twine &path, file_status &result) { FILE_FLAG_BACKUP_SEMANTICS, 0)); if (!h) - goto handle_status_error; + return getStatus(INVALID_HANDLE_VALUE, result); BY_HANDLE_FILE_INFORMATION Info; if (!::GetFileInformationByHandle(h, &Info)) - goto handle_status_error; + return getStatus(INVALID_HANDLE_VALUE, result); - result = file_status( - file_type::regular_file, Info.ftLastWriteTime.dwHighDateTime, - Info.ftLastWriteTime.dwLowDateTime, Info.dwVolumeSerialNumber, - Info.nFileSizeHigh, Info.nFileSizeLow, Info.nFileIndexHigh, - Info.nFileIndexLow); + return getStatus(h, result); } return error_code::success(); +} -handle_status_error: - error_code ec = windows_error(::GetLastError()); - if (ec == windows_error::file_not_found || - ec == windows_error::path_not_found) - result = file_status(file_type::file_not_found); - else if (ec == windows_error::sharing_violation) - result = file_status(file_type::type_unknown); - else { - result = file_status(file_type::status_error); - return ec; - } - - return error_code::success(); +error_code status(int FD, file_status &Result) { + HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD)); + return getStatus(FileHandle, Result); } error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { |