24 #include <sys/types.h>
35 #ifndef _ERRNO_T_DEFINED
36 #define _ERRNO_T_DEFINED
41 # pragma comment(lib, "advapi32.lib") // This provides CryptAcquireContextW.
42 # pragma comment(lib, "ole32.lib") // This provides CoTaskMemFree
70 const size_t MaxDirLen = MAX_PATH - 12;
82 CurPathLen = ::GetCurrentDirectoryW(0, NULL);
88 if ((Path8Str.
size() + CurPathLen) >= MaxDirLen &&
95 FullPath.append(CurPath);
104 if (
I->size() == 1 && *
I ==
".")
106 if (
I->size() == 2 && *
I ==
"..")
143 return std::string(PathNameUTF8.
data());
149 uint64_t FileID = (
static_cast<uint64_t
>(FileIndexHigh) << 32ULL) |
150 static_cast<uint64_t
>(FileIndexLow);
152 return UniqueID(VolumeSerialNumber, FileID);
156 ULARGE_INTEGER Avail, Total, Free;
157 if (!::GetDiskFreeSpaceExA(Path.
str().c_str(), &Avail, &Total, &Free))
159 space_info SpaceInfo;
161 (
static_cast<uint64_t
>(Total.HighPart) << 32) + Total.LowPart;
162 SpaceInfo.free = (
static_cast<uint64_t
>(Free.HighPart) << 32) + Free.LowPart;
163 SpaceInfo.available =
164 (
static_cast<uint64_t
>(Avail.HighPart) << 32) + Avail.LowPart;
170 Time.dwLowDateTime = LastAccessedTimeLow;
171 Time.dwHighDateTime = LastAccessedTimeHigh;
177 Time.dwLowDateTime = LastWriteTimeLow;
178 Time.dwHighDateTime = LastWriteTimeHigh;
188 DWORD len = MAX_PATH;
192 len = ::GetCurrentDirectoryW(cur_path.
capacity(), cur_path.
data());
200 }
while (len > cur_path.
capacity());
211 if (std::error_code ec =
widenPath(path, wide_path))
214 if (!::SetCurrentDirectoryW(wide_path.
begin()))
217 return std::error_code();
224 if (std::error_code ec =
widenPath(path, path_utf16))
227 if (!::CreateDirectoryW(path_utf16.
begin(), NULL)) {
228 DWORD LastError = ::GetLastError();
229 if (LastError != ERROR_ALREADY_EXISTS || !IgnoreExisting)
233 return std::error_code();
241 if (std::error_code ec =
widenPath(from, wide_from))
243 if (std::error_code ec =
widenPath(to, wide_to))
246 if (!::CreateHardLinkW(wide_from.
begin(), wide_to.
begin(), NULL))
249 return std::error_code();
256 std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting) {
260 if (std::error_code EC =
status(path, ST)) {
263 return std::error_code();
266 if (std::error_code ec =
widenPath(path, path_utf16))
270 if (!::RemoveDirectoryW(
c_str(path_utf16))) {
275 return std::error_code();
277 if (!::DeleteFileW(
c_str(path_utf16))) {
282 return std::error_code();
292 ::GetVolumePathNameW(Path.
data(), VolumePath.
data(), VolumePath.
size());
297 DWORD Err = ::GetLastError();
298 if (Err != ERROR_INSUFFICIENT_BUFFER)
308 const wchar_t *
P = VolumePath.
data();
310 UINT
Type = ::GetDriveTypeW(P);
314 return std::error_code();
318 case DRIVE_REMOVABLE:
320 return std::error_code();
336 if (std::error_code ec =
widenPath(P, WidePath))
338 return is_local_internal(WidePath, result);
341 std::error_code
is_local(
int FD,
bool &Result) {
343 HANDLE Handle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
348 Len = ::GetFinalPathNameByHandleW(Handle, FinalPath.
data(),
349 FinalPath.
capacity() - 1, VOLUME_NAME_NT);
352 }
while (Len > FinalPath.
capacity());
356 return is_local_internal(FinalPath, Result);
363 if (std::error_code ec =
widenPath(from, wide_from))
365 if (std::error_code ec =
widenPath(to, wide_to))
368 std::error_code ec = std::error_code();
374 bool TryReplace =
true;
376 for (
int i = 0; i < 2000; i++) {
383 if (::ReplaceFileW(wide_to.
data(), wide_from.
data(), NULL, 0, NULL, NULL))
384 return std::error_code();
386 DWORD ReplaceError = ::GetLastError();
391 if (ReplaceError == ERROR_UNABLE_TO_MOVE_REPLACEMENT ||
392 ReplaceError == ERROR_UNABLE_TO_MOVE_REPLACEMENT_2) {
398 if (ReplaceError == ERROR_UNABLE_TO_REMOVE_REPLACED)
402 if (ReplaceError != ERROR_ACCESS_DENIED &&
403 ReplaceError != ERROR_FILE_NOT_FOUND &&
404 ReplaceError != ERROR_SHARING_VIOLATION)
408 if (::MoveFileExW(wide_from.
begin(), wide_to.
begin(),
409 MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
410 return std::error_code();
412 DWORD MoveError = ::GetLastError();
414 if (MoveError != ERROR_ACCESS_DENIED)
break;
420 std::error_code
resize_file(
int FD, uint64_t Size) {
421 #ifdef HAVE__CHSIZE_S
422 errno_t
error = ::_chsize_s(FD, Size);
424 errno_t error = ::_chsize(FD, Size);
426 return std::error_code(error, std::generic_category());
432 if (std::error_code EC =
widenPath(Path, PathUtf16))
435 DWORD Attributes = ::GetFileAttributesW(PathUtf16.
begin());
437 if (Attributes == INVALID_FILE_ATTRIBUTES) {
439 DWORD LastError = ::GetLastError();
440 if (LastError != ERROR_FILE_NOT_FOUND &&
441 LastError != ERROR_PATH_NOT_FOUND)
449 return std::error_code();
459 return A.FileIndexHigh == B.FileIndexHigh &&
460 A.FileIndexLow == B.FileIndexLow &&
461 A.FileSizeHigh == B.FileSizeHigh &&
462 A.FileSizeLow == B.FileSizeLow &&
463 A.LastAccessedTimeHigh == B.LastAccessedTimeHigh &&
464 A.LastAccessedTimeLow == B.LastAccessedTimeLow &&
465 A.LastWriteTimeHigh == B.LastWriteTimeHigh &&
466 A.LastWriteTimeLow == B.LastWriteTimeLow &&
467 A.VolumeSerialNumber == B.VolumeSerialNumber;
471 file_status fsA, fsB;
472 if (std::error_code ec =
status(A, fsA))
474 if (std::error_code ec =
status(B, fsB))
477 return std::error_code();
480 static bool isReservedName(
StringRef path) {
483 static const char *
const sReservedNames[] = {
"nul",
"con",
"prn",
"aux",
484 "com1",
"com2",
"com3",
"com4",
485 "com5",
"com6",
"com7",
"com8",
486 "com9",
"lpt1",
"lpt2",
"lpt3",
487 "lpt4",
"lpt5",
"lpt6",
"lpt7",
505 static std::error_code getStatus(HANDLE FileHandle, file_status &Result) {
506 if (FileHandle == INVALID_HANDLE_VALUE)
507 goto handle_status_error;
509 switch (::GetFileType(FileHandle)) {
512 case FILE_TYPE_UNKNOWN: {
513 DWORD Err = ::GetLastError();
517 return std::error_code();
523 return std::error_code();
526 return std::error_code();
529 BY_HANDLE_FILE_INFORMATION Info;
530 if (!::GetFileInformationByHandle(FileHandle, &Info))
531 goto handle_status_error;
534 file_type Type = (Info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
537 perms Permissions = (Info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
540 Result = file_status(
541 Type, Permissions, Info.nNumberOfLinks,
542 Info.ftLastAccessTime.dwHighDateTime,
543 Info.ftLastAccessTime.dwLowDateTime,
544 Info.ftLastWriteTime.dwHighDateTime, Info.ftLastWriteTime.dwLowDateTime,
545 Info.dwVolumeSerialNumber, Info.nFileSizeHigh, Info.nFileSizeLow,
546 Info.nFileIndexHigh, Info.nFileIndexLow);
547 return std::error_code();
551 DWORD LastError = ::GetLastError();
552 if (LastError == ERROR_FILE_NOT_FOUND ||
553 LastError == ERROR_PATH_NOT_FOUND)
555 else if (LastError == ERROR_SHARING_VIOLATION)
562 std::error_code
status(
const Twine &path, file_status &result,
bool Follow) {
567 if (isReservedName(path8)) {
569 return std::error_code();
572 if (std::error_code ec =
widenPath(path8, path_utf16))
575 DWORD attr = ::GetFileAttributesW(path_utf16.
begin());
576 if (attr == INVALID_FILE_ATTRIBUTES)
577 return getStatus(INVALID_HANDLE_VALUE, result);
581 if (!Follow && (attr & FILE_ATTRIBUTE_REPARSE_POINT))
582 Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
585 ::CreateFileW(path_utf16.
begin(), 0,
586 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
587 NULL, OPEN_EXISTING,
Flags, 0));
589 return getStatus(INVALID_HANDLE_VALUE, result);
591 return getStatus(h, result);
594 std::error_code
status(
int FD, file_status &Result) {
595 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
596 return getStatus(FileHandle, Result);
601 if (std::error_code EC =
widenPath(Path, PathUTF16))
604 DWORD Attributes = ::GetFileAttributesW(PathUTF16.
begin());
605 if (Attributes == INVALID_FILE_ATTRIBUTES)
612 Attributes &= ~FILE_ATTRIBUTE_READONLY;
615 Attributes |= FILE_ATTRIBUTE_NORMAL;
618 Attributes |= FILE_ATTRIBUTE_READONLY;
621 Attributes &= ~FILE_ATTRIBUTE_NORMAL;
624 if (!::SetFileAttributesW(PathUTF16.
begin(), Attributes))
627 return std::error_code();
632 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
633 if (!SetFileTime(FileHandle, NULL, &FT, &FT))
635 return std::error_code();
638 std::error_code mapped_file_region::init(
int FD, uint64_t
Offset,
644 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(_get_osfhandle(FD));
645 if (FileHandle == INVALID_HANDLE_VALUE)
650 case readonly: flprotect = PAGE_READONLY;
break;
651 case readwrite: flprotect = PAGE_READWRITE;
break;
652 case priv: flprotect = PAGE_WRITECOPY;
break;
655 HANDLE FileMappingHandle =
656 ::CreateFileMappingW(FileHandle, 0, flprotect,
657 (Offset + Size) >> 32,
658 (Offset + Size) & 0xffffffff,
660 if (FileMappingHandle == NULL) {
665 DWORD dwDesiredAccess;
667 case readonly: dwDesiredAccess = FILE_MAP_READ;
break;
668 case readwrite: dwDesiredAccess = FILE_MAP_WRITE;
break;
669 case priv: dwDesiredAccess = FILE_MAP_COPY;
break;
671 Mapping = ::MapViewOfFile(FileMappingHandle,
676 if (Mapping == NULL) {
678 ::CloseHandle(FileMappingHandle);
683 MEMORY_BASIC_INFORMATION mbi;
684 SIZE_T Result = VirtualQuery(Mapping, &mbi,
sizeof(mbi));
687 ::UnmapViewOfFile(Mapping);
688 ::CloseHandle(FileMappingHandle);
691 Size = mbi.RegionSize;
696 ::CloseHandle(FileMappingHandle);
697 return std::error_code();
701 uint64_t offset, std::error_code &ec)
702 : Size(length), Mapping() {
703 ec =
init(fd, offset, mode);
708 mapped_file_region::~mapped_file_region() {
710 ::UnmapViewOfFile(Mapping);
713 uint64_t mapped_file_region::size()
const {
714 assert(Mapping &&
"Mapping failed but used anyway!");
718 char *mapped_file_region::data()
const {
719 assert(Mapping &&
"Mapping failed but used anyway!");
720 return reinterpret_cast<char*
>(Mapping);
723 const char *mapped_file_region::const_data()
const {
724 assert(Mapping &&
"Mapping failed but used anyway!");
725 return reinterpret_cast<const char*
>(Mapping);
728 int mapped_file_region::alignment() {
730 ::GetSystemInfo(&SysInfo);
731 return SysInfo.dwAllocationGranularity;
736 bool follow_symlinks) {
739 if (std::error_code ec =
widenPath(path, path_utf16))
743 if (path_utf16.
size() > 0 &&
745 path_utf16[path.
size() - 1] !=
L':') {
753 WIN32_FIND_DATAW FirstFind;
758 size_t FilenameLen = ::wcslen(FirstFind.cFileName);
759 while ((FilenameLen == 1 && FirstFind.cFileName[0] ==
L'.') ||
760 (FilenameLen == 2 && FirstFind.cFileName[0] ==
L'.' &&
761 FirstFind.cFileName[1] ==
L'.'))
762 if (!::FindNextFileW(FindHandle, &FirstFind)) {
763 DWORD LastError = ::GetLastError();
765 if (LastError == ERROR_NO_MORE_FILES)
769 FilenameLen = ::wcslen(FirstFind.cFileName);
773 if (std::error_code ec =
774 UTF16ToUTF8(FirstFind.cFileName, ::wcslen(FirstFind.cFileName),
775 directory_entry_name_utf8))
778 it.IterationHandle =
intptr_t(FindHandle.take());
780 path::append(directory_entry_path, directory_entry_name_utf8);
781 it.CurrentEntry = directory_entry(directory_entry_path, follow_symlinks);
783 return std::error_code();
787 if (it.IterationHandle != 0)
790 it.IterationHandle = 0;
791 it.CurrentEntry = directory_entry();
792 return std::error_code();
796 WIN32_FIND_DATAW FindData;
797 if (!::FindNextFileW(HANDLE(it.IterationHandle), &FindData)) {
798 DWORD LastError = ::GetLastError();
800 if (LastError == ERROR_NO_MORE_FILES)
805 size_t FilenameLen = ::wcslen(FindData.cFileName);
806 if ((FilenameLen == 1 && FindData.cFileName[0] ==
L'.') ||
807 (FilenameLen == 2 && FindData.cFileName[0] ==
L'.' &&
808 FindData.cFileName[1] ==
L'.'))
812 if (std::error_code ec =
813 UTF16ToUTF8(FindData.cFileName, ::wcslen(FindData.cFileName),
814 directory_entry_path_utf8))
817 it.CurrentEntry.replace_filename(
Twine(directory_entry_path_utf8));
818 return std::error_code();
821 static std::error_code realPathFromHandle(HANDLE
H,
825 DWORD CountChars = ::GetFinalPathNameByHandleW(
826 H, Buffer.
begin(), Buffer.
capacity() - 1, FILE_NAME_NORMALIZED);
827 if (CountChars > Buffer.
capacity()) {
831 CountChars = ::GetFinalPathNameByHandleW(
832 H, Buffer.
data(), Buffer.
capacity() - 1, FILE_NAME_NORMALIZED);
837 const wchar_t *
Data = Buffer.
data();
838 if (CountChars >= 4) {
839 if (0 == ::memcmp(Data,
L"\\\\?\\", 8)) {
849 static std::error_code directoryRealPath(
const Twine &
Name,
853 if (std::error_code EC =
widenPath(Name, PathUTF16))
857 ::CreateFileW(PathUTF16.
begin(), GENERIC_READ,
858 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
859 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
860 if (H == INVALID_HANDLE_VALUE)
862 std::error_code EC = realPathFromHandle(H, RealPath);
871 if (std::error_code EC =
widenPath(Name, PathUTF16))
875 ::CreateFileW(PathUTF16.
begin(), GENERIC_READ,
876 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
877 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
878 if (H == INVALID_HANDLE_VALUE) {
879 DWORD LastError = ::GetLastError();
884 if (LastError != ERROR_ACCESS_DENIED)
891 int FD = ::_open_osfhandle(
intptr_t(H), 0);
899 realPathFromHandle(H, *RealPath);
902 return std::error_code();
909 "Cannot specify both 'excl' and 'append' file creation flags!");
913 if (std::error_code EC =
widenPath(Name, PathUTF16))
916 DWORD CreationDisposition;
918 CreationDisposition = CREATE_NEW;
920 CreationDisposition = OPEN_ALWAYS;
922 CreationDisposition = CREATE_ALWAYS;
924 DWORD Access = GENERIC_WRITE;
926 Access |= GENERIC_READ;
928 HANDLE H = ::CreateFileW(PathUTF16.
begin(), Access,
929 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
930 CreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
932 if (H == INVALID_HANDLE_VALUE) {
933 DWORD LastError = ::GetLastError();
938 if (LastError != ERROR_ACCESS_DENIED)
946 if (Flags & F_Append)
947 OpenFlags |= _O_APPEND;
950 OpenFlags |= _O_TEXT;
952 int FD = ::_open_osfhandle(
intptr_t(H), OpenFlags);
959 return std::error_code();
963 HANDLE FileHandle =
reinterpret_cast<HANDLE
>(::_get_osfhandle(FD));
964 if (FileHandle == INVALID_HANDLE_VALUE)
970 CharCount = ::GetFinalPathNameByHandleW(FileHandle, TempPath.
begin(),
972 FILE_NAME_NORMALIZED);
973 if (CharCount < TempPath.
capacity())
980 TempPath.
reserve(CharCount + 1);
990 if (TempPath.
back() ==
L'\0') {
1001 std::error_code EC =
widenPath(path, Path16);
1002 if (EC && !IgnoreErrors)
1013 SHFILEOPSTRUCTW shfos = {};
1014 shfos.wFunc = FO_DELETE;
1015 shfos.pFrom = Path16.
data();
1016 shfos.fFlags = FOF_NO_UI;
1018 int result = ::SHFileOperationW(&shfos);
1019 if (result != 0 && !IgnoreErrors)
1021 return std::error_code();
1026 if (Path.
empty() || Path[0] !=
'~')
1033 if (!Expr.
empty()) {
1045 Path[0] = HomeDir[0];
1050 bool expand_tilde) {
1053 return std::error_code();
1058 expandTildeExpr(Storage);
1063 return directoryRealPath(path, dest);
1069 return std::error_code();
1075 static bool getKnownFolderPath(KNOWNFOLDERID folderId,
1077 wchar_t *path =
nullptr;
1078 if (::SHGetKnownFolderPath(folderId, KF_FLAG_CREATE,
nullptr, &path) != S_OK)
1081 bool ok = !
UTF16ToUTF8(path, ::wcslen(path), result);
1082 ::CoTaskMemFree(path);
1087 return getKnownFolderPath(FOLDERID_LocalAppData, Result);
1091 return getKnownFolderPath(FOLDERID_Profile, result);
1099 Size = GetEnvironmentVariableW(Var, Buf.
data(), Buf.
capacity());
1111 const wchar_t *EnvironmentVariables[] = {
L"TMP",
L"TEMP", L
"USERPROFILE"};
1112 for (
auto *Env : EnvironmentVariables) {
1113 if (getTempDirEnvVar(Env, Res))
1120 (void)ErasedOnReboot;
1127 if (getTempDirEnvVar(Result)) {
1128 assert(!Result.
empty() &&
"Unexpected empty path");
1135 const char *DefaultResult =
"C:\\Temp";
1136 Result.
append(DefaultResult, DefaultResult + strlen(DefaultResult));
1143 if (!utf8.
empty()) {
1144 int len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8.
begin(),
1153 len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8.
begin(),
1164 return std::error_code();
1168 std::error_code UTF16ToCodePage(
unsigned codepage,
const wchar_t *utf16,
1173 int len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, utf8.
begin(),
1183 len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, utf8.
data(),
1184 utf8.
size(), NULL, NULL);
1194 return std::error_code();
1197 std::error_code
UTF16ToUTF8(
const wchar_t *utf16,
size_t utf16_len,
1199 return UTF16ToCodePage(CP_UTF8, utf16, utf16_len, utf8);
1202 std::error_code
UTF16ToCurCP(
const wchar_t *utf16,
size_t utf16_len,
1204 return UTF16ToCodePage(CP_ACP, utf16, utf16_len, utf8);
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE 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...
void push_back(const T &Elt)
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
const_iterator end(StringRef path)
Get end iterator over path.
F_Append - When opening a file, if it already exists append to the existing file instead of returning...
bool can_execute(const Twine &Path)
Can we execute this file?
Represents either an error or a value T.
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
size_t capacity() const
Return the total number of elements in the currently allocated buffer.
FILETIME toFILETIME(TimePoint<> TP)
std::error_code openFileForRead(const Twine &Name, int &ResultFD, SmallVectorImpl< char > *RealPath=nullptr)
F_Excl - When opening a file, this flag makes raw_fd_ostream report an error if the file already exis...
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
UniqueID getUniqueID() const
std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time)
Set the file modification and access time.
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
void reserve(size_type N)
std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
LLVM_ATTRIBUTE_ALWAYS_INLINE TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
bool status_known(file_status s)
Is status available?
mapped_file_region()=delete
amode Optimize addressing mode
std::error_code directory_iterator_increment(DirIterState &)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
std::error_code make_error_code(BitcodeError E)
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
May access map via data and modify it. Written to path.
LLVM_NODISCARD bool empty() const
May only access map via const_data as read only.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
std::error_code is_local(const Twine &path, bool &result)
Is the file mounted on a local filesystem?
std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
Open the file for read and write.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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...
std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
uint32_t getLinkCount() const
initializer< Ty > init(const Ty &Val)
The instances of the Type class are immutable: once they are created, they are never changed...
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
TimePoint getLastAccessedTime() const
std::error_code mapWindowsError(unsigned EV)
std::error_code UTF8ToUTF16(StringRef utf8, SmallVectorImpl< wchar_t > &utf16)
std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
bool startswith(StringRef Prefix) const
startswith - Check if this string starts with the given Prefix.
std::error_code getPathFromOpenFD(int FD, SmallVectorImpl< char > &ResultPath)
Fetch a path to an open file, as specified by a file descriptor.
std::error_code make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
bool is_directory(file_status status)
Does status represent a directory?
std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, SmallVectorImpl< char > &utf8)
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
std::error_code directory_iterator_construct(DirIterState &, StringRef, bool)
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
std::error_code UTF16ToCurCP(const wchar_t *utf16, size_t utf16_len, SmallVectorImpl< char > &utf8)
Convert from UTF16 to the current code page used in the system.
std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
The file should be opened in text mode on platforms that make this distinction.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
iterator insert(iterator I, T &&Elt)
std::error_code set_current_path(const Twine &path)
Set the current path.
May modify via data, but changes are lost on destruction.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
bool has_root_path(const Twine &path, Style style=Style::native)
Has root path?
ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void set_size(size_type N)
Set the array size to N, which the current array must have enough capacity for.
std::error_code directory_iterator_destruct(DirIterState &)
pointer data()
Return a pointer to the vector's buffer, even if empty().
file_type
An enumeration for the file system's view of the type.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
TimePoint getLastModificationTime() const
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
void system_temp_directory(bool erasedOnReboot, SmallVectorImpl< char > &result)
Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
bool home_directory(SmallVectorImpl< char > &result)
Get the user's home directory.
std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
StringRef - Represent a constant reference to a string, i.e.
bool exists(file_status status)
Does file exist?
std::error_code widenPath(const Twine &Path8, SmallVectorImpl< wchar_t > &Path16)
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags, unsigned Mode=0666)