summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Windows/Path.inc
diff options
context:
space:
mode:
authorTaewook Oh <twoh@fb.com>2016-06-03 18:38:39 +0000
committerTaewook Oh <twoh@fb.com>2016-06-03 18:38:39 +0000
commitdfec58e80ce1c4c0213a587ac41688c3d31a2e96 (patch)
tree7e6284e7b121e149819a1be9263ef8d31c515fad /llvm/lib/Support/Windows/Path.inc
parent5859a9ed80829bf3eee5f8e9946b0ab0d2142600 (diff)
downloadbcm5719-llvm-dfec58e80ce1c4c0213a587ac41688c3d31a2e96.tar.gz
bcm5719-llvm-dfec58e80ce1c4c0213a587ac41688c3d31a2e96.zip
In openFileForRead, attempt to fetch the actual name of the file on disk -- including case -- so that clang can later warn about non-portable #include and #import directives.
Differential Revision: http://reviews.llvm.org/D19842 Patch by Eric Niebler llvm-svn: 271704
Diffstat (limited to 'llvm/lib/Support/Windows/Path.inc')
-rw-r--r--llvm/lib/Support/Windows/Path.inc46
1 files changed, 45 insertions, 1 deletions
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index f2f34d85e32..5f588d7884e 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -707,7 +707,8 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &it) {
return std::error_code();
}
-std::error_code openFileForRead(const Twine &Name, int &ResultFD) {
+std::error_code openFileForRead(const Twine &Name, int &ResultFD,
+ SmallVectorImpl<char> *RealPath) {
SmallVector<wchar_t, 128> PathUTF16;
if (std::error_code EC = widenPath(Name, PathUTF16))
@@ -736,6 +737,22 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD) {
return mapWindowsError(ERROR_INVALID_HANDLE);
}
+ // Fetch the real name of the file, if the user asked
+ if (RealPath) {
+ RealPath->clear();
+ wchar_t RealPathUTF16[MAX_PATH];
+ DWORD CountChars =
+ ::GetFinalPathNameByHandleW(H, RealPathUTF16, MAX_PATH,
+ FILE_NAME_NORMALIZED);
+ if (CountChars > 0 && CountChars < MAX_PATH) {
+ // Convert the result from UTF-16 to UTF-8.
+ SmallString<MAX_PATH> RealPathUTF8;
+ if (!UTF16ToUTF8(RealPathUTF16, CountChars, RealPathUTF8))
+ RealPath->append(RealPathUTF8.data(),
+ RealPathUTF8.data() + strlen(RealPathUTF8.data()));
+ }
+ }
+
ResultFD = FD;
return std::error_code();
}
@@ -796,6 +813,32 @@ std::error_code openFileForWrite(const Twine &Name, int &ResultFD,
ResultFD = FD;
return std::error_code();
}
+
+std::error_code getPathFromOpenFD(int FD, SmallVectorImpl<char> &ResultPath) {
+ HANDLE FileHandle = reinterpret_cast<HANDLE>(::_get_osfhandle(FD));
+ if (FileHandle == INVALID_HANDLE_VALUE)
+ return make_error_code(errc::bad_file_descriptor);
+
+ DWORD CharCount;
+ do {
+ CharCount = ::GetFinalPathNameByHandleA(FileHandle, ResultPath.begin(),
+ ResultPath.capacity(), FILE_NAME_NORMALIZED);
+ if (CharCount <= ResultPath.capacity())
+ break;
+ ResultPath.reserve(CharCount);
+ } while (true);
+
+ if (CharCount == 0)
+ return mapWindowsError(::GetLastError());
+
+ ResultPath.set_size(CharCount);
+
+ // On earlier Windows releases, the character count includes the terminating null.
+ if (ResultPath.back() == '\0')
+ ResultPath.pop_back();
+
+ return std::error_code();
+}
} // end namespace fs
namespace path {
@@ -930,6 +973,7 @@ std::error_code UTF16ToCurCP(const wchar_t *utf16, size_t utf16_len,
llvm::SmallVectorImpl<char> &utf8) {
return UTF16ToCodePage(CP_ACP, utf16, utf16_len, utf8);
}
+
} // end namespace windows
} // end namespace sys
} // end namespace llvm
OpenPOWER on IntegriCloud