30 #ifdef HAVE_SYS_MMAN_H 38 #include <mach-o/dyld.h> 41 #elif defined(__FreeBSD__) 42 #include <osreldate.h> 43 #if __FreeBSD_version >= 1300057 46 #include <machine/elf.h> 47 extern char **environ;
49 #elif defined(__DragonFly__) 50 #include <sys/mount.h> 60 #if defined(__GNU__) && !defined(PATH_MAX) 61 # define PATH_MAX 4096 62 # define MAXPATHLEN 4096 65 #include <sys/types.h> 66 #if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && \ 67 !defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX) 68 #include <sys/statvfs.h> 69 #define STATVFS statvfs 70 #define FSTATVFS fstatvfs 71 #define STATVFS_F_FRSIZE(vfs) vfs.f_frsize 73 #if defined(__OpenBSD__) || defined(__FreeBSD__) 74 #include <sys/mount.h> 75 #include <sys/param.h> 76 #elif defined(__linux__) 77 #if defined(HAVE_LINUX_MAGIC_H) 78 #include <linux/magic.h> 80 #if defined(HAVE_LINUX_NFS_FS_H) 81 #include <linux/nfs_fs.h> 83 #if defined(HAVE_LINUX_SMB_H) 84 #include <linux/smb.h> 89 #include <sys/statfs.h> 95 #include <sys/vmount.h> 97 #include <sys/mount.h> 99 #define STATVFS statfs 100 #define FSTATVFS fstatfs 101 #define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize) 104 #if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) 105 #define STATVFS_F_FLAG(vfs) (vfs).f_flag 107 #define STATVFS_F_FLAG(vfs) (vfs).f_flags 110 using namespace llvm;
118 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 119 defined(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \ 120 defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) 122 test_dir(
char ret[PATH_MAX],
const char *dir,
const char *bin)
125 char fullpath[PATH_MAX];
127 int chars = snprintf(fullpath, PATH_MAX,
"%s/%s", dir, bin);
130 if (chars >= PATH_MAX)
132 if (!realpath(fullpath, ret))
134 if (stat(fullpath, &sb) != 0)
141 getprogpath(
char ret[PATH_MAX],
const char *bin)
145 if (test_dir(ret,
"/", bin) == 0)
151 if (strchr(bin,
'/')) {
153 if (!getcwd(cwd, PATH_MAX))
155 if (test_dir(ret, cwd, bin) == 0)
162 if ((pv = getenv(
"PATH")) ==
nullptr)
164 char *s = strdup(pv);
168 for (
char *t = strtok_r(s,
":", &state); t !=
nullptr;
169 t = strtok_r(
nullptr,
":", &state)) {
170 if (test_dir(ret, t, bin) == 0) {
178 #endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__ 183 #if defined(__APPLE__) 187 char exe_path[MAXPATHLEN];
189 if (_NSGetExecutablePath(exe_path, &size) == 0) {
190 char link_path[MAXPATHLEN];
191 if (realpath(exe_path, link_path))
194 #elif defined(__FreeBSD__) 199 char exe_path[PATH_MAX];
200 #if __FreeBSD_version >= 1300057 201 if (elf_aux_info(AT_EXECPATH, exe_path,
sizeof(exe_path)) == 0)
207 char **p = ::environ;
212 switch (*(uintptr_t *)p++) {
222 if (getprogpath(exe_path, argv0) != NULL)
224 #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__minix) || \ 225 defined(__DragonFly__) || defined(__FreeBSD_kernel__) || defined(_AIX) 226 const char *curproc =
"/proc/curproc/file";
227 char exe_path[PATH_MAX];
229 ssize_t len = readlink(curproc, exe_path,
sizeof(exe_path));
233 len = std::min(len, ssize_t(
sizeof(exe_path) - 1));
234 exe_path[len] =
'\0';
239 if (getprogpath(exe_path, argv0) != NULL)
241 #elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__) 242 char exe_path[MAXPATHLEN];
243 const char *aPath =
"/proc/self/exe";
246 ssize_t len = readlink(aPath, exe_path,
sizeof(exe_path));
252 len = std::min(len, ssize_t(
sizeof(exe_path) - 1));
253 exe_path[len] =
'\0';
259 #if _POSIX_VERSION >= 200112 || defined(__GLIBC__) 260 if (
char *
real_path = realpath(exe_path, NULL)) {
261 std::string ret = std::string(
real_path);
267 if (realpath(exe_path, real_path))
268 return std::string(real_path);
272 if (getprogpath(exe_path, argv0))
274 #elif defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) 277 int err = dladdr(MainAddr, &DLInfo);
283 char link_path[MAXPATHLEN];
284 if (realpath(DLInfo.dli_fname, link_path))
287 #error GetMainExecutable is not implemented on this host yet. 301 return UniqueID(fs_st_dev, fs_st_ino);
310 if (::STATVFS(const_cast<char *>(Path.
str().c_str()), &Vfs))
311 return std::error_code(errno, std::generic_category());
312 auto FrSize = STATVFS_F_FRSIZE(Vfs);
313 space_info SpaceInfo;
314 SpaceInfo.capacity =
static_cast<uint64_t
>(Vfs.f_blocks) * FrSize;
315 SpaceInfo.free =
static_cast<uint64_t
>(Vfs.f_bfree) * FrSize;
316 SpaceInfo.available =
static_cast<uint64_t
>(Vfs.f_bavail) * FrSize;
323 const char *pwd = ::getenv(
"PWD");
329 result.
append(pwd, pwd + strlen(pwd));
330 return std::error_code();
341 if (::getcwd(result.
data(), result.
capacity()) ==
nullptr) {
344 return std::error_code(errno, std::generic_category());
352 return std::error_code();
359 if (::chdir(p.
begin()) == -1)
360 return std::error_code(errno, std::generic_category());
362 return std::error_code();
371 if (errno != EEXIST || !IgnoreExisting)
372 return std::error_code(errno, std::generic_category());
375 return std::error_code();
388 return std::error_code(errno, std::generic_category());
390 return std::error_code();
401 return std::error_code(errno, std::generic_category());
403 return std::error_code();
406 std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting) {
408 StringRef p = path.toNullTerminatedStringRef(path_storage);
411 if (lstat(p.
begin(), &buf) != 0) {
412 if (errno != ENOENT || !IgnoreNonExisting)
413 return std::error_code(errno, std::generic_category());
414 return std::error_code();
422 if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode))
425 if (::
remove(p.
begin()) == -1) {
426 if (errno != ENOENT || !IgnoreNonExisting)
427 return std::error_code(errno, std::generic_category());
430 return std::error_code();
433 static bool is_local_impl(
struct STATVFS &Vfs) {
434 #if defined(__linux__) || defined(__GNU__) 435 #ifndef NFS_SUPER_MAGIC 436 #define NFS_SUPER_MAGIC 0x6969 438 #ifndef SMB_SUPER_MAGIC 439 #define SMB_SUPER_MAGIC 0x517B 441 #ifndef CIFS_MAGIC_NUMBER 442 #define CIFS_MAGIC_NUMBER 0xFF534D42 449 case NFS_SUPER_MAGIC:
450 case SMB_SUPER_MAGIC:
451 case CIFS_MAGIC_NUMBER:
456 #elif defined(__CYGWIN__) 459 #elif defined(__Fuchsia__) 462 #elif defined(__EMSCRIPTEN__) 465 #elif defined(__HAIKU__) 472 return !fstype.equals(
"nfs");
477 size_t BufSize = 2048u;
478 std::unique_ptr<char[]> Buf;
481 Buf = std::make_unique<char[]>(BufSize);
482 Ret = mntctl(MCTL_QUERY, BufSize, Buf.get());
485 BufSize = *
reinterpret_cast<unsigned int *
>(Buf.get());
494 char *CurObjPtr = Buf.get();
496 struct vmount *Vp =
reinterpret_cast<struct vmount *
>(CurObjPtr);
497 static_assert(
sizeof(Vfs.f_fsid) ==
sizeof(Vp->vmt_fsid),
498 "fsid length mismatch");
499 if (
memcmp(&Vfs.f_fsid, &Vp->vmt_fsid,
sizeof Vfs.f_fsid) == 0)
500 return (Vp->vmt_flags & MNT_REMOTE) == 0;
502 CurObjPtr += Vp->vmt_length;
508 return !!(STATVFS_F_FLAG(Vfs) & MNT_LOCAL);
514 if (::STATVFS(const_cast<char *>(Path.
str().c_str()), &Vfs))
515 return std::error_code(errno, std::generic_category());
517 Result = is_local_impl(Vfs);
518 return std::error_code();
521 std::error_code
is_local(
int FD,
bool &Result) {
523 if (::FSTATVFS(FD, &Vfs))
524 return std::error_code(errno, std::generic_category());
526 Result = is_local_impl(Vfs);
527 return std::error_code();
538 return std::error_code(errno, std::generic_category());
540 return std::error_code();
544 #if defined(HAVE_POSIX_FALLOCATE) 547 if (
int Err = ::posix_fallocate(FD, 0, Size)) {
549 constexpr
int NotSupportedError = ENOTSUP;
551 constexpr
int NotSupportedError = EOPNOTSUPP;
553 if (Err != EINVAL && Err != NotSupportedError)
554 return std::error_code(Err, std::generic_category());
559 if (::ftruncate(FD, Size) == -1)
560 return std::error_code(errno, std::generic_category());
562 return std::error_code();
581 if (::
access(P.
begin(), convertAccessMode(Mode)) == -1)
582 return std::error_code(errno, std::generic_category());
587 if (0 != stat(P.
begin(), &buf))
589 if (!S_ISREG(buf.st_mode))
593 return std::error_code();
602 return A.fs_st_dev == B.fs_st_dev &&
603 A.fs_st_ino == B.fs_st_ino;
607 file_status fsA, fsB;
608 if (std::error_code ec =
status(A, fsA))
610 if (std::error_code ec =
status(B, fsB))
613 return std::error_code();
618 if (PathStr.empty() || !PathStr.startswith(
"~"))
634 Path[0] = Storage[0];
641 struct passwd *
Entry =
nullptr;
643 Entry = ::getpwnam(User.c_str());
652 Path.
append(Entry->pw_dir, Entry->pw_dir + strlen(Entry->pw_dir));
663 expandTildeExpr(dest);
668 static file_type typeForMode(mode_t Mode) {
671 else if (S_ISREG(Mode))
673 else if (S_ISBLK(Mode))
675 else if (S_ISCHR(Mode))
677 else if (S_ISFIFO(Mode))
679 else if (S_ISSOCK(Mode))
681 else if (S_ISLNK(Mode))
686 static std::error_code fillStatus(
int StatRet,
const struct stat &
Status,
687 file_status &Result) {
689 std::error_code
EC(errno, std::generic_category());
698 #if defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) 699 atime_nsec = Status.st_atimespec.tv_nsec;
700 mtime_nsec = Status.st_mtimespec.tv_nsec;
701 #elif defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) 702 atime_nsec = Status.st_atim.tv_nsec;
703 mtime_nsec = Status.st_mtim.tv_nsec;
705 atime_nsec = mtime_nsec = 0;
709 Result = file_status(typeForMode(Status.st_mode), Perms, Status.st_dev,
710 Status.st_nlink, Status.st_ino,
711 Status.st_atime, atime_nsec, Status.st_mtime, mtime_nsec,
712 Status.st_uid, Status.st_gid, Status.st_size);
714 return std::error_code();
717 std::error_code
status(
const Twine &Path, file_status &Result,
bool Follow) {
722 int StatRet = (Follow ? ::stat : ::lstat)(P.
begin(), &Status);
723 return fillStatus(StatRet, Status, Result);
726 std::error_code
status(
int FD, file_status &Result) {
728 int StatRet = ::fstat(FD, &Status);
729 return fillStatus(StatRet, Status, Result);
735 unsigned Mask = ::umask(0);
736 (void) ::umask(Mask);
744 if (::chmod(P.
begin(), Permissions))
745 return std::error_code(errno, std::generic_category());
746 return std::error_code();
750 if (::fchmod(FD, Permissions))
751 return std::error_code(errno, std::generic_category());
752 return std::error_code();
756 TimePoint<> ModificationTime) {
757 #if defined(HAVE_FUTIMENS) 761 if (::futimens(FD, Times))
762 return std::error_code(errno, std::generic_category());
763 return std::error_code();
764 #elif defined(HAVE_FUTIMES) 767 std::chrono::time_point_cast<std::chrono::microseconds>(AccessTime));
769 sys::toTimeVal(std::chrono::time_point_cast<std::chrono::microseconds>(
771 if (::futimes(FD, Times))
772 return std::error_code(errno, std::generic_category());
773 return std::error_code();
775 #warning Missing futimes() and futimens() 784 int flags = (Mode == readwrite) ? MAP_SHARED : MAP_PRIVATE;
785 int prot = (Mode == readonly) ? PROT_READ : (PROT_READ | PROT_WRITE);
786 #if defined(__APPLE__) 796 if (Mode == readonly) {
797 #if defined(MAP_RESILIENT_CODESIGN) 798 flags |= MAP_RESILIENT_CODESIGN;
800 #if defined(MAP_RESILIENT_MEDIA) 801 flags |= MAP_RESILIENT_MEDIA;
804 #endif // #if defined (__APPLE__) 806 Mapping = ::mmap(
nullptr, Size, prot, flags, FD, Offset);
807 if (Mapping == MAP_FAILED)
808 return std::error_code(errno, std::generic_category());
809 return std::error_code();
813 uint64_t offset, std::error_code &ec)
814 : Size(length), Mapping(), Mode(mode) {
816 ec =
init(fd, offset, mode);
821 mapped_file_region::~mapped_file_region() {
823 ::munmap(Mapping, Size);
827 assert(Mapping &&
"Mapping failed but used anyway!");
831 char *mapped_file_region::data()
const {
832 assert(Mapping &&
"Mapping failed but used anyway!");
833 return reinterpret_cast<char*
>(Mapping);
836 const char *mapped_file_region::const_data()
const {
837 assert(Mapping &&
"Mapping failed but used anyway!");
838 return reinterpret_cast<const char*
>(Mapping);
841 int mapped_file_region::alignment() {
847 bool follow_symlinks) {
849 DIR *directory = ::opendir(path_null.c_str());
851 return std::error_code(errno, std::generic_category());
853 it.IterationHandle =
reinterpret_cast<intptr_t>(directory);
856 it.CurrentEntry = directory_entry(path_null.str(), follow_symlinks);
861 if (it.IterationHandle)
862 ::closedir(reinterpret_cast<DIR *>(it.IterationHandle));
863 it.IterationHandle = 0;
864 it.CurrentEntry = directory_entry();
865 return std::error_code();
868 static file_type direntType(dirent* Entry) {
875 return typeForMode(DTTOIF(Entry->d_type));
878 return file_type::type_unknown;
884 dirent *CurDir = ::readdir(reinterpret_cast<DIR *>(It.IterationHandle));
885 if (CurDir ==
nullptr && errno != 0) {
886 return std::error_code(errno, std::generic_category());
887 }
else if (CurDir !=
nullptr) {
889 if ((
Name.size() == 1 &&
Name[0] ==
'.') ||
892 It.CurrentEntry.replace_filename(
Name, direntType(CurDir));
896 return std::error_code();
901 if (
auto EC =
fs::status(Path, s, FollowSymlinks))
906 #if !defined(F_GETPATH) 907 static bool hasProcSelfFD() {
910 static const bool Result = (
::access(
"/proc/self/fd", R_OK) == 0);
942 if (Flags & OF_Append)
956 int OpenFlags = nativeOpenFlags(Disp, Flags, Access);
964 return std::error_code(errno, std::generic_category());
967 int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
969 assert(r == 0 &&
"fcntl(F_SETFD, FD_CLOEXEC) failed");
972 return std::error_code();
980 std::error_code
EC =
openFile(Name, FD, Disp, Access, Flags, Mode);
996 return std::error_code();
998 #if defined(F_GETPATH) 1001 char Buffer[MAXPATHLEN];
1002 if (::fcntl(ResultFD, F_GETPATH, Buffer) != -1)
1003 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1005 char Buffer[PATH_MAX];
1006 if (hasProcSelfFD()) {
1008 snprintf(ProcPath,
sizeof(ProcPath),
"/proc/self/fd/%d", ResultFD);
1009 ssize_t CharCount = ::readlink(ProcPath, Buffer,
sizeof(Buffer));
1011 RealPath->
append(Buffer, Buffer + CharCount);
1017 if (::realpath(P.
begin(), Buffer) !=
nullptr)
1018 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1021 return std::error_code();
1027 std::error_code EC =
openFileForRead(Name, ResultFD, Flags, RealPath);
1040 if (ssize_t(NumRead) == -1)
1051 if (lseek(FD, Offset, SEEK_SET) == -1)
1067 template <
typename T>
1068 static std::error_code remove_directories_impl(
const T &Entry,
1069 bool IgnoreErrors) {
1071 directory_iterator Begin(Entry, EC,
false);
1072 directory_iterator End;
1073 while (Begin != End) {
1074 auto &Item = *Begin;
1076 if (!st && !IgnoreErrors)
1080 EC = remove_directories_impl(Item, IgnoreErrors);
1081 if (EC && !IgnoreErrors)
1086 if (EC && !IgnoreErrors)
1089 Begin.increment(EC);
1090 if (EC && !IgnoreErrors)
1093 return std::error_code();
1097 auto EC = remove_directories_impl(path, IgnoreErrors);
1098 if (EC && !IgnoreErrors)
1101 if (EC && !IgnoreErrors)
1103 return std::error_code();
1110 return std::error_code();
1115 expandTildeExpr(Storage);
1121 char Buffer[PATH_MAX];
1122 if (::realpath(P.
begin(), Buffer) ==
nullptr)
1123 return std::error_code(errno, std::generic_category());
1124 dest.
append(Buffer, Buffer + strlen(Buffer));
1125 return std::error_code();
1133 char *RequestedDir = getenv(
"HOME");
1134 if (!RequestedDir) {
1135 struct passwd *pw = getpwuid(getuid());
1136 if (pw && pw->pw_dir)
1137 RequestedDir = pw->pw_dir;
1143 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1148 #if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR) 1151 int ConfName = TempDir ? _CS_DARWIN_USER_TEMP_DIR
1152 : _CS_DARWIN_USER_CACHE_DIR;
1153 size_t ConfLen = confstr(ConfName,
nullptr, 0);
1157 ConfLen = confstr(ConfName, Result.
data(), Result.
size());
1158 }
while (ConfLen > 0 && ConfLen != Result.
size());
1172 static const char *getEnvTempDir() {
1175 const char *EnvironmentVariables[] = {
"TMPDIR",
"TMP",
"TEMP",
"TEMPDIR"};
1176 for (
const char *Env : EnvironmentVariables) {
1177 if (
const char *Dir = std::getenv(Env))
1184 static const char *getDefaultTempDir(
bool ErasedOnReboot) {
1198 if (ErasedOnReboot) {
1200 if (
const char *RequestedDir = getEnvTempDir()) {
1201 Result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1206 if (getDarwinConfDir(ErasedOnReboot, Result))
1209 const char *RequestedDir = getDefaultTempDir(ErasedOnReboot);
1210 Result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1225 #if __has_builtin(__builtin_available) && defined(COPYFILE_CLONE) 1226 if (__builtin_available(macos 10.12, *)) {
1232 if (!IsSymlink && !
exists(To))
1233 Flag = COPYFILE_CLONE;
1237 copyfile(From.
str().c_str(), To.
str().c_str(), NULL,
Flag);
1240 return std::error_code();
1241 return std::error_code(errno, std::generic_category());
const file_t kInvalidFile
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
bool can_execute(const Twine &Path)
Can we execute this file?
Represents either an error or a value T.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
bool status_known(const basic_file_status &s)
Is status available?
This class represents lattice values for constants.
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_NODISCARD 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...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
file_t getStderrHandle()
Return an open handle to standard error.
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
bool is_directory(const basic_file_status &status)
Does status represent a directory?
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...
void reserve(size_type N)
std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
Represents the result of a call to sys::fs::status().
CD_OpenExisting - When opening a file:
uint32_t fs_st_mtime_nsec
Expected< size_t > readNativeFileSlice(file_t FileHandle, MutableArrayRef< char > Buf, uint64_t Offset)
Reads Buf.size() bytes from FileHandle at offset Offset into Buf.
struct timespec toTimeSpec(TimePoint<> TP)
Convert a time point to struct timespec.
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
std::error_code make_error_code(BitcodeError E)
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Tagged union holding either a T or a Error.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
When a child process is launched, this file should remain open in the child process.
unsigned getUmask()
Get file creation mode mask of the process.
CD_CreateNew - When opening a file:
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.
LLVM_NODISCARD size_t size() const
size - Get the string size.
static unsigned getPageSizeEstimate()
Get the process's estimated page size.
file_t getStdinHandle()
Return an open handle to standard in.
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...
Flag
These should be considered private to the implementation of the MCInstrDesc class.
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
void expand_tilde(const Twine &path, SmallVectorImpl< char > &output)
Expands ~ expressions to the user's home directory.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
UniqueID getUniqueID() const
size_t size() const
size - Get the array size.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void set_size(size_t N)
Set the array size to N, which the current array must have enough capacity for.
std::error_code getError() const
uint32_t getLinkCount() const
TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such...
std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
auto RetryAfterSignal(const FailT &Fail, const Fun &F, const Args &... As) -> decltype(F(As...))
struct timeval toTimeVal(TimePoint< std::chrono::microseconds > TP)
Convert a time point to struct timeval.
Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
uint32_t fs_st_atime_nsec
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
std::error_code directory_iterator_construct(DirIterState &, StringRef, bool)
BlockVerifier::State From
The file should be opened in append mode.
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.
std::error_code closeFile(file_t &F)
Close the file object.
std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
iterator insert(iterator I, T &&Elt)
std::error_code set_current_path(const Twine &path)
Set the current path.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
std::error_code directory_iterator_destruct(DirIterState &)
pointer data()
Return a pointer to the vector's buffer, even if empty().
Merge contiguous icmps into a memcmp
file_type
An enumeration for the file system's view of the type.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
std::string str() const
Return the twine contents as a std::string.
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?
CD_CreateAlways - When opening a file:
Lightweight error class with error context and mandatory checking.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static std::error_code SafelyCloseFileDescriptor(int FD)
bool home_directory(SmallVectorImpl< char > &result)
Get the user's home directory.
file_t getStdoutHandle()
Return an open handle to standard out.
std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
StringRef - Represent a constant reference to a string, i.e.
CD_OpenAlways - When opening a file:
TimePoint getLastAccessedTime() const
The file access time as reported from the underlying file system.
bool is_symlink_file(const basic_file_status &status)
Does status represent a symlink file?
bool exists(const basic_file_status &status)
Does file exist?
TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.