forked from OSchip/llvm-project
parent
041299e3eb
commit
8dc0e1095f
|
@ -345,7 +345,41 @@ std::error_code is_local(const Twine &path, bool &result) {
|
|||
}
|
||||
|
||||
static std::error_code realPathFromHandle(HANDLE H,
|
||||
SmallVectorImpl<wchar_t> &Buffer);
|
||||
SmallVectorImpl<wchar_t> &Buffer) {
|
||||
DWORD CountChars = ::GetFinalPathNameByHandleW(
|
||||
H, Buffer.begin(), Buffer.capacity() - 1, FILE_NAME_NORMALIZED);
|
||||
if (CountChars > Buffer.capacity()) {
|
||||
// The buffer wasn't big enough, try again. In this case the return value
|
||||
// *does* indicate the size of the null terminator.
|
||||
Buffer.reserve(CountChars);
|
||||
CountChars = ::GetFinalPathNameByHandleW(
|
||||
H, Buffer.data(), Buffer.capacity() - 1, FILE_NAME_NORMALIZED);
|
||||
}
|
||||
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;
|
||||
Data += 4;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert the result from UTF-16 to UTF-8.
|
||||
return UTF16ToUTF8(Data, CountChars, RealPath);
|
||||
}
|
||||
|
||||
std::error_code is_local(int FD, bool &Result) {
|
||||
SmallVector<wchar_t, 128> FinalPath;
|
||||
|
@ -911,43 +945,6 @@ ErrorOr<basic_file_status> directory_entry::status() const {
|
|||
return Status;
|
||||
}
|
||||
|
||||
static std::error_code realPathFromHandle(HANDLE H,
|
||||
SmallVectorImpl<wchar_t> &Buffer) {
|
||||
DWORD CountChars = ::GetFinalPathNameByHandleW(
|
||||
H, Buffer.begin(), Buffer.capacity() - 1, FILE_NAME_NORMALIZED);
|
||||
if (CountChars > Buffer.capacity()) {
|
||||
// The buffer wasn't big enough, try again. In this case the return value
|
||||
// *does* indicate the size of the null terminator.
|
||||
Buffer.reserve(CountChars);
|
||||
CountChars = ::GetFinalPathNameByHandleW(
|
||||
H, Buffer.data(), Buffer.capacity() - 1, FILE_NAME_NORMALIZED);
|
||||
}
|
||||
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;
|
||||
Data += 4;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert the result from UTF-16 to UTF-8.
|
||||
return UTF16ToUTF8(Data, CountChars, RealPath);
|
||||
}
|
||||
|
||||
static std::error_code directoryRealPath(const Twine &Name,
|
||||
SmallVectorImpl<char> &RealPath) {
|
||||
SmallVector<wchar_t, 128> PathUTF16;
|
||||
|
|
Loading…
Reference in New Issue