[llvm] [Windows][Support] Add helper to expand short 8.3 form paths (PR #178480)
Ben Dunbobbin via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 03:38:43 PST 2026
================
@@ -2485,6 +2486,145 @@ TEST_F(FileSystemTest, widenPath) {
#endif
#ifdef _WIN32
+/// Checks whether short 8.3 form names are enabled in the given UTF-8 path.
+static llvm::Expected<bool> areShortNamesEnabled(llvm::StringRef Path8) {
+ // Create a directory under Path8 with a name long enough that Windows will
+ // provide a short 8.3 form name, if short 8.3 form names are enabled.
+ SmallString<256> Dir(Path8);
+ path::append(Dir, "verylongdir");
+ if (std::error_code EC = fs::create_directories(Dir))
+ return llvm::errorCodeToError(EC);
+ scope_exit Close([&] { fs::remove_directories(Dir); });
+
+ SmallVector<wchar_t, MAX_PATH> Path16;
+ if (std::error_code EC = sys::windows::widenPath(Dir, Path16))
+ return llvm::errorCodeToError(EC);
+
+ WIN32_FIND_DATAW Data;
+ HANDLE H = ::FindFirstFileW(Path16.data(), &Data);
+ if (H == INVALID_HANDLE_VALUE)
+ return llvm::make_error<llvm::StringError>(
+ "FindFirstFileW returned invalid handle",
+ llvm::inconvertibleErrorCode());
+ ::FindClose(H);
+
+ return (Data.cAlternateFileName[0] != L'\0');
----------------
bd1976bris wrote:
> While looking again at the `FindFirstFileW` documentation, I did notice that the string must be null-terminated. I modified the code to ensure that.
Apologies for the noise. `widenPath` does guarantee null termination. I have reverted the code back to as it was when approved.
https://github.com/llvm/llvm-project/pull/178480
More information about the llvm-commits
mailing list