40#include <mach-o/dyld.h>
42#if __has_include(<sys/clonefile.h>)
43#include <sys/clonefile.h>
45#elif defined(__FreeBSD__)
47#if __FreeBSD_version >= 1300057
50#include <machine/elf.h>
53#elif defined(__DragonFly__)
71#define PATH_MAX _XOPEN_PATH_MAX
76#if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && \
77 !defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX)
78#include <sys/statvfs.h>
79#define STATVFS statvfs
80#define FSTATVFS fstatvfs
81#define STATVFS_F_FRSIZE(vfs) vfs.f_frsize
83#if defined(__OpenBSD__) || defined(__FreeBSD__)
86#elif defined(__linux__)
87#if defined(HAVE_LINUX_MAGIC_H)
88#include <linux/magic.h>
90#if defined(HAVE_LINUX_NFS_FS_H)
91#include <linux/nfs_fs.h>
93#if defined(HAVE_LINUX_SMB_H)
99#include <sys/statfs.h>
105#include <sys/vmount.h>
107#include <sys/mount.h>
109#define STATVFS statfs
110#define FSTATVFS fstatfs
111#define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize)
114#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
116#define STATVFS_F_FLAG(vfs) (vfs).f_flag
118#define STATVFS_F_FLAG(vfs) (vfs).f_flags
129#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
130 defined(__FreeBSD_kernel__) || defined(__linux__) || defined(__CYGWIN__) || \
131 defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || \
132 (defined(__sun__) && defined(__svr4__) || defined(__HAIKU__))
133static int test_dir(
char ret[
PATH_MAX],
const char *dir,
const char *bin) {
137 int chars = snprintf(fullpath,
PATH_MAX,
"%s/%s", dir, bin);
142 if (!realpath(fullpath, ret))
144 if (stat(fullpath, &sb) != 0)
150static char *getprogpath(
char ret[
PATH_MAX],
const char *bin) {
156 if (test_dir(ret,
"/", bin) == 0)
162 if (strchr(bin,
'/')) {
166 if (test_dir(ret, cwd, bin) == 0)
173 if ((pv = getenv(
"PATH")) ==
nullptr)
175 char *s = strdup(pv);
179 for (
char *t = strtok_r(s,
":", &state); t !=
nullptr;
180 t = strtok_r(
nullptr,
":", &state)) {
181 if (test_dir(ret, t, bin) == 0) {
194#if defined(__APPLE__)
200 if (_NSGetExecutablePath(exe_path, &size) == 0) {
202 if (realpath(exe_path, link_path))
205#elif defined(__FreeBSD__)
211#if __FreeBSD_version >= 1300057
212 if (elf_aux_info(AT_EXECPATH, exe_path,
sizeof(exe_path)) == 0) {
214 if (realpath(exe_path, link_path))
221 char **
p = ::environ;
225 for (Elf_Auxinfo *aux = (Elf_Auxinfo *)
p; aux->a_type != AT_NULL; aux++) {
226 if (aux->a_type == AT_EXECPATH) {
228 if (realpath((
char *)aux->a_un.a_ptr, link_path))
234 if (getprogpath(exe_path, argv0) != NULL)
236#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) || \
238 const char *curproc =
"/proc/curproc/file";
241 ssize_t len = readlink(curproc, exe_path,
sizeof(exe_path));
245 len = std::min(len, ssize_t(
sizeof(exe_path) - 1));
246 exe_path[len] =
'\0';
251 if (getprogpath(exe_path, argv0) != NULL)
253#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__)
255 const char *aPath =
"/proc/self/exe";
258 ssize_t len = readlink(aPath, exe_path,
sizeof(exe_path));
264 len = std::min(len, ssize_t(
sizeof(exe_path) - 1));
265 exe_path[len] =
'\0';
271#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
272 if (
char *
real_path = realpath(exe_path,
nullptr)) {
273 std::string ret = std::string(
real_path);
284 if (getprogpath(exe_path, argv0))
286#elif defined(__OpenBSD__) || defined(__HAIKU__)
289 if (getprogpath(exe_path, argv0) != NULL)
291#elif defined(__sun__) && defined(__svr4__)
293 const char *aPath =
"/proc/self/execname";
295 int fd = open(aPath, O_RDONLY);
298 if (
read(fd, exe_path,
sizeof(exe_path)) < 0)
303 if (getprogpath(exe_path, argv0) != NULL)
305#elif defined(__MVS__)
308 char exe_path[PS_PATHBLEN];
309 pid_t pid = getpid();
311 memset(&buf, 0,
sizeof(buf));
312 buf.ps_pathptr = exe_path;
313 buf.ps_pathlen =
sizeof(exe_path);
316 if ((token = w_getpsent(token, &buf,
sizeof(buf))) <= 0)
318 if (buf.ps_pid != pid)
325#elif defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
328 int err = dladdr(MainAddr, &DLInfo);
335 if (realpath(DLInfo.dli_fname, link_path))
338#error GetMainExecutable is not implemented on this host yet.
352 return UniqueID(fs_st_dev, fs_st_ino);
359 if (::STATVFS(
const_cast<char *
>(
Path.str().c_str()), &Vfs))
361 auto FrSize = STATVFS_F_FRSIZE(Vfs);
362 space_info SpaceInfo;
363 SpaceInfo.capacity =
static_cast<uint64_t>(Vfs.f_blocks) * FrSize;
364 SpaceInfo.free =
static_cast<uint64_t>(Vfs.f_bfree) * FrSize;
365 SpaceInfo.available =
static_cast<uint64_t>(Vfs.f_bavail) * FrSize;
372 const char *pwd = ::getenv(
"PWD");
378 result.
append(pwd, pwd + strlen(pwd));
379 return std::error_code();
385 if (::getcwd(result.
data(), result.
size()) ==
nullptr) {
387 if (errno != ENOMEM) {
398 return std::error_code();
405 if (::chdir(
p.begin()) == -1)
408 return std::error_code();
416 if (::mkdir(
p.begin(), Perms) == -1) {
417 if (errno != EEXIST || !IgnoreExisting)
421 return std::error_code();
433 if (::symlink(t.
begin(),
f.begin()) == -1)
436 return std::error_code();
446 if (::link(t.
begin(),
f.begin()) == -1)
449 return std::error_code();
452std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting) {
454 StringRef p = path.toNullTerminatedStringRef(path_storage);
457 if (lstat(
p.begin(), &buf) != 0) {
458 if (errno != ENOENT || !IgnoreNonExisting)
460 return std::error_code();
468 if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode))
472 if (errno != ENOENT || !IgnoreNonExisting)
476 return std::error_code();
479static bool is_local_impl(
struct STATVFS &Vfs) {
480#if defined(__linux__) || defined(__GNU__)
481#ifndef NFS_SUPER_MAGIC
482#define NFS_SUPER_MAGIC 0x6969
484#ifndef SMB_SUPER_MAGIC
485#define SMB_SUPER_MAGIC 0x517B
487#ifndef CIFS_MAGIC_NUMBER
488#define CIFS_MAGIC_NUMBER 0xFF534D42
495 case NFS_SUPER_MAGIC:
496 case SMB_SUPER_MAGIC:
497 case CIFS_MAGIC_NUMBER:
502#elif defined(__CYGWIN__)
505#elif defined(__Fuchsia__)
508#elif defined(__EMSCRIPTEN__)
511#elif defined(__HAIKU__)
519 return fstype !=
"nfs";
524 size_t BufSize = 2048
u;
525 std::unique_ptr<char[]> Buf;
528 Buf = std::make_unique<char[]>(BufSize);
529 Ret = mntctl(MCTL_QUERY, BufSize, Buf.get());
532 BufSize = *
reinterpret_cast<unsigned int *
>(Buf.get());
541 char *CurObjPtr = Buf.get();
543 struct vmount *Vp =
reinterpret_cast<struct vmount *
>(CurObjPtr);
544 static_assert(
sizeof(Vfs.f_fsid) ==
sizeof(Vp->vmt_fsid),
545 "fsid length mismatch");
546 if (
memcmp(&Vfs.f_fsid, &Vp->vmt_fsid,
sizeof Vfs.f_fsid) == 0)
547 return (Vp->vmt_flags & MNT_REMOTE) == 0;
549 CurObjPtr += Vp->vmt_length;
554#elif defined(__MVS__)
559 return !!(STATVFS_F_FLAG(Vfs) & MNT_LOCAL);
565 if (::STATVFS(
const_cast<char *
>(
Path.str().c_str()), &Vfs))
568 Result = is_local_impl(Vfs);
569 return std::error_code();
572std::error_code
is_local(
int FD,
bool &Result) {
574 if (::FSTATVFS(FD, &Vfs))
577 Result = is_local_impl(Vfs);
578 return std::error_code();
591 return std::error_code();
597 if (::ftruncate(FD,
Size) == -1)
600 return std::error_code();
625 if (0 != stat(
P.begin(), &buf))
627 if (!S_ISREG(buf.st_mode))
631 return std::error_code();
640 return A.fs_st_dev ==
B.fs_st_dev &&
A.fs_st_ino ==
B.fs_st_ino;
644 file_status fsA, fsB;
645 if (std::error_code ec =
status(
A, fsA))
647 if (std::error_code ec =
status(
B, fsB))
650 return std::error_code();
655 if (PathStr.empty() || !PathStr.starts_with(
"~"))
658 PathStr = PathStr.drop_front();
671 Path[0] = Storage[0];
678 std::unique_ptr<char[]> Buf;
679 long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
682 Buf = std::make_unique<char[]>(BufSize);
685 struct passwd *
Entry =
nullptr;
686 getpwnam_r(
User.c_str(), &Pwd, Buf.get(), BufSize, &Entry);
688 if (!Entry || !
Entry->pw_dir) {
705 expandTildeExpr(dest);
711 else if (S_ISREG(
Mode))
713 else if (S_ISBLK(
Mode))
715 else if (S_ISCHR(
Mode))
717 else if (S_ISFIFO(
Mode))
719 else if (S_ISSOCK(
Mode))
721 else if (S_ISLNK(
Mode))
726static std::error_code fillStatus(
int StatRet,
const struct stat &
Status,
727 file_status &Result) {
738#if defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
739 atime_nsec =
Status.st_atimespec.tv_nsec;
740 mtime_nsec =
Status.st_mtimespec.tv_nsec;
741#elif defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
742 atime_nsec =
Status.st_atim.tv_nsec;
743 mtime_nsec =
Status.st_mtim.tv_nsec;
745 atime_nsec = mtime_nsec = 0;
754 return std::error_code();
757std::error_code
status(
const Twine &Path, file_status &Result,
bool Follow) {
762 int StatRet = (Follow ? ::stat : ::lstat)(
P.begin(), &
Status);
763 return fillStatus(StatRet,
Status, Result);
766std::error_code
status(
int FD, file_status &Result) {
768 int StatRet = ::fstat(FD, &
Status);
769 return fillStatus(StatRet,
Status, Result);
775 unsigned Mask = ::umask(0);
784 if (::chmod(
P.begin(), Permissions))
786 return std::error_code();
790 if (::fchmod(FD, Permissions))
792 return std::error_code();
797#if defined(HAVE_FUTIMENS)
801 if (::futimens(FD, Times))
803 return std::error_code();
804#elif defined(HAVE_FUTIMES)
807 std::chrono::time_point_cast<std::chrono::microseconds>(AccessTime));
809 sys::toTimeVal(std::chrono::time_point_cast<std::chrono::microseconds>(
811 if (::futimes(FD, Times))
813 return std::error_code();
814#elif defined(__MVS__)
816 memset(&Attr, 0,
sizeof(Attr));
817 Attr.att_atimechg = 1;
819 Attr.att_mtimechg = 1;
821 if (::__fchattr(FD, &Attr,
sizeof(Attr)) != 0)
823 return std::error_code();
825#warning Missing futimes() and futimens()
835 int prot = (
Mode ==
readonly) ? PROT_READ : (PROT_READ | PROT_WRITE);
836#if defined(MAP_NORESERVE)
837 flags |= MAP_NORESERVE;
839#if defined(__APPLE__)
850#if defined(MAP_RESILIENT_CODESIGN)
851 flags |= MAP_RESILIENT_CODESIGN;
853#if defined(MAP_RESILIENT_MEDIA)
854 flags |= MAP_RESILIENT_MEDIA;
859 Mapping = ::mmap(
nullptr,
Size, prot, flags, FD,
Offset);
860 if (Mapping == MAP_FAILED)
862 return std::error_code();
866 uint64_t offset, std::error_code &ec)
871 copyFrom(mapped_file_region());
874void mapped_file_region::unmapImpl() {
876 ::munmap(Mapping,
Size);
879void mapped_file_region::dontNeedImpl() {
883#if defined(__MVS__) || defined(_AIX)
885#elif defined(POSIX_MADV_DONTNEED)
886 ::posix_madvise(Mapping,
Size, POSIX_MADV_DONTNEED);
888 ::madvise(Mapping,
Size, MADV_DONTNEED);
892int mapped_file_region::alignment() {
return Process::getPageSizeEstimate(); }
894std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
896 bool follow_symlinks) {
898 DIR *directory = ::opendir(path_null.c_str());
902 it.IterationHandle =
reinterpret_cast<intptr_t
>(directory);
904 path::append(path_null,
".");
905 it.CurrentEntry = directory_entry(path_null.str(), follow_symlinks);
909std::error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
910 if (it.IterationHandle)
911 ::closedir(
reinterpret_cast<DIR *
>(it.IterationHandle));
912 it.IterationHandle = 0;
913 it.CurrentEntry = directory_entry();
914 return std::error_code();
917static file_type direntType(dirent *Entry) {
924 return typeForMode(DTTOIF(
Entry->d_type));
927 return file_type::type_unknown;
931std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
933 dirent *CurDir = ::readdir(
reinterpret_cast<DIR *
>(It.IterationHandle));
934 if (CurDir ==
nullptr && errno != 0) {
936 }
else if (CurDir !=
nullptr) {
938 if ((
Name.size() == 1 &&
Name[0] ==
'.') ||
941 It.CurrentEntry.replace_filename(
Name, direntType(CurDir));
945 return std::error_code();
950 if (
auto EC = fs::status(Path, s, FollowSymlinks))
959#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
960#define TRY_PROC_SELF_FD
963#if !defined(F_GETPATH) && defined(TRY_PROC_SELF_FD)
964static bool hasProcSelfFD() {
967 static const bool Result = (::access(
"/proc/self/fd", R_OK) == 0);
972static int nativeOpenFlags(CreationDisposition Disp, OpenFlags Flags,
975 if (Access == FA_Read)
977 else if (Access == FA_Write)
979 else if (Access == (FA_Read | FA_Write))
984 if (Flags & OF_Append)
987 if (Disp == CD_CreateNew) {
990 }
else if (Disp == CD_CreateAlways) {
993 }
else if (Disp == CD_OpenAlways) {
995 }
else if (Disp == CD_OpenExisting) {
1003 if (Flags & OF_Append)
1008 if (!(Flags & OF_ChildInherit))
1016 CreationDisposition Disp, FileAccess Access,
1017 OpenFlags Flags,
unsigned Mode) {
1018 int OpenFlags = nativeOpenFlags(Disp, Flags, Access);
1024 auto Open = [&]() { return ::open(
P.begin(), OpenFlags,
Mode); };
1025 if ((ResultFD = sys::RetryAfterSignal(-1, Open)) < 0)
1028 if (!(Flags & OF_ChildInherit)) {
1029 int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
1031 assert(r == 0 &&
"fcntl(F_SETFD, FD_CLOEXEC) failed");
1089 if ((Flags & OF_Append) && lseek(ResultFD, 0, SEEK_END) == -1)
1092 if (fstat(ResultFD, &Stat) == -1)
1094 if (S_ISREG(Stat.st_mode)) {
1095 bool DoSetTag = (Access &
FA_Write) && (Disp != CD_OpenExisting) &&
1096 !Stat.st_tag.ft_txtflag && !Stat.st_tag.ft_ccsid &&
1098 if (Flags & OF_Text) {
1099 if (
auto EC = llvm::enableAutoConversion(ResultFD))
1102 if (
auto EC = llvm::setFileTag(ResultFD, CCSID_IBM_1047,
true))
1106 if (
auto EC = llvm::disableAutoConversion(ResultFD))
1109 if (
auto EC = llvm::setFileTag(ResultFD, FT_BINARY,
false))
1116 return std::error_code();
1120 FileAccess Access, OpenFlags Flags,
1133 std::error_code
EC =
1134 openFile(
Name, ResultFD, CD_OpenExisting, FA_Read, Flags, 0666);
1140 return std::error_code();
1142#if defined(F_GETPATH)
1146 if (::fcntl(ResultFD, F_GETPATH, Buffer) != -1)
1147 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1150#if defined(TRY_PROC_SELF_FD)
1151 if (hasProcSelfFD()) {
1153 snprintf(ProcPath,
sizeof(ProcPath),
"/proc/self/fd/%d", ResultFD);
1154 ssize_t CharCount = ::readlink(ProcPath, Buffer,
sizeof(Buffer));
1156 RealPath->
append(Buffer, Buffer + CharCount);
1163 if (::realpath(
P.begin(), Buffer) !=
nullptr)
1164 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1165#if defined(TRY_PROC_SELF_FD)
1169 return std::error_code();
1186#if defined(__APPLE__)
1187 size_t Size = std::min<size_t>(Buf.
size(), INT32_MAX);
1191 ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.
data(),
Size);
1192 if (ssize_t(NumRead) == -1)
1196#if defined(__MVS__) || defined(_AIX)
1198 if (fstat(FD, &
Status) == -1)
1200 if (S_ISDIR(
Status.st_mode))
1208#if defined(__APPLE__)
1209 size_t Size = std::min<size_t>(Buf.
size(), INT32_MAX);
1215 sys::RetryAfterSignal(-1, ::pread, FD, Buf.
data(),
Size,
Offset);
1217 if (lseek(FD,
Offset, SEEK_SET) == -1)
1219 ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.
data(),
Size);
1226std::error_code
tryLockFile(
int FD, std::chrono::milliseconds Timeout) {
1227 auto Start = std::chrono::steady_clock::now();
1228 auto End = Start + Timeout;
1231 memset(&Lock, 0,
sizeof(Lock));
1232 Lock.l_type = F_WRLCK;
1233 Lock.l_whence = SEEK_SET;
1236 if (::fcntl(FD, F_SETLK, &Lock) != -1)
1237 return std::error_code();
1240 return std::error_code(
Error, std::generic_category());
1242 }
while (std::chrono::steady_clock::now() <
End);
1248 memset(&Lock, 0,
sizeof(Lock));
1249 Lock.l_type = F_WRLCK;
1250 Lock.l_whence = SEEK_SET;
1253 if (::fcntl(FD, F_SETLKW, &Lock) != -1)
1254 return std::error_code();
1260 Lock.l_type = F_UNLCK;
1261 Lock.l_whence = SEEK_SET;
1264 if (::fcntl(FD, F_SETLK, &Lock) != -1)
1265 return std::error_code();
1272 return Process::SafelyCloseFileDescriptor(TmpF);
1275template <
typename T>
1276static std::error_code remove_directories_impl(
const T &Entry,
1277 bool IgnoreErrors) {
1279 directory_iterator Begin(Entry, EC,
false);
1280 directory_iterator
End;
1281 while (Begin !=
End) {
1282 auto &Item = *Begin;
1286 EC = remove_directories_impl(Item, IgnoreErrors);
1287 if (EC && !IgnoreErrors)
1291 EC = fs::remove(Item.path(),
true);
1292 if (EC && !IgnoreErrors)
1294 }
else if (!IgnoreErrors) {
1298 Begin.increment(EC);
1299 if (EC && !IgnoreErrors)
1302 return std::error_code();
1306 auto EC = remove_directories_impl(path, IgnoreErrors);
1307 if (EC && !IgnoreErrors)
1309 EC = fs::remove(path,
true);
1310 if (EC && !IgnoreErrors)
1312 return std::error_code();
1316 bool expand_tilde) {
1319 return std::error_code();
1324 expandTildeExpr(Storage);
1331 if (::realpath(
P.begin(), Buffer) ==
nullptr)
1333 dest.
append(Buffer, Buffer + strlen(Buffer));
1334 return std::error_code();
1338 auto FChown = [&]() { return ::fchown(FD, Owner, Group); };
1340 if ((sys::RetryAfterSignal(-1, FChown)) < 0)
1342 return std::error_code();
1350 std::unique_ptr<char[]> Buf;
1351 char *RequestedDir = getenv(
"HOME");
1352 if (!RequestedDir) {
1353 long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
1356 Buf = std::make_unique<char[]>(BufSize);
1358 struct passwd *pw =
nullptr;
1359 getpwuid_r(getuid(), &Pwd, Buf.get(), BufSize, &pw);
1360 if (pw && pw->pw_dir)
1361 RequestedDir = pw->pw_dir;
1367 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1372#if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
1375 int ConfName = TempDir ? _CS_DARWIN_USER_TEMP_DIR : _CS_DARWIN_USER_CACHE_DIR;
1376 size_t ConfLen = confstr(ConfName,
nullptr, 0);
1380 ConfLen = confstr(ConfName,
Result.data(),
Result.size());
1381 }
while (ConfLen > 0 && ConfLen !=
Result.size());
1399 append(result,
"Library",
"Preferences");
1405 if (
const char *RequestedDir = getenv(
"XDG_CONFIG_HOME")) {
1407 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1415 append(result,
".config");
1421 if (getDarwinConfDir(
false , result)) {
1427 if (
const char *RequestedDir = getenv(
"XDG_CACHE_HOME")) {
1429 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1436 append(result,
".cache");
1440static const char *getEnvTempDir() {
1443 const char *EnvironmentVariables[] = {
"TMPDIR",
"TMP",
"TEMP",
"TEMPDIR"};
1444 for (
const char *Env : EnvironmentVariables) {
1445 if (
const char *Dir = std::getenv(Env))
1452static const char *getDefaultTempDir(
bool ErasedOnReboot) {
1466 if (ErasedOnReboot) {
1468 if (
const char *RequestedDir = getEnvTempDir()) {
1469 Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
1474 if (getDarwinConfDir(ErasedOnReboot, Result))
1477 const char *RequestedDir = getDefaultTempDir(ErasedOnReboot);
1478 Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
1492 std::string FromS =
From.str();
1493 std::string ToS = To.
str();
1494#if __has_builtin(__builtin_available)
1495 if (__builtin_available(macos 10.12, *)) {
1502 if (!clonefile(FromS.c_str(), ToS.c_str(), 0))
1503 return std::error_code();
1513 return std::error_code(Errno, std::generic_category());
1522 if (!copyfile(FromS.c_str(), ToS.c_str(), NULL, COPYFILE_DATA))
1523 return std::error_code();
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
amode Optimize addressing mode
std::unique_ptr< MemoryBuffer > openFile(const Twine &Path)
Merge contiguous icmps into a memcmp
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
size_t size() const
size - Get the array size.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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 append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void truncate(size_type N)
Like resize, but requires that N is less than size().
pointer data()
Return a pointer to the vector's buffer, even if empty().
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
StringRef take_until(function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that no character in the prefix satisfies the given predicat...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string str() const
Return the twine contents as a std::string.
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
uint32_t fs_st_mtime_nsec
uint32_t fs_st_atime_nsec
TimePoint getLastAccessedTime() const
The file access time as reported from the underlying file system.
TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
Represents the result of a call to sys::fs::status().
uint32_t getLinkCount() const
UniqueID getUniqueID() const
mapped_file_region()=default
@ 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.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
initializer< Ty > init(const Ty &Val)
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
std::error_code directory_iterator_destruct(DirIterState &)
std::error_code directory_iterator_increment(DirIterState &)
std::error_code unlockFile(int FD)
Unlock the file.
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 remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
const file_t kInvalidFile
std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
Try to locks the file during the specified time.
Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
std::error_code closeFile(file_t &F)
Close the file object.
file_t getStdoutHandle()
Return an open handle to standard out.
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
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.
void expand_tilde(const Twine &path, SmallVectorImpl< char > &output)
Expands ~ expressions to the user's home directory.
Expected< size_t > readNativeFileSlice(file_t FileHandle, MutableArrayRef< char > Buf, uint64_t Offset)
Reads Buf.size() bytes from FileHandle at offset Offset into Buf.
std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
bool exists(const basic_file_status &status)
Does file exist?
file_type
An enumeration for the file system's view of the type.
std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group)
Change ownership of a file.
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
std::error_code lockFile(int FD)
Lock the file.
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
@ CD_OpenAlways
CD_OpenAlways - When opening a file:
std::error_code set_current_path(const Twine &path)
Set the current path.
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...
ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
file_t getStderrHandle()
Return an open handle to standard error.
bool status_known(const basic_file_status &s)
Is status available?
std::error_code is_local(const Twine &path, bool &result)
Is the file mounted on a local filesystem?
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
bool can_execute(const Twine &Path)
Can we execute this file?
unsigned getUmask()
Get file creation mode mask of the process.
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 current_path(SmallVectorImpl< char > &result)
Get the current path.
std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
bool is_directory(const basic_file_status &status)
Does status represent a directory?
file_t getStdinHandle()
Return an open handle to standard in.
bool user_config_directory(SmallVectorImpl< char > &result)
Get the directory where packages should read user-specific configurations.
bool home_directory(SmallVectorImpl< char > &result)
Get the user's home directory.
bool cache_directory(SmallVectorImpl< char > &result)
Get the directory where installed packages should put their machine-local cache, e....
void system_temp_directory(bool erasedOnReboot, SmallVectorImpl< char > &result)
Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
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.
struct timespec toTimeSpec(TimePoint<> TP)
Convert a time point to struct timespec.
struct timeval toTimeVal(TimePoint< std::chrono::microseconds > TP)
Convert a time point to struct timeval.
std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::error_code make_error_code(BitcodeError E)
@ no_such_file_or_directory
@ operation_not_permitted
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.