mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-08 04:51:23 +00:00
Split realPathFromHandle in two.
By having an UTF-16 version we avoid some code duplication in calling GetFinalPathNameByHandleW. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318583 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
43a4579060
commit
53742c5e59
@ -344,20 +344,15 @@ std::error_code is_local(const Twine &path, bool &result) {
|
||||
return is_local_internal(WidePath, result);
|
||||
}
|
||||
|
||||
static std::error_code realPathFromHandle(HANDLE H,
|
||||
SmallVectorImpl<wchar_t> &Buffer);
|
||||
|
||||
std::error_code is_local(int FD, bool &Result) {
|
||||
SmallVector<wchar_t, 128> FinalPath;
|
||||
HANDLE Handle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
|
||||
|
||||
size_t Len = 128;
|
||||
do {
|
||||
FinalPath.reserve(Len);
|
||||
Len = ::GetFinalPathNameByHandleW(Handle, FinalPath.data(),
|
||||
FinalPath.capacity() - 1, VOLUME_NAME_NT);
|
||||
if (Len == 0)
|
||||
return mapWindowsError(::GetLastError());
|
||||
} while (Len > FinalPath.capacity());
|
||||
|
||||
FinalPath.set_size(Len);
|
||||
if (std::error_code EC = realPathFromHandle(Handle, FinalPath))
|
||||
return EC;
|
||||
|
||||
return is_local_internal(FinalPath, Result);
|
||||
}
|
||||
@ -917,9 +912,7 @@ ErrorOr<basic_file_status> directory_entry::status() const {
|
||||
}
|
||||
|
||||
static std::error_code realPathFromHandle(HANDLE H,
|
||||
SmallVectorImpl<char> &RealPath) {
|
||||
RealPath.clear();
|
||||
llvm::SmallVector<wchar_t, MAX_PATH> Buffer;
|
||||
SmallVectorImpl<wchar_t> &Buffer) {
|
||||
DWORD CountChars = ::GetFinalPathNameByHandleW(
|
||||
H, Buffer.begin(), Buffer.capacity() - 1, FILE_NAME_NORMALIZED);
|
||||
if (CountChars > Buffer.capacity()) {
|
||||
@ -931,8 +924,19 @@ static std::error_code realPathFromHandle(HANDLE H,
|
||||
}
|
||||
if (CountChars == 0)
|
||||
return mapWindowsError(GetLastError());
|
||||
Buffer.set_size(CountChars);
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
static std::error_code realPathFromHandle(HANDLE H,
|
||||
SmallVectorImpl<char> &RealPath) {
|
||||
RealPath.clear();
|
||||
SmallVector<wchar_t, MAX_PATH> Buffer;
|
||||
if (std::error_code EC = realPathFromHandle(H, Buffer))
|
||||
return EC;
|
||||
|
||||
const wchar_t *Data = Buffer.data();
|
||||
DWORD CountChars = Buffer.size();
|
||||
if (CountChars >= 4) {
|
||||
if (0 == ::memcmp(Data, L"\\\\?\\", 8)) {
|
||||
CountChars -= 4;
|
||||
|
Loading…
Reference in New Issue
Block a user