36#ifndef _ERRNO_T_DEFINED
37#define _ERRNO_T_DEFINED
42#pragma comment(lib, "advapi32.lib")
43#pragma comment(lib, "ole32.lib")
48using llvm::sys::windows::CurCPToUTF16;
49using llvm::sys::windows::UTF16ToUTF8;
50using llvm::sys::windows::UTF8ToUTF16;
68static constexpr wchar_t LongPathPrefix16[] = LR
"(\\?\)";
69static constexpr wchar_t LongPathUNCPrefix16[] = LR
"(\\?\UNC\)";
71static constexpr DWORD LongPathPrefix16Len =
72 static_cast<DWORD
>(std::size(LongPathPrefix16) - 1);
73static constexpr DWORD LongPathUNCPrefix16Len =
74 static_cast<DWORD
>(std::size(LongPathUNCPrefix16) - 1);
76static void stripLongPathPrefix(
wchar_t *&
Data, DWORD &CountChars) {
77 if (CountChars >= LongPathUNCPrefix16Len &&
78 ::wmemcmp(
Data, LongPathUNCPrefix16, LongPathUNCPrefix16Len) == 0) {
83 }
else if (CountChars >= LongPathPrefix16Len &&
84 ::wmemcmp(
Data, LongPathPrefix16, LongPathPrefix16Len) == 0) {
98std::error_code
widenPath(
const Twine &Path8, SmallVectorImpl<wchar_t> &Path16,
100 assert(MaxPathLen <= MAX_PATH);
104 SmallString<MAX_PATH> Path8Str;
112 if (std::error_code EC = UTF8ToUTF16(Path8Str, Path16))
120 CurPathLen = ::GetCurrentDirectoryW(
126 if ((Path16.
size() + CurPathLen) < MaxPathLen ||
128 return std::error_code();
143 "Root name cannot be empty for an absolute path!");
145 SmallString<2 * MAX_PATH> FullPath;
146 if (RootName[1] !=
':') {
147 FullPath.
append(LongPathUNCPrefix8);
150 FullPath.
append(LongPathPrefix8);
151 FullPath.
append(Path8Str);
154 return UTF8ToUTF16(FullPath, Path16);
158 llvm::SmallVectorImpl<char> &Result8) {
159 SmallString<128> PathStorage;
160 StringRef PathStr = Path8.
toStringRef(PathStorage);
161 bool HadPrefix = PathStr.
starts_with(LongPathPrefix8);
164 if (std::error_code EC =
widenPath(PathStr, Path16))
175 Len = ::GetLongPathNameW(Path16.
data(), Long16.
data(), Len);
186 }
while (Len > Long16.
size());
196 stripLongPathPrefix(
Data, Len);
198 return sys::windows::UTF16ToUTF8(
Data, Len, Result8);
229 if (UTF16ToUTF8(PathName.
data(), PathName.
size(), PathNameUTF8))
234 SmallString<256> RealPath;
237 return std::string(RealPath);
238 return std::string(PathNameUTF8.
data());
242 return UniqueID(VolumeSerialNumber, PathHash);
245ErrorOr<space_info>
disk_space(
const Twine &Path) {
249 if (std::error_code EC =
widenPath(Path, PathUTF16))
252 if (!::GetDiskFreeSpaceExW(PathUTF16.
data(), &Avail, &
Total, &
Free))
257 SpaceInfo.free =
Free.QuadPart;
258 SpaceInfo.available = Avail.QuadPart;
265 Time.dwLowDateTime = LastAccessedTimeLow;
266 Time.dwHighDateTime = LastAccessedTimeHigh;
272 Time.dwLowDateTime = LastWriteTimeLow;
273 Time.dwHighDateTime = LastWriteTimeHigh;
279std::error_code
current_path(SmallVectorImpl<char> &result) {
283 DWORD len = MAX_PATH;
287 len = ::GetCurrentDirectoryW(cur_path.
size(), cur_path.
data());
295 }
while (len > cur_path.
size());
301 if (std::error_code EC =
302 UTF16ToUTF8(cur_path.
begin(), cur_path.
size(), result))
306 return std::error_code();
314 if (std::error_code ec =
widenPath(path, wide_path))
317 if (!::SetCurrentDirectoryW(wide_path.
begin()))
320 return std::error_code();
329 if (std::error_code ec =
widenPath(path, path_utf16, MAX_PATH - 12))
332 if (!::CreateDirectoryW(path_utf16.
begin(), NULL)) {
333 DWORD LastError = ::GetLastError();
334 if (LastError != ERROR_ALREADY_EXISTS || !IgnoreExisting)
338 return std::error_code();
341std::error_code
create_symlink(
const Twine &to,
const Twine &from) {
344 SmallString<128> ToStr;
349 if (std::error_code ec =
widenPath(from, WideFrom))
351 if (std::error_code ec =
widenPath(ToStr, WideTo))
359 const SmallVectorImpl<wchar_t> *AttrPath = &WideTo;
362 SmallString<128> FromStr;
366 if (std::error_code ec =
widenPath(Resolved, WideResolved))
368 AttrPath = &WideResolved;
371 DWORD Attr = ::GetFileAttributesW(AttrPath->
begin());
372 if (Attr == INVALID_FILE_ATTRIBUTES) {
373 DWORD Err = ::GetLastError();
374 if (Err != ERROR_FILE_NOT_FOUND && Err != ERROR_PATH_NOT_FOUND)
378 }
else if (Attr & FILE_ATTRIBUTE_DIRECTORY) {
379 Flags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
384 if (::CreateSymbolicLinkW(WideFrom.
begin(), WideTo.
begin(),
386 SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE))
387 return std::error_code();
390 DWORD Err = ::GetLastError();
391 if (Err == ERROR_INVALID_PARAMETER) {
392 if (::CreateSymbolicLinkW(WideFrom.
begin(), WideTo.
begin(), Flags))
393 return std::error_code();
394 Err = ::GetLastError();
400std::error_code
create_link(
const Twine &to,
const Twine &from) {
411 if (std::error_code ec =
widenPath(from, wide_from))
413 if (std::error_code ec =
widenPath(to, wide_to))
416 if (!::CreateHardLinkW(wide_from.
begin(), wide_to.
begin(), NULL))
419 return std::error_code();
422std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting) {
425 if (std::error_code ec =
widenPath(path, path_utf16))
439 c_str(path_utf16), DELETE,
440 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
442 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS |
443 FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_DELETE_ON_CLOSE,
451 return std::error_code();
454static std::error_code is_local_internal(SmallVectorImpl<wchar_t> &Path,
461 ::GetVolumePathNameW(
Path.data(), VolumePath.
data(), VolumePath.
size());
466 DWORD Err = ::GetLastError();
467 if (Err != ERROR_INSUFFICIENT_BUFFER)
477 const wchar_t *
P = VolumePath.
data();
479 UINT
Type = ::GetDriveTypeW(
P);
483 return std::error_code();
487 case DRIVE_REMOVABLE:
489 return std::error_code();
496std::error_code
is_local(
const Twine &path,
bool &result) {
502 SmallString<128> Storage;
507 if (std::error_code ec =
widenPath(
P, WidePath))
509 return is_local_internal(WidePath, result);
512static std::error_code realPathFromHandle(HANDLE
H,
513 SmallVectorImpl<wchar_t> &Buffer,
514 DWORD flags = VOLUME_NAME_DOS) {
516 DWORD CountChars = ::GetFinalPathNameByHandleW(
517 H, Buffer.
begin(), Buffer.
capacity(), FILE_NAME_NORMALIZED | flags);
518 if (CountChars && CountChars >= Buffer.
capacity()) {
522 CountChars = ::GetFinalPathNameByHandleW(
H, Buffer.
begin(), Buffer.
size(),
523 FILE_NAME_NORMALIZED | flags);
528 return std::error_code();
531static std::error_code realPathFromHandle(HANDLE
H,
532 SmallVectorImpl<char> &RealPath) {
535 if (std::error_code EC = realPathFromHandle(
H, Buffer))
542 stripLongPathPrefix(
Data, CountChars);
545 if (std::error_code EC = UTF16ToUTF8(
Data, CountChars, RealPath))
549 return std::error_code();
552std::error_code
is_local(
int FD,
bool &Result) {
556 HANDLE Handle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
558 if (std::error_code EC = realPathFromHandle(Handle, FinalPath))
561 return is_local_internal(FinalPath, Result);
564static std::error_code setDeleteDisposition(HANDLE Handle,
bool Delete) {
569 FILE_DISPOSITION_INFO Disposition;
570 Disposition.DeleteFile =
false;
571 if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition,
572 sizeof(Disposition)))
575 return std::error_code();
581 if (std::error_code EC = realPathFromHandle(Handle, FinalPath))
585 if (std::error_code EC = is_local_internal(FinalPath, IsLocal))
593 Disposition.DeleteFile =
true;
594 if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition,
595 sizeof(Disposition)))
597 return std::error_code();
600static std::error_code rename_internal(HANDLE FromHandle,
const Twine &To,
601 bool ReplaceIfExists) {
606 std::vector<char> RenameInfoBuf(
sizeof(FILE_RENAME_INFO) -
sizeof(
wchar_t) +
607 (ToWide.
size() *
sizeof(
wchar_t)));
608 FILE_RENAME_INFO &RenameInfo =
609 *
reinterpret_cast<FILE_RENAME_INFO *
>(RenameInfoBuf.data());
610 RenameInfo.ReplaceIfExists = ReplaceIfExists;
611 RenameInfo.RootDirectory = 0;
612 RenameInfo.FileNameLength = ToWide.
size() *
sizeof(wchar_t);
613 std::copy(ToWide.
begin(), ToWide.
end(), &RenameInfo.FileName[0]);
615 SetLastError(ERROR_SUCCESS);
616 if (!SetFileInformationByHandle(FromHandle, FileRenameInfo, &RenameInfo,
617 RenameInfoBuf.size())) {
618 unsigned Error = GetLastError();
619 if (
Error == ERROR_SUCCESS)
620 Error = ERROR_CALL_NOT_IMPLEMENTED;
624 return std::error_code();
627static std::error_code rename_handle(HANDLE FromHandle,
const Twine &To) {
629 if (std::error_code EC =
widenPath(To, WideTo))
635 for (
unsigned Retry = 0; Retry != 200; ++Retry) {
636 auto EC = rename_internal(FromHandle, To,
true);
639 std::error_code(ERROR_CALL_NOT_IMPLEMENTED, std::system_category())) {
643 if (std::error_code EC2 = realPathFromHandle(FromHandle, WideFrom))
645 if (::MoveFileExW(WideFrom.
begin(), WideTo.
begin(),
646 MOVEFILE_REPLACE_EXISTING))
647 return std::error_code();
661 ::CreateFileW(WideTo.
begin(), GENERIC_READ | DELETE,
662 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
664 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL));
675 BY_HANDLE_FILE_INFORMATION FI;
676 if (!GetFileInformationByHandle(ToHandle, &FI))
680 for (
unsigned UniqueId = 0; UniqueId != 200; ++UniqueId) {
681 std::string TmpFilename = (To +
".tmp" +
utostr(UniqueId)).str();
682 if (
auto EC = rename_internal(ToHandle, TmpFilename,
false)) {
690 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
691 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
698 BY_HANDLE_FILE_INFORMATION FI2;
699 if (!GetFileInformationByHandle(ToHandle2, &FI2))
701 if (FI.nFileIndexHigh != FI2.nFileIndexHigh ||
702 FI.nFileIndexLow != FI2.nFileIndexLow ||
703 FI.dwVolumeSerialNumber != FI2.dwVolumeSerialNumber)
722std::error_code
rename(
const Twine &From,
const Twine &To) {
725 if (std::error_code EC =
widenPath(From, WideFrom))
730 for (
unsigned Retry = 0; Retry != 200; ++Retry) {
736 ::CreateFileW(WideFrom.
begin(), GENERIC_READ | DELETE,
737 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
738 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
750 return rename_handle(FromHandle, To);
759 return std::error_code(
error, std::generic_category());
763 HANDLE hFile =
reinterpret_cast<HANDLE
>(::_get_osfhandle(FD));
765 if (!DeviceIoControl(hFile, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &temp,
769 LARGE_INTEGER liSize;
770 liSize.QuadPart =
Size;
771 if (!SetFilePointerEx(hFile, liSize, NULL, FILE_BEGIN) ||
772 !SetEndOfFile(hFile)) {
775 return std::error_code();
783 if (std::error_code EC =
widenPath(Path, PathUtf16))
794 DWORD LastError = ::GetLastError();
795 if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND)
806 return std::error_code();
816 return A.getUniqueID() ==
B.getUniqueID();
819std::error_code
equivalent(
const Twine &
A,
const Twine &
B,
bool &result) {
823 if (std::error_code ec =
status(
A, fsA))
825 if (std::error_code ec =
status(
B, fsB))
828 return std::error_code();
831static bool isReservedName(StringRef path) {
834 static const char *
const sReservedNames[] = {
835 "nul",
"con",
"prn",
"aux",
"com1",
"com2",
"com3",
"com4",
836 "com5",
"com6",
"com7",
"com8",
"com9",
"lpt1",
"lpt2",
"lpt3",
837 "lpt4",
"lpt5",
"lpt6",
"lpt7",
"lpt8",
"lpt9"};
845 for (
size_t i = 0; i < std::size(sReservedNames); ++i) {
854static file_type file_type_from_attrs(DWORD Attrs) {
859static perms perms_from_attrs(DWORD Attrs) {
863static std::error_code getStatus(HANDLE FileHandle,
file_status &Result) {
865 if (FileHandle == INVALID_HANDLE_VALUE)
866 goto handle_status_error;
868 switch (::GetFileType(FileHandle)) {
871 case FILE_TYPE_UNKNOWN: {
872 DWORD Err = ::GetLastError();
876 return std::error_code();
882 return std::error_code();
885 return std::error_code();
888 BY_HANDLE_FILE_INFORMATION
Info;
889 if (!::GetFileInformationByHandle(FileHandle, &Info))
890 goto handle_status_error;
903 if (std::error_code EC =
904 realPathFromHandle(FileHandle, ntPath, VOLUME_NAME_NT)) {
910 PathHash = (
static_cast<uint64_t
>(
Info.nFileIndexHigh) << 32ULL) |
911 static_cast<uint64_t
>(
Info.nFileIndexLow);
917 file_type_from_attrs(
Info.dwFileAttributes),
918 perms_from_attrs(
Info.dwFileAttributes),
Info.nNumberOfLinks,
919 Info.ftLastAccessTime.dwHighDateTime,
Info.ftLastAccessTime.dwLowDateTime,
920 Info.ftLastWriteTime.dwHighDateTime,
Info.ftLastWriteTime.dwLowDateTime,
921 Info.dwVolumeSerialNumber,
Info.nFileSizeHigh,
Info.nFileSizeLow,
923 return std::error_code();
927 if (Err == std::errc::no_such_file_or_directory)
929 else if (Err == std::errc::permission_denied)
939 SmallString<128> path_storage;
943 if (isReservedName(path8)) {
945 return std::error_code();
948 if (std::error_code ec =
widenPath(path8, path_utf16))
953 DWORD attr = ::GetFileAttributesW(path_utf16.
begin());
954 if (attr == INVALID_FILE_ATTRIBUTES)
955 return getStatus(INVALID_HANDLE_VALUE, result);
958 if (attr & FILE_ATTRIBUTE_REPARSE_POINT)
959 Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
963 ::CreateFileW(path_utf16.
begin(), 0,
964 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
965 NULL, OPEN_EXISTING, Flags, 0));
967 return getStatus(INVALID_HANDLE_VALUE, result);
969 return getStatus(h, result);
975 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
976 return getStatus(FileHandle, Result);
982 return getStatus(FileHandle, Result);
989 if (std::error_code EC =
widenPath(Path, PathUTF16))
1014 return std::error_code();
1019 return std::make_error_code(std::errc::not_supported);
1025 FILETIME ModifyFT =
toFILETIME(ModificationTime);
1026 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
1027 if (!SetFileTime(FileHandle, NULL, &AccessFT, &ModifyFT))
1029 return std::error_code();
1032std::error_code mapped_file_region::init(
sys::fs::file_t OrigFileHandle,
1035 if (OrigFileHandle == INVALID_HANDLE_VALUE)
1041 flprotect = PAGE_READONLY;
1044 flprotect = PAGE_READWRITE;
1047 flprotect = PAGE_WRITECOPY;
1051 HANDLE FileMappingHandle = ::CreateFileMappingW(OrigFileHandle, 0, flprotect,
1053 if (FileMappingHandle == NULL) {
1058 DWORD dwDesiredAccess;
1061 dwDesiredAccess = FILE_MAP_READ;
1064 dwDesiredAccess = FILE_MAP_WRITE;
1067 dwDesiredAccess = FILE_MAP_COPY;
1070 Mapping = ::MapViewOfFile(FileMappingHandle, dwDesiredAccess,
Offset >> 32,
1071 Offset & 0xffffffff, Size);
1072 if (Mapping == NULL) {
1074 ::CloseHandle(FileMappingHandle);
1079 MEMORY_BASIC_INFORMATION mbi;
1080 SIZE_T
Result = VirtualQuery(Mapping, &mbi,
sizeof(mbi));
1083 ::UnmapViewOfFile(Mapping);
1084 ::CloseHandle(FileMappingHandle);
1087 Size = mbi.RegionSize;
1095 ::CloseHandle(FileMappingHandle);
1096 if (!::DuplicateHandle(::GetCurrentProcess(), OrigFileHandle,
1097 ::GetCurrentProcess(), &FileHandle, 0, 0,
1098 DUPLICATE_SAME_ACCESS)) {
1100 ::UnmapViewOfFile(Mapping);
1104 return std::error_code();
1108 size_t length, uint64_t offset,
1109 std::error_code &ec)
1115 copyFrom(mapped_file_region());
1118static bool hasFlushBufferKernelBug() {
1124 static const char PEMagic[] = {
'P',
'E',
'\0',
'\0'};
1128 if (
Magic.substr(off).starts_with(
StringRef(PEMagic,
sizeof(PEMagic))))
1134void mapped_file_region::unmapImpl() {
1139 ::UnmapViewOfFile(Mapping);
1141 if (
Mode == mapmode::readwrite) {
1142 bool DoFlush =
Exe && hasFlushBufferKernelBug();
1160 bool IsLocal =
false;
1162 if (!realPathFromHandle(FileHandle, FinalPath)) {
1165 is_local_internal(FinalPath, IsLocal);
1170 ::FlushFileBuffers(FileHandle);
1173 ::CloseHandle(FileHandle);
1177void mapped_file_region::dontNeedImpl() {}
1179void mapped_file_region::willNeedImpl() {
1180 struct MEMORY_RANGE_ENTRY {
1181 PVOID VirtualAddress;
1182 SIZE_T NumberOfBytes;
1186 typedef BOOL(WINAPI * PrefetchVirtualMemory_t)(
1187 HANDLE hProcess, ULONG_PTR NumberOfEntries,
1188 MEMORY_RANGE_ENTRY * VirtualAddresses, ULONG Flags);
1190 static auto pfnPrefetchVirtualMemory = []() -> PrefetchVirtualMemory_t {
1195 return (PrefetchVirtualMemory_t)::GetProcAddress(kernelM,
1196 "PrefetchVirtualMemory");
1198 if (pfnPrefetchVirtualMemory) {
1199 MEMORY_RANGE_ENTRY
Range{Mapping,
Size};
1200 pfnPrefetchVirtualMemory(::GetCurrentProcess(), 1, &
Range, 0);
1204std::error_code mapped_file_region::sync()
const {
1205 if (!::FlushViewOfFile(Mapping,
Size))
1207 if (!::FlushFileBuffers(FileHandle))
1209 return std::error_code();
1212int mapped_file_region::alignment() {
1213 SYSTEM_INFO SysInfo;
1214 ::GetSystemInfo(&SysInfo);
1215 return SysInfo.dwAllocationGranularity;
1218static basic_file_status status_from_find_data(WIN32_FIND_DATAW *FindData) {
1219 return basic_file_status(file_type_from_attrs(FindData->dwFileAttributes),
1220 perms_from_attrs(FindData->dwFileAttributes),
1221 FindData->ftLastAccessTime.dwHighDateTime,
1222 FindData->ftLastAccessTime.dwLowDateTime,
1223 FindData->ftLastWriteTime.dwHighDateTime,
1224 FindData->ftLastWriteTime.dwLowDateTime,
1225 FindData->nFileSizeHigh, FindData->nFileSizeLow);
1228std::error_code detail::directory_iterator_construct(detail::DirIterState &
IT,
1230 bool FollowSymlinks) {
1235 if (std::error_code EC =
widenPath(Path, PathUTF16))
1239 size_t PathUTF16Len = PathUTF16.
size();
1240 if (PathUTF16Len > 0 && !
is_separator(PathUTF16[PathUTF16Len - 1]) &&
1241 PathUTF16[PathUTF16Len - 1] != L
':') {
1249 WIN32_FIND_DATAW FirstFind;
1251 c_str(PathUTF16), FindExInfoBasic, &FirstFind, FindExSearchNameMatch,
1252 NULL, FIND_FIRST_EX_LARGE_FETCH));
1256 size_t FilenameLen = ::wcslen(FirstFind.cFileName);
1257 while ((FilenameLen == 1 && FirstFind.cFileName[0] == L
'.') ||
1258 (FilenameLen == 2 && FirstFind.cFileName[0] == L
'.' &&
1259 FirstFind.cFileName[1] == L
'.'))
1260 if (!::FindNextFileW(FindHandle, &FirstFind)) {
1261 DWORD LastError = ::GetLastError();
1263 if (LastError == ERROR_NO_MORE_FILES)
1264 return detail::directory_iterator_destruct(
IT);
1267 FilenameLen = ::wcslen(FirstFind.cFileName);
1272 if (std::error_code EC =
1273 UTF16ToUTF8(FirstFind.cFileName, ::wcslen(FirstFind.cFileName),
1274 DirectoryEntryNameUTF8))
1277 IT.IterationHandle = intptr_t(FindHandle.take());
1279 path::append(DirectoryEntryPath, DirectoryEntryNameUTF8);
1281 directory_entry(DirectoryEntryPath, FollowSymlinks,
1282 file_type_from_attrs(FirstFind.dwFileAttributes),
1283 status_from_find_data(&FirstFind));
1285 return std::error_code();
1288std::error_code detail::directory_iterator_destruct(detail::DirIterState &
IT) {
1289 if (
IT.IterationHandle != 0)
1292 IT.IterationHandle = 0;
1293 IT.CurrentEntry = directory_entry();
1294 return std::error_code();
1297std::error_code detail::directory_iterator_increment(detail::DirIterState &
IT) {
1300 WIN32_FIND_DATAW FindData;
1301 if (!::FindNextFileW(HANDLE(
IT.IterationHandle), &FindData)) {
1302 DWORD LastError = ::GetLastError();
1304 if (LastError == ERROR_NO_MORE_FILES)
1305 return detail::directory_iterator_destruct(
IT);
1309 size_t FilenameLen = ::wcslen(FindData.cFileName);
1310 if ((FilenameLen == 1 && FindData.cFileName[0] == L
'.') ||
1311 (FilenameLen == 2 && FindData.cFileName[0] == L
'.' &&
1312 FindData.cFileName[1] == L
'.'))
1316 if (std::error_code EC =
1317 UTF16ToUTF8(FindData.cFileName, ::wcslen(FindData.cFileName),
1318 DirectoryEntryPathUTF8))
1321 IT.CurrentEntry.replace_filename(
1322 Twine(DirectoryEntryPathUTF8),
1323 file_type_from_attrs(FindData.dwFileAttributes),
1324 status_from_find_data(&FindData));
1325 return std::error_code();
1330static std::error_code nativeFileToFd(Expected<HANDLE>
H,
int &ResultFD,
1332 int CrtOpenFlags = 0;
1333 if (Flags & OF_Append)
1334 CrtOpenFlags |= _O_APPEND;
1336 if (Flags & OF_CRLF) {
1337 assert(Flags & OF_Text &&
"Flags set OF_CRLF without OF_Text");
1338 CrtOpenFlags |= _O_TEXT;
1345 ResultFD = ::_open_osfhandle(intptr_t(*
H), CrtOpenFlags);
1346 if (ResultFD == -1) {
1350 return std::error_code();
1353static DWORD nativeDisposition(CreationDisposition Disp, OpenFlags Flags) {
1362 if (Flags & OF_Append)
1367 return CREATE_ALWAYS;
1373 return OPEN_EXISTING;
1378static DWORD nativeAccess(FileAccess
Access, OpenFlags Flags) {
1384 if (Flags & OF_Delete)
1386 if (Flags & OF_UpdateAtime)
1387 Result |= FILE_WRITE_ATTRIBUTES;
1391static std::error_code openNativeFileInternal(
const Twine &Name,
1392 file_t &ResultFile, DWORD Disp,
1393 DWORD
Access, DWORD Flags,
1394 bool Inherit =
false) {
1396 if (std::error_code EC =
widenPath(Name, PathUTF16))
1399 SECURITY_ATTRIBUTES SA;
1400 SA.nLength =
sizeof(SA);
1401 SA.lpSecurityDescriptor =
nullptr;
1402 SA.bInheritHandle = Inherit;
1406 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, &SA,
1408 if (
H == INVALID_HANDLE_VALUE) {
1409 DWORD LastError = ::GetLastError();
1414 if (LastError != ERROR_ACCESS_DENIED)
1421 return std::error_code();
1425 FileAccess
Access, OpenFlags Flags,
1430 assert((!(Disp == CD_CreateNew) || !(Flags & OF_Append)) &&
1431 "Cannot specify both 'CreateNew' and 'Append' file creation flags!");
1433 DWORD NativeDisp = nativeDisposition(Disp, Flags);
1434 DWORD NativeAccess = nativeAccess(
Access, Flags);
1436 bool Inherit =
false;
1437 if (Flags & OF_ChildInherit)
1441 std::error_code
EC = openNativeFileInternal(
1442 Name, Result, NativeDisp, NativeAccess, FILE_ATTRIBUTE_NORMAL, Inherit);
1446 if (Flags & OF_UpdateAtime) {
1448 SYSTEMTIME SystemTime;
1449 GetSystemTime(&SystemTime);
1450 if (SystemTimeToFileTime(&SystemTime, &FileTime) == 0 ||
1451 SetFileTime(Result, NULL, &FileTime, NULL) == 0) {
1452 DWORD LastError = ::GetLastError();
1453 ::CloseHandle(Result);
1462 CreationDisposition Disp, FileAccess
Access,
1463 OpenFlags Flags,
unsigned int Mode) {
1470 return nativeFileToFd(*Result, ResultFD, Flags);
1473static std::error_code directoryRealPath(
const Twine &Name,
1476 std::error_code
EC = openNativeFileInternal(
1477 Name, File, OPEN_EXISTING, GENERIC_READ, FILE_FLAG_BACKUP_SEMANTICS);
1481 EC = realPathFromHandle(File, RealPath);
1482 ::CloseHandle(File);
1492 return nativeFileToFd(std::move(NativeFile), ResultFD, OF_None);
1499 Expected<file_t>
Result =
1503 if (Result && RealPath)
1504 realPathFromHandle(*Result, *RealPath);
1510 return reinterpret_cast<HANDLE
>(::_get_osfhandle(FD));
1517static Expected<size_t> readNativeFileImpl(
file_t FileHandle,
1519 OVERLAPPED *Overlap) {
1523 std::min(
size_t(std::numeric_limits<DWORD>::max()), Buf.
size());
1524 DWORD BytesRead = 0;
1525 if (::ReadFile(FileHandle, Buf.
data(), BytesToRead, &BytesRead, Overlap))
1527 DWORD Err = ::GetLastError();
1529 if (Err == ERROR_BROKEN_PIPE || Err == ERROR_HANDLE_EOF)
1537 return readNativeFileImpl(FileHandle, Buf,
nullptr);
1545 OVERLAPPED Overlapped = {};
1548 return readNativeFileImpl(FileHandle, Buf, &Overlapped);
1553 DWORD Flags = Kind == LockKind::Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
1554 Flags |= LOCKFILE_FAIL_IMMEDIATELY;
1557 auto Start = std::chrono::steady_clock::now();
1560 if (::LockFileEx(File, Flags, 0, MAXDWORD, MAXDWORD, &OV))
1561 return std::error_code();
1562 DWORD Error = ::GetLastError();
1563 if (Error == ERROR_LOCK_VIOLATION) {
1570 }
while (std::chrono::steady_clock::now() < End);
1574std::error_code
lockFile(
int FD, LockKind Kind) {
1575 DWORD Flags = Kind == LockKind::Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
1578 if (::LockFileEx(File, Flags, 0, MAXDWORD, MAXDWORD, &OV))
1579 return std::error_code();
1580 DWORD Error = ::GetLastError();
1587 if (::UnlockFileEx(File, 0, MAXDWORD, MAXDWORD, &OV))
1588 return std::error_code();
1595 if (!::CloseHandle(TmpF))
1597 return std::error_code();
1605 std::error_code
EC =
widenPath(NativePath, Path16);
1606 if (EC && !IgnoreErrors)
1620 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
1624 IFileOperation *FileOp = NULL;
1625 HR = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL,
1626 IID_PPV_ARGS(&FileOp));
1630 HR = FileOp->SetOperationFlags(FOF_NO_UI | FOFX_NOCOPYHOOKS);
1633 PIDLIST_ABSOLUTE PIDL = ILCreateFromPathW(Path16.
data());
1635 IShellItem *ShItem = NULL;
1636 HR = SHCreateItemFromIDList(PIDL, IID_PPV_ARGS(&ShItem));
1640 HR = FileOp->DeleteItem(ShItem, NULL);
1643 HR = FileOp->PerformOperations();
1645 if (FAILED(HR) && !IgnoreErrors)
1647 return std::error_code();
1652 if (
Path.empty() || Path[0] !=
'~')
1660 if (!Expr.
empty()) {
1672 Path[0] = HomeDir[0];
1678 if (
path.isTriviallyEmpty())
1681 path.toVector(dest);
1682 expandTildeExpr(dest);
1688 bool expand_tilde) {
1692 if (
path.isTriviallyEmpty())
1693 return std::error_code();
1697 path.toVector(Storage);
1698 expandTildeExpr(Storage);
1703 return directoryRealPath(
path, dest);
1706 if (std::error_code EC =
1710 return std::error_code();
1715struct LLVM_REPARSE_DATA_BUFFER {
1716 unsigned long ReparseTag;
1717 unsigned short ReparseDataLength;
1721 unsigned short SubstituteNameOffset;
1722 unsigned short SubstituteNameLength;
1723 unsigned short PrintNameOffset;
1724 unsigned short PrintNameLength;
1725 unsigned long Flags;
1726 wchar_t PathBuffer[1];
1727 } SymbolicLinkReparseBuffer;
1729 unsigned short SubstituteNameOffset;
1730 unsigned short SubstituteNameLength;
1731 unsigned short PrintNameOffset;
1732 unsigned short PrintNameLength;
1733 wchar_t PathBuffer[1];
1734 } MountPointReparseBuffer;
1736 unsigned char DataBuffer[1];
1737 } GenericReparseBuffer;
1750 c_str(PathUTF16), FILE_READ_ATTRIBUTES,
1751 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1752 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
1759 LLVM_REPARSE_DATA_BUFFER RDB;
1760 char Buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
1762 DWORD BytesReturned;
1763 if (!::DeviceIoControl(
H, FSCTL_GET_REPARSE_POINT, NULL, 0, &RDB,
1764 sizeof(Buffer), &BytesReturned, NULL)) {
1765 DWORD Err = ::GetLastError();
1766 if (Err == ERROR_NOT_A_REPARSE_POINT)
1771 if (RDB.ReparseTag != IO_REPARSE_TAG_SYMLINK)
1774 const auto &SLB = RDB.SymbolicLinkReparseBuffer;
1775 size_t PathBufOffset =
1776 offsetof(LLVM_REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer);
1780 USHORT NameOffset, NameLength;
1781 if (SLB.PrintNameLength != 0) {
1782 NameOffset = SLB.PrintNameOffset;
1783 NameLength = SLB.PrintNameLength;
1785 NameOffset = SLB.SubstituteNameOffset;
1786 NameLength = SLB.SubstituteNameLength;
1790 if (PathBufOffset + NameOffset + NameLength > BytesReturned)
1793 const wchar_t *
Target = SLB.PathBuffer + NameOffset /
sizeof(wchar_t);
1794 USHORT TargetLen = NameLength /
sizeof(wchar_t);
1796 if (std::error_code EC = UTF16ToUTF8(
Target, TargetLen, dest))
1799 return std::error_code();
1805static bool getKnownFolderPath(KNOWNFOLDERID folderId,
1806 SmallVectorImpl<char> &result) {
1807 wchar_t *path =
nullptr;
1808 if (::SHGetKnownFolderPath(folderId, KF_FLAG_CREATE,
nullptr, &path) != S_OK)
1811 bool ok = !UTF16ToUTF8(path, ::wcslen(path), result);
1812 ::CoTaskMemFree(path);
1819 return getKnownFolderPath(FOLDERID_Profile, result);
1825 return getKnownFolderPath(FOLDERID_LocalAppData, result);
1829 return getKnownFolderPath(FOLDERID_LocalAppData, result);
1832static bool getTempDirEnvVar(
const wchar_t *Var, SmallVectorImpl<char> &Res) {
1833 SmallVector<wchar_t, 1024> Buf;
1837 Size = GetEnvironmentVariableW(Var, Buf.
data(), Buf.
size());
1845 return !windows::UTF16ToUTF8(Buf.
data(),
Size, Res);
1848static bool getTempDirEnvVar(SmallVectorImpl<char> &Res) {
1849 const wchar_t *EnvironmentVariables[] = {
L"TMP",
L"TEMP",
L"USERPROFILE"};
1850 for (
auto *Env : EnvironmentVariables) {
1851 if (getTempDirEnvVar(Env, Res))
1858 (void)ErasedOnReboot;
1865 if (getTempDirEnvVar(Result)) {
1868 fs::make_absolute(Result);
1873 const char *DefaultResult =
"C:\\Temp";
1874 Result.append(DefaultResult, DefaultResult + strlen(DefaultResult));
1880std::error_code CodePageToUTF16(
unsigned codepage, llvm::StringRef original,
1881 llvm::SmallVectorImpl<wchar_t> &utf16) {
1882 if (!original.
empty()) {
1884 ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.
begin(),
1895 ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.
begin(),
1907 return std::error_code();
1910std::error_code UTF8ToUTF16(llvm::StringRef utf8,
1911 llvm::SmallVectorImpl<wchar_t> &utf16) {
1912 return CodePageToUTF16(CP_UTF8, utf8, utf16);
1915std::error_code CurCPToUTF16(llvm::StringRef curcp,
1916 llvm::SmallVectorImpl<wchar_t> &utf16) {
1917 return CodePageToUTF16(CP_ACP, curcp, utf16);
1920static std::error_code UTF16ToCodePage(
unsigned codepage,
const wchar_t *utf16,
1922 llvm::SmallVectorImpl<char> &converted) {
1925 int len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len,
1926 converted.
begin(), 0, NULL, NULL);
1936 len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, converted.
data(),
1937 converted.
size(), NULL, NULL);
1948 return std::error_code();
1951std::error_code UTF16ToUTF8(
const wchar_t *utf16,
size_t utf16_len,
1952 llvm::SmallVectorImpl<char> &utf8) {
1953 return UTF16ToCodePage(CP_UTF8, utf16, utf16_len, utf8);
1956std::error_code UTF16ToCurCP(
const wchar_t *utf16,
size_t utf16_len,
1957 llvm::SmallVectorImpl<char> &curcp) {
1958 return UTF16ToCodePage(CP_ACP, utf16, utf16_len, curcp);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
amode Optimize addressing mode
#define offsetof(TYPE, MEMBER)
std::unique_ptr< MemoryBuffer > openFile(const Twine &Path)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
LLVM_ABI const file_t kInvalidFile
size_t size() const
size - Get the array size.
Represents either an error or a value T.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
bool starts_with(StringRef Prefix) const
starts_with - Check if this string starts with the given Prefix.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
void reserve(size_type N)
void truncate(size_type N)
Like resize, but requires that N is less than size().
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
StringRef take_until(function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that no character in the prefix satisfies the given predicat...
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
LLVM_ABI void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Represents a version number in the form major[.minor[.subminor[.build]]].
LLVM_ABI TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
LLVM_ABI TimePoint getLastAccessedTime() const
The file access time as reported from the underlying file system.
Represents the result of a call to sys::fs::status().
LLVM_ABI uint32_t getLinkCount() const
LLVM_ABI UniqueID getUniqueID() const
mapped_file_region()=default
@ priv
May modify via data, but changes are lost on destruction.
@ readonly
May only access map via const_data as read only.
@ readwrite
May access map via data and modify it. Written to path.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
@ Resolved
Queried, materialization begun.
uint32_t read32le(const void *P)
LLVM_ABI std::error_code directory_iterator_increment(DirIterState &)
LLVM_ABI std::error_code readlink(const Twine &path, SmallVectorImpl< char > &output)
Read the target of a symbolic link.
LLVM_ABI bool can_execute(const Twine &Path)
Can we execute this file?
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
LLVM_ABI std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
LLVM_ABI std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
LLVM_ABI const file_t kInvalidFile
LLVM_ABI std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
LLVM_ABI ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
LLVM_ABI Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
LLVM_ABI unsigned getUmask()
Get file creation mode mask of the process.
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
LLVM_ABI Expected< file_t > openNativeFile(const Twine &Name, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
Opens a file with the specified creation disposition, access mode, and flags and returns a platform-s...
LLVM_ABI file_t getStdoutHandle()
Return an open handle to standard out.
file_type
An enumeration for the file system's view of the type.
LLVM_ABI std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
LLVM_ABI std::error_code create_symlink(const Twine &to, const Twine &from)
Create a symbolic link from from to to.
LLVM_ABI void expand_tilde(const Twine &path, SmallVectorImpl< char > &output)
Expands ~ expressions to the user's home directory.
LLVM_ABI std::error_code lockFile(int FD, LockKind Kind=LockKind::Exclusive)
Lock the file.
LLVM_ABI std::error_code set_current_path(const Twine &path)
Set the current path.
LLVM_ABI std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
@ CD_OpenAlways
CD_OpenAlways - When opening a file:
@ CD_CreateAlways
CD_CreateAlways - When opening a file:
@ CD_CreateNew
CD_CreateNew - When opening a file:
LLVM_ABI Expected< size_t > readNativeFileSlice(file_t FileHandle, MutableArrayRef< char > Buf, uint64_t Offset)
Reads Buf.size() bytes from FileHandle at offset Offset into Buf.
LLVM_ABI std::string getMainExecutable(const char *argv0, void *MainExecAddr)
Return the path to the main executable, given the value of argv[0] from program startup and the addre...
LLVM_ABI Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI bool status_known(const basic_file_status &s)
Is status available?
LLVM_ABI std::error_code make_absolute(SmallVectorImpl< char > &path)
Make path an absolute path.
LLVM_ABI std::error_code resize_file_sparse(int FD, uint64_t Size)
Resize path to size with sparse files explicitly enabled.
LLVM_ABI std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), LockKind Kind=LockKind::Exclusive)
Try to locks the file during the specified time.
LLVM_ABI std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
LLVM_ABI std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
LLVM_ABI file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ABI std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
LLVM_ABI std::error_code is_local(const Twine &path, bool &result)
Is the file mounted on a local filesystem?
LLVM_ABI std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
LLVM_ABI bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
LLVM_ABI file_t getStderrHandle()
Return an open handle to standard error.
LLVM_ABI std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
LLVM_ABI file_t getStdinHandle()
Return an open handle to standard in.
LLVM_ABI std::error_code unlockFile(int FD)
Unlock the file.
LLVM_ABI std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
LLVM_ABI bool cache_directory(SmallVectorImpl< char > &result)
Get the directory where installed packages should put their machine-local cache, e....
LLVM_ABI bool user_config_directory(SmallVectorImpl< char > &result)
Get the directory where packages should read user-specific configurations.
LLVM_ABI bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
Remove '.
LLVM_ABI bool has_root_path(const Twine &path, Style style=Style::native)
Has root path?
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
void make_preferred(SmallVectorImpl< char > &path, Style style=Style::native)
For Windows path styles, convert path to use the preferred path separators.
LLVM_ABI bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
LLVM_ABI void system_temp_directory(bool erasedOnReboot, SmallVectorImpl< char > &result)
Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".
LLVM_ABI void native(const Twine &path, SmallVectorImpl< char > &result, Style style=Style::native)
Convert path to the native form.
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI StringRef root_name(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root name.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
LLVM_ABI bool home_directory(SmallVectorImpl< char > &result)
Get the user's home directory.
LLVM_ABI bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
void violationIfEnabled()
ScopedSetting scopedDisable()
LLVM_ABI std::error_code makeLongFormPath(const Twine &Path8, llvm::SmallVectorImpl< char > &Result8)
Convert a UTF-8 path to a long form UTF-8 path expanding any short 8.3 form components.
LLVM_ABI std::error_code widenPath(const Twine &Path8, SmallVectorImpl< wchar_t > &Path16, size_t MaxPathLen=MAX_PATH)
Convert UTF-8 path to a suitable UTF-16 path for use with the Win32 Unicode File API.
LLVM_ABI HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName)
Retrieves the handle to a in-memory system module such as ntdll.dll, while ensuring we're not retriev...
FILETIME toFILETIME(TimePoint<> TP)
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code mapLastWindowsError()
std::error_code make_error_code(BitcodeError E)
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
LLVM_ABI llvm::VersionTuple GetWindowsOSVersion()
Returns the Windows version as Major.Minor.0.BuildNumber.
std::string utostr(uint64_t X, bool isNeg=false)
ScopedHandle< FindHandleTraits > ScopedFindHandle
@ no_such_file_or_directory
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
@ Success
The lock was released successfully.
@ Timeout
Reached timeout while waiting for the owner to release the lock.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
LLVM_ABI std::error_code mapWindowsError(unsigned EV)
ScopedHandle< FileHandleTraits > ScopedFileHandle
LLVM_ABI std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
space_info - Self explanatory.