37#ifndef _ERRNO_T_DEFINED
38#define _ERRNO_T_DEFINED
43#pragma comment(lib, "advapi32.lib")
44#pragma comment(lib, "ole32.lib")
52typedef enum _FSINFOCLASS { FileFsDeviceInformation = 4 } FS_INFORMATION_CLASS;
54typedef struct _FILE_FS_DEVICE_INFORMATION {
55 DEVICE_TYPE DeviceType;
57} FILE_FS_DEVICE_INFORMATION;
60extern "C" NTSYSAPI NTSTATUS NTAPI NtQueryVolumeInformationFile(
61 HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation,
62 ULONG Length, FS_INFORMATION_CLASS FsInformationClass);
66#ifndef FILE_REMOVABLE_MEDIA
67#define FILE_REMOVABLE_MEDIA 0x00000001
69#ifndef FILE_REMOTE_DEVICE
70#define FILE_REMOTE_DEVICE 0x00000010
75using llvm::sys::windows::CurCPToUTF16;
76using llvm::sys::windows::UTF16ToUTF8;
77using llvm::sys::windows::UTF8ToUTF16;
95static constexpr wchar_t LongPathPrefix16[] = LR
"(\\?\)";
96static constexpr wchar_t LongPathUNCPrefix16[] = LR
"(\\?\UNC\)";
98static constexpr DWORD LongPathPrefix16Len =
99 static_cast<DWORD
>(std::size(LongPathPrefix16) - 1);
100static constexpr DWORD LongPathUNCPrefix16Len =
101 static_cast<DWORD
>(std::size(LongPathUNCPrefix16) - 1);
103static void stripLongPathPrefix(
wchar_t *&
Data, DWORD &CountChars) {
104 if (CountChars >= LongPathUNCPrefix16Len &&
105 ::wmemcmp(
Data, LongPathUNCPrefix16, LongPathUNCPrefix16Len) == 0) {
110 }
else if (CountChars >= LongPathPrefix16Len &&
111 ::wmemcmp(
Data, LongPathPrefix16, LongPathPrefix16Len) == 0) {
125std::error_code
widenPath(
const Twine &Path8, SmallVectorImpl<wchar_t> &Path16,
127 assert(MaxPathLen <= MAX_PATH);
131 SmallString<MAX_PATH> Path8Str;
139 if (std::error_code EC = UTF8ToUTF16(Path8Str, Path16))
147 CurPathLen = ::GetCurrentDirectoryW(
153 if ((Path16.
size() + CurPathLen) < MaxPathLen ||
155 return std::error_code();
170 "Root name cannot be empty for an absolute path!");
172 SmallString<2 * MAX_PATH> FullPath;
173 if (RootName[1] !=
':') {
174 FullPath.
append(LongPathUNCPrefix8);
177 FullPath.
append(LongPathPrefix8);
178 FullPath.
append(Path8Str);
181 return UTF8ToUTF16(FullPath, Path16);
185 llvm::SmallVectorImpl<char> &Result8) {
186 SmallString<128> PathStorage;
187 StringRef PathStr = Path8.
toStringRef(PathStorage);
188 bool HadPrefix = PathStr.
starts_with(LongPathPrefix8);
191 if (std::error_code EC =
widenPath(PathStr, Path16))
202 Len = ::GetLongPathNameW(Path16.
data(), Long16.
data(), Len);
213 }
while (Len > Long16.
size());
223 stripLongPathPrefix(
Data, Len);
225 return sys::windows::UTF16ToUTF8(
Data, Len, Result8);
256 if (UTF16ToUTF8(PathName.
data(), PathName.
size(), PathNameUTF8))
261 SmallString<256> RealPath;
264 return std::string(RealPath);
265 return std::string(PathNameUTF8.
data());
269 return UniqueID(VolumeSerialNumber, PathHash);
272ErrorOr<space_info>
disk_space(
const Twine &Path) {
276 if (std::error_code EC =
widenPath(Path, PathUTF16))
279 if (!::GetDiskFreeSpaceExW(PathUTF16.
data(), &Avail, &
Total, &
Free))
284 SpaceInfo.free =
Free.QuadPart;
285 SpaceInfo.available = Avail.QuadPart;
292 Time.dwLowDateTime = LastAccessedTimeLow;
293 Time.dwHighDateTime = LastAccessedTimeHigh;
299 Time.dwLowDateTime = LastWriteTimeLow;
300 Time.dwHighDateTime = LastWriteTimeHigh;
306std::error_code
current_path(SmallVectorImpl<char> &result) {
310 DWORD len = MAX_PATH;
314 len = ::GetCurrentDirectoryW(cur_path.
size(), cur_path.
data());
322 }
while (len > cur_path.
size());
328 if (std::error_code EC =
329 UTF16ToUTF8(cur_path.
begin(), cur_path.
size(), result))
333 return std::error_code();
341 if (std::error_code ec =
widenPath(path, wide_path))
344 if (!::SetCurrentDirectoryW(wide_path.
begin()))
347 return std::error_code();
356 if (std::error_code ec =
widenPath(path, path_utf16, MAX_PATH - 12))
359 if (!::CreateDirectoryW(path_utf16.
begin(), NULL)) {
360 DWORD LastError = ::GetLastError();
361 if (LastError != ERROR_ALREADY_EXISTS || !IgnoreExisting)
365 return std::error_code();
368std::error_code
create_symlink(
const Twine &to,
const Twine &from) {
371 SmallString<128> ToStr;
376 if (std::error_code ec =
widenPath(from, WideFrom))
378 if (std::error_code ec =
widenPath(ToStr, WideTo))
386 const SmallVectorImpl<wchar_t> *AttrPath = &WideTo;
389 SmallString<128> FromStr;
393 if (std::error_code ec =
widenPath(Resolved, WideResolved))
395 AttrPath = &WideResolved;
398 DWORD Attr = ::GetFileAttributesW(AttrPath->
begin());
399 if (Attr == INVALID_FILE_ATTRIBUTES) {
400 DWORD Err = ::GetLastError();
401 if (Err != ERROR_FILE_NOT_FOUND && Err != ERROR_PATH_NOT_FOUND)
405 }
else if (Attr & FILE_ATTRIBUTE_DIRECTORY) {
406 Flags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
411 if (::CreateSymbolicLinkW(WideFrom.
begin(), WideTo.
begin(),
413 SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE))
414 return std::error_code();
417 DWORD Err = ::GetLastError();
418 if (Err == ERROR_INVALID_PARAMETER) {
419 if (::CreateSymbolicLinkW(WideFrom.
begin(), WideTo.
begin(), Flags))
420 return std::error_code();
421 Err = ::GetLastError();
427std::error_code
create_link(
const Twine &to,
const Twine &from) {
438 if (std::error_code ec =
widenPath(from, wide_from))
440 if (std::error_code ec =
widenPath(to, wide_to))
443 if (!::CreateHardLinkW(wide_from.
begin(), wide_to.
begin(), NULL))
446 return std::error_code();
449std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting) {
452 if (std::error_code ec =
widenPath(path, path_utf16))
466 c_str(path_utf16), DELETE,
467 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
469 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS |
470 FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_DELETE_ON_CLOSE,
478 return std::error_code();
481static std::error_code is_local_internal(SmallVectorImpl<wchar_t> &Path,
488 ::GetVolumePathNameW(
Path.data(), VolumePath.
data(), VolumePath.
size());
493 DWORD Err = ::GetLastError();
494 if (Err != ERROR_INSUFFICIENT_BUFFER)
504 const wchar_t *
P = VolumePath.
data();
506 UINT
Type = ::GetDriveTypeW(
P);
510 return std::error_code();
514 case DRIVE_REMOVABLE:
516 return std::error_code();
523std::error_code
is_local(
const Twine &path,
bool &result) {
529 SmallString<128> Storage;
534 if (std::error_code ec =
widenPath(
P, WidePath))
536 return is_local_internal(WidePath, result);
539static std::error_code realPathFromHandle(HANDLE
H,
540 SmallVectorImpl<wchar_t> &Buffer,
541 DWORD flags = VOLUME_NAME_DOS) {
543 DWORD CountChars = ::GetFinalPathNameByHandleW(
544 H, Buffer.
begin(), Buffer.
capacity(), FILE_NAME_NORMALIZED | flags);
545 if (CountChars && CountChars >= Buffer.
capacity()) {
549 CountChars = ::GetFinalPathNameByHandleW(
H, Buffer.
begin(), Buffer.
size(),
550 FILE_NAME_NORMALIZED | flags);
555 return std::error_code();
558static std::error_code realPathFromHandle(HANDLE
H,
559 SmallVectorImpl<char> &RealPath) {
562 if (std::error_code EC = realPathFromHandle(
H, Buffer))
569 stripLongPathPrefix(
Data, CountChars);
572 if (std::error_code EC = UTF16ToUTF8(
Data, CountChars, RealPath))
576 return std::error_code();
579static std::error_code is_local_internal(HANDLE Handle,
bool &Result) {
582 IO_STATUS_BLOCK IoStatus;
583 FILE_FS_DEVICE_INFORMATION
Info;
584 if (::NtQueryVolumeInformationFile(Handle, &IoStatus, &Info,
sizeof(Info),
585 FileFsDeviceInformation) >= 0 &&
586 (
Info.DeviceType == FILE_DEVICE_DISK ||
587 Info.DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM) &&
588 !(
Info.Characteristics & (FILE_REMOVABLE_MEDIA | FILE_REMOTE_DEVICE))) {
590 return std::error_code();
594 if (std::error_code EC = realPathFromHandle(Handle, FinalPath))
596 return is_local_internal(FinalPath, Result);
599std::error_code
is_local(
int FD,
bool &Result) {
602 HANDLE Handle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
603 return is_local_internal(Handle, Result);
606static std::error_code setDeleteDisposition(HANDLE Handle,
bool Delete) {
611 FILE_DISPOSITION_INFO Disposition;
612 Disposition.DeleteFile =
false;
613 if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition,
614 sizeof(Disposition)))
617 return std::error_code();
623 if (std::error_code EC = is_local_internal(Handle, IsLocal))
631 Disposition.DeleteFile =
true;
632 if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition,
633 sizeof(Disposition)))
635 return std::error_code();
638static std::error_code rename_internal(HANDLE FromHandle,
const Twine &To,
639 bool ReplaceIfExists) {
644 std::vector<char> RenameInfoBuf(
sizeof(FILE_RENAME_INFO) -
sizeof(
wchar_t) +
645 (ToWide.
size() *
sizeof(
wchar_t)));
646 FILE_RENAME_INFO &RenameInfo =
647 *
reinterpret_cast<FILE_RENAME_INFO *
>(RenameInfoBuf.data());
648 RenameInfo.ReplaceIfExists = ReplaceIfExists;
649 RenameInfo.RootDirectory = 0;
650 RenameInfo.FileNameLength = ToWide.
size() *
sizeof(wchar_t);
651 std::copy(ToWide.
begin(), ToWide.
end(), &RenameInfo.FileName[0]);
653 SetLastError(ERROR_SUCCESS);
654 if (!SetFileInformationByHandle(FromHandle, FileRenameInfo, &RenameInfo,
655 RenameInfoBuf.size())) {
656 unsigned Error = GetLastError();
657 if (
Error == ERROR_SUCCESS)
658 Error = ERROR_CALL_NOT_IMPLEMENTED;
662 return std::error_code();
665static std::error_code rename_handle(HANDLE FromHandle,
const Twine &To) {
667 if (std::error_code EC =
widenPath(To, WideTo))
673 for (
unsigned Retry = 0; Retry != 200; ++Retry) {
674 auto EC = rename_internal(FromHandle, To,
true);
677 std::error_code(ERROR_CALL_NOT_IMPLEMENTED, std::system_category())) {
681 if (std::error_code EC2 = realPathFromHandle(FromHandle, WideFrom))
683 if (::MoveFileExW(WideFrom.
begin(), WideTo.
begin(),
684 MOVEFILE_REPLACE_EXISTING))
685 return std::error_code();
699 ::CreateFileW(WideTo.
begin(), GENERIC_READ | DELETE,
700 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
702 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL));
713 BY_HANDLE_FILE_INFORMATION FI;
714 if (!GetFileInformationByHandle(ToHandle, &FI))
718 for (
unsigned UniqueId = 0; UniqueId != 200; ++UniqueId) {
719 std::string TmpFilename = (To +
".tmp" +
utostr(UniqueId)).str();
720 if (
auto EC = rename_internal(ToHandle, TmpFilename,
false)) {
728 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
729 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
736 BY_HANDLE_FILE_INFORMATION FI2;
737 if (!GetFileInformationByHandle(ToHandle2, &FI2))
739 if (FI.nFileIndexHigh != FI2.nFileIndexHigh ||
740 FI.nFileIndexLow != FI2.nFileIndexLow ||
741 FI.dwVolumeSerialNumber != FI2.dwVolumeSerialNumber)
760std::error_code
rename(
const Twine &From,
const Twine &To) {
763 if (std::error_code EC =
widenPath(From, WideFrom))
768 for (
unsigned Retry = 0; Retry != 200; ++Retry) {
774 ::CreateFileW(WideFrom.
begin(), GENERIC_READ | DELETE,
775 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
776 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
788 return rename_handle(FromHandle, To);
797 return std::error_code(
error, std::generic_category());
801 HANDLE hFile =
reinterpret_cast<HANDLE
>(::_get_osfhandle(FD));
803 if (!DeviceIoControl(hFile, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &temp,
807 LARGE_INTEGER liSize;
808 liSize.QuadPart =
Size;
809 if (!SetFilePointerEx(hFile, liSize, NULL, FILE_BEGIN) ||
810 !SetEndOfFile(hFile)) {
813 return std::error_code();
821 if (std::error_code EC =
widenPath(Path, PathUtf16))
832 DWORD LastError = ::GetLastError();
833 if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND)
844 return std::error_code();
854 return A.getUniqueID() ==
B.getUniqueID();
857std::error_code
equivalent(
const Twine &
A,
const Twine &
B,
bool &result) {
861 if (std::error_code ec =
status(
A, fsA))
863 if (std::error_code ec =
status(
B, fsB))
866 return std::error_code();
869static bool isReservedName(StringRef path) {
872 static const char *
const sReservedNames[] = {
873 "nul",
"con",
"prn",
"aux",
"com1",
"com2",
"com3",
"com4",
874 "com5",
"com6",
"com7",
"com8",
"com9",
"lpt1",
"lpt2",
"lpt3",
875 "lpt4",
"lpt5",
"lpt6",
"lpt7",
"lpt8",
"lpt9"};
883 for (
size_t i = 0; i < std::size(sReservedNames); ++i) {
892static file_type file_type_from_attrs(DWORD Attrs) {
897static perms perms_from_attrs(DWORD Attrs) {
901static std::error_code getStatus(HANDLE FileHandle,
file_status &Result) {
903 if (FileHandle == INVALID_HANDLE_VALUE)
904 goto handle_status_error;
906 switch (::GetFileType(FileHandle)) {
909 case FILE_TYPE_UNKNOWN: {
910 DWORD Err = ::GetLastError();
914 return std::error_code();
920 return std::error_code();
923 return std::error_code();
926 BY_HANDLE_FILE_INFORMATION
Info;
927 if (!::GetFileInformationByHandle(FileHandle, &Info))
928 goto handle_status_error;
941 if (std::error_code EC =
942 realPathFromHandle(FileHandle, ntPath, VOLUME_NAME_NT)) {
948 PathHash = (
static_cast<uint64_t>(
Info.nFileIndexHigh) << 32ULL) |
955 file_type_from_attrs(
Info.dwFileAttributes),
956 perms_from_attrs(
Info.dwFileAttributes),
Info.nNumberOfLinks,
957 Info.ftLastAccessTime.dwHighDateTime,
Info.ftLastAccessTime.dwLowDateTime,
958 Info.ftLastWriteTime.dwHighDateTime,
Info.ftLastWriteTime.dwLowDateTime,
959 Info.dwVolumeSerialNumber,
Info.nFileSizeHigh,
Info.nFileSizeLow,
961 return std::error_code();
965 if (Err == std::errc::no_such_file_or_directory)
967 else if (Err == std::errc::permission_denied)
977 SmallString<128> path_storage;
981 if (isReservedName(path8)) {
983 return std::error_code();
986 if (std::error_code ec =
widenPath(path8, path_utf16))
991 DWORD attr = ::GetFileAttributesW(path_utf16.
begin());
992 if (attr == INVALID_FILE_ATTRIBUTES)
993 return getStatus(INVALID_HANDLE_VALUE, result);
996 if (attr & FILE_ATTRIBUTE_REPARSE_POINT)
997 Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
1001 ::CreateFileW(path_utf16.
begin(), 0,
1002 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
1003 NULL, OPEN_EXISTING, Flags, 0));
1005 return getStatus(INVALID_HANDLE_VALUE, result);
1007 return getStatus(h, result);
1013 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
1014 return getStatus(FileHandle, Result);
1020 return getStatus(FileHandle.
get(), Result);
1024 LARGE_INTEGER FileSize;
1025 if (!::GetFileSizeEx(FileHandle.
get(), &FileSize))
1027 return FileSize.QuadPart;
1034 if (std::error_code EC =
widenPath(Path, PathUTF16))
1059 return std::error_code();
1064 return std::make_error_code(std::errc::not_supported);
1070 FILETIME ModifyFT =
toFILETIME(ModificationTime);
1071 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
1072 if (!SetFileTime(FileHandle, NULL, &AccessFT, &ModifyFT))
1074 return std::error_code();
1077std::error_code mapped_file_region::init(sys::fs::file_t OrigFileHandle,
1081 if (!OrigFileHandle.
isValid())
1087 flprotect = PAGE_READONLY;
1090 flprotect = PAGE_READWRITE;
1093 flprotect = PAGE_WRITECOPY;
1099 if (std::error_code EC = UTF8ToUTF16(Name, NameUTF16))
1102 HANDLE FileMappingHandle =
1103 ::CreateFileMappingW(OrigFileHandle.
get(), 0, flprotect,
Hi_32(Size),
1105 if (FileMappingHandle == NULL) {
1110 DWORD dwDesiredAccess;
1113 dwDesiredAccess = FILE_MAP_READ;
1116 dwDesiredAccess = FILE_MAP_WRITE;
1119 dwDesiredAccess = FILE_MAP_COPY;
1122 Mapping = ::MapViewOfFile(FileMappingHandle, dwDesiredAccess,
Offset >> 32,
1123 Offset & 0xffffffff, Size);
1124 if (Mapping == NULL) {
1126 ::CloseHandle(FileMappingHandle);
1131 MEMORY_BASIC_INFORMATION mbi;
1132 SIZE_T
Result = VirtualQuery(Mapping, &mbi,
sizeof(mbi));
1135 ::UnmapViewOfFile(Mapping);
1136 ::CloseHandle(FileMappingHandle);
1139 Size = mbi.RegionSize;
1147 ::CloseHandle(FileMappingHandle);
1149 if (!::DuplicateHandle(::GetCurrentProcess(), OrigFileHandle.
get(),
1150 ::GetCurrentProcess(), &
H, 0, 0,
1151 DUPLICATE_SAME_ACCESS)) {
1153 ::UnmapViewOfFile(Mapping);
1158 return std::error_code();
1163 std::error_code &ec,
const char *
name)
1169 copyFrom(mapped_file_region());
1172static bool hasFlushBufferKernelBug() {
1178 static const char PEMagic[] = {
'P',
'E',
'\0',
'\0'};
1182 if (
Magic.substr(off).starts_with(
StringRef(PEMagic,
sizeof(PEMagic))))
1188void mapped_file_region::unmapImpl() {
1191 BY_HANDLE_FILE_INFORMATION FI;
1192 if (::GetFileInformationByHandle(FileHandle.get(), &FI) &&
1193 (FI.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0)
1194 ::FlushViewOfFile(Mapping,
Size);
1198 ::UnmapViewOfFile(Mapping);
1200 if (
Mode == mapmode::readwrite) {
1201 bool DoFlush =
Exe && hasFlushBufferKernelBug();
1219 bool IsLocal =
false;
1222 is_local_internal(FileHandle.get(), IsLocal);
1226 ::FlushFileBuffers(FileHandle.get());
1229 ::CloseHandle(FileHandle.get());
1233void mapped_file_region::dontNeedImpl() {}
1235void mapped_file_region::randomAccessImpl() {}
1237void mapped_file_region::willNeedImpl() {
1238 struct MEMORY_RANGE_ENTRY {
1239 PVOID VirtualAddress;
1240 SIZE_T NumberOfBytes;
1244 typedef BOOL(WINAPI * PrefetchVirtualMemory_t)(
1245 HANDLE hProcess, ULONG_PTR NumberOfEntries,
1246 MEMORY_RANGE_ENTRY * VirtualAddresses, ULONG Flags);
1248 static auto pfnPrefetchVirtualMemory = []() -> PrefetchVirtualMemory_t {
1253 return (PrefetchVirtualMemory_t)(
void *)::GetProcAddress(
1254 kernelM,
"PrefetchVirtualMemory");
1256 if (pfnPrefetchVirtualMemory) {
1257 MEMORY_RANGE_ENTRY
Range{Mapping,
Size};
1258 pfnPrefetchVirtualMemory(::GetCurrentProcess(), 1, &
Range, 0);
1262std::error_code mapped_file_region::sync()
const {
1263 if (!::FlushViewOfFile(Mapping,
Size))
1265 if (!::FlushFileBuffers(FileHandle.get()))
1267 return std::error_code();
1270int mapped_file_region::alignment() {
1271 SYSTEM_INFO SysInfo;
1272 ::GetSystemInfo(&SysInfo);
1273 return SysInfo.dwAllocationGranularity;
1276static basic_file_status status_from_find_data(WIN32_FIND_DATAW *FindData) {
1277 return basic_file_status(file_type_from_attrs(FindData->dwFileAttributes),
1278 perms_from_attrs(FindData->dwFileAttributes),
1279 FindData->ftLastAccessTime.dwHighDateTime,
1280 FindData->ftLastAccessTime.dwLowDateTime,
1281 FindData->ftLastWriteTime.dwHighDateTime,
1282 FindData->ftLastWriteTime.dwLowDateTime,
1283 FindData->nFileSizeHigh, FindData->nFileSizeLow);
1286std::error_code detail::directory_iterator_construct(detail::DirIterState &
IT,
1288 bool FollowSymlinks) {
1293 if (std::error_code EC =
widenPath(Path, PathUTF16))
1297 size_t PathUTF16Len = PathUTF16.
size();
1298 if (PathUTF16Len > 0 && !
is_separator(PathUTF16[PathUTF16Len - 1]) &&
1299 PathUTF16[PathUTF16Len - 1] != L
':') {
1307 WIN32_FIND_DATAW FirstFind;
1309 c_str(PathUTF16), FindExInfoBasic, &FirstFind, FindExSearchNameMatch,
1310 NULL, FIND_FIRST_EX_LARGE_FETCH));
1314 size_t FilenameLen = ::wcslen(FirstFind.cFileName);
1315 while ((FilenameLen == 1 && FirstFind.cFileName[0] == L
'.') ||
1316 (FilenameLen == 2 && FirstFind.cFileName[0] == L
'.' &&
1317 FirstFind.cFileName[1] == L
'.'))
1318 if (!::FindNextFileW(FindHandle, &FirstFind)) {
1319 DWORD LastError = ::GetLastError();
1321 if (LastError == ERROR_NO_MORE_FILES)
1322 return detail::directory_iterator_destruct(
IT);
1325 FilenameLen = ::wcslen(FirstFind.cFileName);
1330 if (std::error_code EC =
1331 UTF16ToUTF8(FirstFind.cFileName, ::wcslen(FirstFind.cFileName),
1332 DirectoryEntryNameUTF8))
1335 IT.IterationHandle = intptr_t(FindHandle.take());
1337 path::append(DirectoryEntryPath, DirectoryEntryNameUTF8);
1339 directory_entry(DirectoryEntryPath, FollowSymlinks,
1340 file_type_from_attrs(FirstFind.dwFileAttributes),
1341 status_from_find_data(&FirstFind));
1343 return std::error_code();
1346std::error_code detail::directory_iterator_destruct(detail::DirIterState &
IT) {
1347 if (
IT.IterationHandle != 0)
1350 IT.IterationHandle = 0;
1351 IT.CurrentEntry = directory_entry();
1352 return std::error_code();
1355std::error_code detail::directory_iterator_increment(detail::DirIterState &
IT) {
1358 WIN32_FIND_DATAW FindData;
1359 if (!::FindNextFileW(HANDLE(
IT.IterationHandle), &FindData)) {
1360 DWORD LastError = ::GetLastError();
1362 if (LastError == ERROR_NO_MORE_FILES)
1363 return detail::directory_iterator_destruct(
IT);
1367 size_t FilenameLen = ::wcslen(FindData.cFileName);
1368 if ((FilenameLen == 1 && FindData.cFileName[0] == L
'.') ||
1369 (FilenameLen == 2 && FindData.cFileName[0] == L
'.' &&
1370 FindData.cFileName[1] == L
'.'))
1374 if (std::error_code EC =
1375 UTF16ToUTF8(FindData.cFileName, ::wcslen(FindData.cFileName),
1376 DirectoryEntryPathUTF8))
1379 IT.CurrentEntry.replace_filename(
1380 Twine(DirectoryEntryPathUTF8),
1381 file_type_from_attrs(FindData.dwFileAttributes),
1382 status_from_find_data(&FindData));
1383 return std::error_code();
1388static std::error_code nativeFileToFd(Expected<file_t>
H,
int &ResultFD,
1390 int CrtOpenFlags = 0;
1391 if (Flags & OF_Append)
1392 CrtOpenFlags |= _O_APPEND;
1394 if (Flags & OF_CRLF) {
1395 assert(Flags & OF_Text &&
"Flags set OF_CRLF without OF_Text");
1396 CrtOpenFlags |= _O_TEXT;
1403 ResultFD = ::_open_osfhandle(intptr_t(
H->get()), CrtOpenFlags);
1404 if (ResultFD == -1) {
1405 ::CloseHandle(
H->get());
1408 return std::error_code();
1411static DWORD nativeDisposition(CreationDisposition Disp, OpenFlags Flags) {
1420 if (Flags & OF_Append)
1425 return CREATE_ALWAYS;
1431 return OPEN_EXISTING;
1436static DWORD nativeAccess(FileAccess
Access, OpenFlags Flags) {
1442 if (Flags & OF_Delete)
1444 if (Flags & OF_UpdateAtime)
1445 Result |= FILE_WRITE_ATTRIBUTES;
1446 if (Flags & OF_UpdateAttributes)
1447 Result |= FILE_WRITE_ATTRIBUTES;
1451static std::error_code openNativeFileInternal(
const Twine &Name,
1452 file_t &ResultFile, DWORD Disp,
1453 DWORD
Access, DWORD Flags,
1454 bool Inherit =
false,
1455 bool AllowDirectory =
false) {
1457 if (std::error_code EC =
widenPath(Name, PathUTF16))
1460 SECURITY_ATTRIBUTES SA;
1461 SA.nLength =
sizeof(SA);
1462 SA.lpSecurityDescriptor =
nullptr;
1463 SA.bInheritHandle = Inherit;
1467 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, &SA,
1469 if (
H == INVALID_HANDLE_VALUE) {
1470 DWORD LastError = ::GetLastError();
1475 if (LastError != ERROR_ACCESS_DENIED)
1482 return std::error_code();
1486 FileAccess
Access, OpenFlags Flags,
1491 assert((!(Disp == CD_CreateNew) || !(Flags & OF_Append)) &&
1492 "Cannot specify both 'CreateNew' and 'Append' file creation flags!");
1494 DWORD NativeDisp = nativeDisposition(Disp, Flags);
1495 DWORD NativeAccess = nativeAccess(
Access, Flags);
1496 DWORD NativeFlags = FILE_ATTRIBUTE_NORMAL;
1497 if (Flags & OF_OpenDirectory)
1498 NativeFlags |= FILE_FLAG_BACKUP_SEMANTICS;
1500 bool Inherit =
false;
1501 if (Flags & OF_ChildInherit)
1505 std::error_code
EC = openNativeFileInternal(
1506 Name, Result, NativeDisp, NativeAccess, NativeFlags, Inherit,
1507 Flags & OF_OpenDirectory);
1511 if (Flags & OF_UpdateAtime) {
1513 SYSTEMTIME SystemTime;
1514 GetSystemTime(&SystemTime);
1515 if (SystemTimeToFileTime(&SystemTime, &FileTime) == 0 ||
1516 SetFileTime(
Result.get(), NULL, &FileTime, NULL) == 0) {
1517 DWORD LastError = ::GetLastError();
1518 ::CloseHandle(
Result.get());
1527 CreationDisposition Disp, FileAccess
Access,
1528 OpenFlags Flags,
unsigned int Mode) {
1535 return nativeFileToFd(std::move(Result), ResultFD, Flags);
1538static std::error_code directoryRealPath(
const Twine &Name,
1541 std::error_code
EC = openNativeFileInternal(
1542 Name, File, OPEN_EXISTING, GENERIC_READ, FILE_FLAG_BACKUP_SEMANTICS);
1546 EC = realPathFromHandle(
File.get(), RealPath);
1547 ::CloseHandle(
File.get());
1557 return nativeFileToFd(std::move(NativeFile), ResultFD, OF_None);
1564 Expected<file_t>
Result =
1568 if (Result && RealPath)
1569 realPathFromHandle(
Result->get(), *RealPath);
1575 return reinterpret_cast<HANDLE
>(::_get_osfhandle(FD));
1582static Expected<size_t> readNativeFileImpl(
file_t FileHandle,
1584 OVERLAPPED *Overlap) {
1588 std::min(
size_t(std::numeric_limits<DWORD>::max()), Buf.
size());
1589 DWORD BytesRead = 0;
1590 if (::ReadFile(FileHandle.
get(), Buf.
data(), BytesToRead, &BytesRead,
1593 DWORD Err = ::GetLastError();
1595 if (Err == ERROR_BROKEN_PIPE || Err == ERROR_HANDLE_EOF)
1603 return readNativeFileImpl(FileHandle, Buf,
nullptr);
1611 OVERLAPPED Overlapped = {};
1614 return readNativeFileImpl(FileHandle, Buf, &Overlapped);
1619 DWORD Flags = Kind == LockKind::Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
1620 Flags |= LOCKFILE_FAIL_IMMEDIATELY;
1623 auto Start = std::chrono::steady_clock::now();
1626 if (::LockFileEx(
File.get(), Flags, 0, MAXDWORD, MAXDWORD, &OV))
1627 return std::error_code();
1628 DWORD Error = ::GetLastError();
1629 if (Error == ERROR_LOCK_VIOLATION) {
1636 }
while (std::chrono::steady_clock::now() <
End);
1640std::error_code
lockFile(
int FD, LockKind Kind) {
1641 DWORD Flags = Kind == LockKind::Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
1644 if (::LockFileEx(
File.get(), Flags, 0, MAXDWORD, MAXDWORD, &OV))
1645 return std::error_code();
1646 DWORD Error = ::GetLastError();
1653 if (::UnlockFileEx(
File.get(), 0, MAXDWORD, MAXDWORD, &OV))
1654 return std::error_code();
1661 if (!::CloseHandle(TmpF.
get()))
1663 return std::error_code();
1671 std::error_code
EC =
widenPath(NativePath, Path16);
1672 if (EC && !IgnoreErrors)
1686 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
1690 IFileOperation *FileOp = NULL;
1691 HR = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL,
1692 IID_PPV_ARGS(&FileOp));
1696 HR = FileOp->SetOperationFlags(FOF_NO_UI | FOFX_NOCOPYHOOKS);
1699 PIDLIST_ABSOLUTE PIDL = ILCreateFromPathW(Path16.
data());
1701 IShellItem *ShItem = NULL;
1702 HR = SHCreateItemFromIDList(PIDL, IID_PPV_ARGS(&ShItem));
1706 HR = FileOp->DeleteItem(ShItem, NULL);
1709 HR = FileOp->PerformOperations();
1711 if (FAILED(HR) && !IgnoreErrors)
1713 return std::error_code();
1718 if (
Path.empty() || Path[0] !=
'~')
1726 if (!Expr.
empty()) {
1738 Path[0] = HomeDir[0];
1744 if (
path.isTriviallyEmpty())
1747 path.toVector(dest);
1748 expandTildeExpr(dest);
1754 bool expand_tilde) {
1758 if (
path.isTriviallyEmpty())
1759 return std::error_code();
1763 path.toVector(Storage);
1764 expandTildeExpr(Storage);
1769 return directoryRealPath(
path, dest);
1772 if (std::error_code EC =
1776 return std::error_code();
1779#if defined(__clang__)
1780#pragma clang diagnostic push
1781#pragma clang diagnostic ignored "-Wnested-anon-types"
1785struct LLVM_REPARSE_DATA_BUFFER {
1786 unsigned long ReparseTag;
1787 unsigned short ReparseDataLength;
1791 unsigned short SubstituteNameOffset;
1792 unsigned short SubstituteNameLength;
1793 unsigned short PrintNameOffset;
1794 unsigned short PrintNameLength;
1795 unsigned long Flags;
1796 wchar_t PathBuffer[1];
1797 } SymbolicLinkReparseBuffer;
1799 unsigned short SubstituteNameOffset;
1800 unsigned short SubstituteNameLength;
1801 unsigned short PrintNameOffset;
1802 unsigned short PrintNameLength;
1803 wchar_t PathBuffer[1];
1804 } MountPointReparseBuffer;
1806 unsigned char DataBuffer[1];
1807 } GenericReparseBuffer;
1810#if defined(__clang__)
1811#pragma clang diagnostic pop
1823 c_str(PathUTF16), FILE_READ_ATTRIBUTES,
1824 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1825 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
1832 LLVM_REPARSE_DATA_BUFFER RDB;
1833 char Buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
1835 DWORD BytesReturned;
1836 if (!::DeviceIoControl(
H, FSCTL_GET_REPARSE_POINT, NULL, 0, &RDB,
1837 sizeof(Buffer), &BytesReturned, NULL)) {
1838 DWORD Err = ::GetLastError();
1839 if (Err == ERROR_NOT_A_REPARSE_POINT)
1844 if (RDB.ReparseTag != IO_REPARSE_TAG_SYMLINK)
1847 const auto &SLB = RDB.SymbolicLinkReparseBuffer;
1848 size_t PathBufOffset =
1849 offsetof(LLVM_REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer);
1853 USHORT NameOffset, NameLength;
1854 if (SLB.PrintNameLength != 0) {
1855 NameOffset = SLB.PrintNameOffset;
1856 NameLength = SLB.PrintNameLength;
1858 NameOffset = SLB.SubstituteNameOffset;
1859 NameLength = SLB.SubstituteNameLength;
1863 if (PathBufOffset + NameOffset + NameLength > BytesReturned)
1866 const wchar_t *
Target = SLB.PathBuffer + NameOffset /
sizeof(wchar_t);
1867 USHORT TargetLen = NameLength /
sizeof(wchar_t);
1869 if (std::error_code EC = UTF16ToUTF8(
Target, TargetLen, dest))
1873 return std::error_code();
1879static bool getKnownFolderPath(KNOWNFOLDERID folderId,
1880 SmallVectorImpl<char> &result) {
1881 wchar_t *path =
nullptr;
1882 if (::SHGetKnownFolderPath(folderId, KF_FLAG_CREATE,
nullptr, &path) != S_OK)
1885 bool ok = !UTF16ToUTF8(path, ::wcslen(path), result);
1886 ::CoTaskMemFree(path);
1893 return getKnownFolderPath(FOLDERID_Profile, result);
1899 return getKnownFolderPath(FOLDERID_LocalAppData, result);
1903 return getKnownFolderPath(FOLDERID_LocalAppData, result);
1906static bool getTempDirEnvVar(
const wchar_t *Var, SmallVectorImpl<char> &Res) {
1907 SmallVector<wchar_t, 1024> Buf;
1911 Size = GetEnvironmentVariableW(Var, Buf.
data(), Buf.
size());
1916 }
while (Size > Buf.
size());
1919 return !windows::UTF16ToUTF8(Buf.
data(), Size, Res);
1922static bool getTempDirEnvVar(SmallVectorImpl<char> &Res) {
1923 const wchar_t *EnvironmentVariables[] = {
L"TMP",
L"TEMP",
L"USERPROFILE"};
1924 for (
auto *Env : EnvironmentVariables) {
1925 if (getTempDirEnvVar(Env, Res))
1932 (void)ErasedOnReboot;
1939 if (getTempDirEnvVar(Result)) {
1942 fs::make_absolute(Result);
1947 const char *DefaultResult =
"C:\\Temp";
1948 Result.append(DefaultResult, DefaultResult + strlen(DefaultResult));
1954std::error_code CodePageToUTF16(
unsigned codepage, llvm::StringRef original,
1955 llvm::SmallVectorImpl<wchar_t> &utf16) {
1956 if (!original.
empty()) {
1958 ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.
begin(),
1969 ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.
begin(),
1981 return std::error_code();
1984std::error_code UTF8ToUTF16(llvm::StringRef utf8,
1985 llvm::SmallVectorImpl<wchar_t> &utf16) {
1986 return CodePageToUTF16(CP_UTF8, utf8, utf16);
1989std::error_code CurCPToUTF16(llvm::StringRef curcp,
1990 llvm::SmallVectorImpl<wchar_t> &utf16) {
1991 return CodePageToUTF16(CP_ACP, curcp, utf16);
1994static std::error_code UTF16ToCodePage(
unsigned codepage,
const wchar_t *utf16,
1996 llvm::SmallVectorImpl<char> &converted) {
1999 int len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len,
2000 converted.
begin(), 0, NULL, NULL);
2010 len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, converted.
data(),
2011 converted.
size(), NULL, NULL);
2022 return std::error_code();
2025std::error_code UTF16ToUTF8(
const wchar_t *utf16,
size_t utf16_len,
2026 llvm::SmallVectorImpl<char> &utf8) {
2027 return UTF16ToCodePage(CP_UTF8, utf16, utf16_len, utf8);
2030std::error_code UTF16ToCurCP(
const wchar_t *utf16,
size_t utf16_len,
2031 llvm::SmallVectorImpl<char> &curcp) {
2032 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")))
size_t size() const
Get the array size.
Represents either an error or a value T.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
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...
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
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
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 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.
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
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.
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
@ End
Run the machine verifier once, at the end of the pipeline.
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.
This class wraps the platform specific file handle/descriptor type to provide an unified representati...
static constexpr value_type Invalid
Value for an invalid file descriptor.
value_type get() const
Get the underlying value and return a platform specific value.
This class wraps the platform specific file handle/descriptor type to provide an unified representati...
int value_type
A file descriptor on UNIX.
bool isValid() const
Is a valid file.
static constexpr value_type Invalid
Value for an invalid file descriptor.
value_type get() const
Get the underlying value and return a platform specific value.
space_info - Self explanatory.