36#include <mach-o/dyld.h>
38#if __has_include(<sys/clonefile.h>)
39#include <sys/clonefile.h>
41#elif defined(__FreeBSD__)
43#if __FreeBSD_version >= 1300057
46#include <machine/elf.h>
49#elif defined(__DragonFly__)
67#define PATH_MAX _XOPEN_PATH_MAX
72#if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && \
73 !defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX)
74#include <sys/statvfs.h>
75#define STATVFS statvfs
76#define FSTATVFS fstatvfs
77#define STATVFS_F_FRSIZE(vfs) vfs.f_frsize
79#if defined(__OpenBSD__) || defined(__FreeBSD__)
82#elif defined(__linux__)
83#if defined(HAVE_LINUX_MAGIC_H)
84#include <linux/magic.h>
86#if defined(HAVE_LINUX_NFS_FS_H)
87#include <linux/nfs_fs.h>
89#if defined(HAVE_LINUX_SMB_H)
95#include <sys/statfs.h>
101#include <sys/vmount.h>
103#include <sys/mount.h>
105#define STATVFS statfs
106#define FSTATVFS fstatfs
107#define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize)
110#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
112#define STATVFS_F_FLAG(vfs) (vfs).f_flag
114#define STATVFS_F_FLAG(vfs) (vfs).f_flags
125#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
126 defined(__FreeBSD_kernel__) || defined(__linux__) || defined(__CYGWIN__) || \
127 defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || \
128 (defined(__sun__) && defined(__svr4__) || defined(__HAIKU__))
129static int test_dir(
char ret[
PATH_MAX],
const char *dir,
const char *bin) {
133 int chars = snprintf(fullpath,
PATH_MAX,
"%s/%s", dir, bin);
138 if (!realpath(fullpath, ret))
140 if (stat(fullpath, &sb) != 0)
146static char *getprogpath(
char ret[
PATH_MAX],
const char *bin) {
152 if (test_dir(ret,
"/", bin) == 0)
158 if (strchr(bin,
'/')) {
162 if (test_dir(ret, cwd, bin) == 0)
169 if ((pv = getenv(
"PATH")) ==
nullptr)
171 char *s = strdup(pv);
175 for (
char *t = strtok_r(s,
":", &state); t !=
nullptr;
176 t = strtok_r(
nullptr,
":", &state)) {
177 if (test_dir(ret, t, bin) == 0) {
190#if defined(__APPLE__)
196 if (_NSGetExecutablePath(exe_path, &size) == 0) {
198 if (realpath(exe_path, link_path))
201#elif defined(__FreeBSD__)
207#if __FreeBSD_version >= 1300057
208 if (elf_aux_info(AT_EXECPATH, exe_path,
sizeof(exe_path)) == 0) {
210 if (realpath(exe_path, link_path))
217 char **
p = ::environ;
221 for (Elf_Auxinfo *aux = (Elf_Auxinfo *)
p; aux->a_type != AT_NULL; aux++) {
222 if (aux->a_type == AT_EXECPATH) {
224 if (realpath((
char *)aux->a_un.a_ptr, link_path))
230 if (getprogpath(exe_path, argv0) != NULL)
232#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) || \
234 const char *curproc =
"/proc/curproc/file";
237 ssize_t len = readlink(curproc, exe_path,
sizeof(exe_path));
241 len = std::min(len, ssize_t(
sizeof(exe_path) - 1));
242 exe_path[len] =
'\0';
247 if (getprogpath(exe_path, argv0) != NULL)
249#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__)
251 const char *aPath =
"/proc/self/exe";
254 ssize_t len = readlink(aPath, exe_path,
sizeof(exe_path));
260 len = std::min(len, ssize_t(
sizeof(exe_path) - 1));
261 exe_path[len] =
'\0';
267#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
268 if (
char *
real_path = realpath(exe_path,
nullptr)) {
269 std::string ret = std::string(
real_path);
280 if (getprogpath(exe_path, argv0))
282#elif defined(__OpenBSD__) || defined(__HAIKU__)
285 if (getprogpath(exe_path, argv0) != NULL)
287#elif defined(__sun__) && defined(__svr4__)
289 const char *aPath =
"/proc/self/execname";
291 int fd = open(aPath, O_RDONLY);
294 if (
read(fd, exe_path,
sizeof(exe_path)) < 0)
299 if (getprogpath(exe_path, argv0) != NULL)
301#elif defined(__MVS__)
304 char exe_path[PS_PATHBLEN];
305 pid_t pid = getpid();
307 memset(&buf, 0,
sizeof(buf));
308 buf.ps_pathptr = exe_path;
309 buf.ps_pathlen =
sizeof(exe_path);
312 if ((token = w_getpsent(token, &buf,
sizeof(buf))) <= 0)
314 if (buf.ps_pid != pid)
321#elif defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
324 int err = dladdr(MainAddr, &DLInfo);
331 if (realpath(DLInfo.dli_fname, link_path))
334#error GetMainExecutable is not implemented on this host yet.
348 return UniqueID(fs_st_dev, fs_st_ino);
355 if (::STATVFS(
const_cast<char *
>(
Path.str().c_str()), &Vfs))
357 auto FrSize = STATVFS_F_FRSIZE(Vfs);
358 space_info SpaceInfo;
359 SpaceInfo.capacity =
static_cast<uint64_t>(Vfs.f_blocks) * FrSize;
360 SpaceInfo.free =
static_cast<uint64_t>(Vfs.f_bfree) * FrSize;
361 SpaceInfo.available =
static_cast<uint64_t>(Vfs.f_bavail) * FrSize;
368 const char *pwd = ::getenv(
"PWD");
374 result.
append(pwd, pwd + strlen(pwd));
375 return std::error_code();
381 if (::getcwd(result.
data(), result.
size()) ==
nullptr) {
383 if (errno != ENOMEM) {
394 return std::error_code();
401 if (::chdir(
p.begin()) == -1)
404 return std::error_code();
412 if (::mkdir(
p.begin(), Perms) == -1) {
413 if (errno != EEXIST || !IgnoreExisting)
417 return std::error_code();
429 if (::symlink(t.
begin(),
f.begin()) == -1)
432 return std::error_code();
442 if (::link(t.
begin(),
f.begin()) == -1)
445 return std::error_code();
448std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting) {
450 StringRef p = path.toNullTerminatedStringRef(path_storage);
453 if (lstat(
p.begin(), &buf) != 0) {
454 if (errno != ENOENT || !IgnoreNonExisting)
456 return std::error_code();
464 if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode))
468 if (errno != ENOENT || !IgnoreNonExisting)
472 return std::error_code();
475static bool is_local_impl(
struct STATVFS &Vfs) {
476#if defined(__linux__) || defined(__GNU__)
477#ifndef NFS_SUPER_MAGIC
478#define NFS_SUPER_MAGIC 0x6969
480#ifndef SMB_SUPER_MAGIC
481#define SMB_SUPER_MAGIC 0x517B
483#ifndef CIFS_MAGIC_NUMBER
484#define CIFS_MAGIC_NUMBER 0xFF534D42
486#if defined(__GNU__) && ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 39)))
491 case NFS_SUPER_MAGIC:
492 case SMB_SUPER_MAGIC:
493 case CIFS_MAGIC_NUMBER:
498#elif defined(__CYGWIN__)
501#elif defined(__Fuchsia__)
504#elif defined(__EMSCRIPTEN__)
507#elif defined(__HAIKU__)
515 return fstype !=
"nfs";
520 size_t BufSize = 2048
u;
521 std::unique_ptr<char[]> Buf;
524 Buf = std::make_unique<char[]>(BufSize);
525 Ret = mntctl(MCTL_QUERY, BufSize, Buf.get());
528 BufSize = *
reinterpret_cast<unsigned int *
>(Buf.get());
537 char *CurObjPtr = Buf.get();
539 struct vmount *Vp =
reinterpret_cast<struct vmount *
>(CurObjPtr);
540 static_assert(
sizeof(Vfs.f_fsid) ==
sizeof(Vp->vmt_fsid),
541 "fsid length mismatch");
542 if (
memcmp(&Vfs.f_fsid, &Vp->vmt_fsid,
sizeof Vfs.f_fsid) == 0)
543 return (Vp->vmt_flags & MNT_REMOTE) == 0;
545 CurObjPtr += Vp->vmt_length;
550#elif defined(__MVS__)
555 return !!(STATVFS_F_FLAG(Vfs) & MNT_LOCAL);
561 if (::STATVFS(
const_cast<char *
>(
Path.str().c_str()), &Vfs))
564 Result = is_local_impl(Vfs);
565 return std::error_code();
568std::error_code
is_local(
int FD,
bool &Result) {
570 if (::FSTATVFS(FD, &Vfs))
573 Result = is_local_impl(Vfs);
574 return std::error_code();
587 return std::error_code();
593 if (::ftruncate(FD,
Size) == -1)
596 return std::error_code();
621 if (0 != stat(
P.begin(), &buf))
623 if (!S_ISREG(buf.st_mode))
627 return std::error_code();
636 return A.fs_st_dev ==
B.fs_st_dev &&
A.fs_st_ino ==
B.fs_st_ino;
640 file_status fsA, fsB;
641 if (std::error_code ec =
status(
A, fsA))
643 if (std::error_code ec =
status(
B, fsB))
646 return std::error_code();
651 if (PathStr.empty() || !PathStr.starts_with(
"~"))
654 PathStr = PathStr.drop_front();
667 Path[0] = Storage[0];
674 std::unique_ptr<char[]> Buf;
675 long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
678 Buf = std::make_unique<char[]>(BufSize);
681 struct passwd *
Entry =
nullptr;
682 getpwnam_r(
User.c_str(), &Pwd, Buf.get(), BufSize, &Entry);
684 if (!Entry || !
Entry->pw_dir) {
701 expandTildeExpr(dest);
707 else if (S_ISREG(
Mode))
709 else if (S_ISBLK(
Mode))
711 else if (S_ISCHR(
Mode))
713 else if (S_ISFIFO(
Mode))
715 else if (S_ISSOCK(
Mode))
717 else if (S_ISLNK(
Mode))
722static std::error_code fillStatus(
int StatRet,
const struct stat &
Status,
723 file_status &Result) {
734#if defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
735 atime_nsec =
Status.st_atimespec.tv_nsec;
736 mtime_nsec =
Status.st_mtimespec.tv_nsec;
737#elif defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
738 atime_nsec =
Status.st_atim.tv_nsec;
739 mtime_nsec =
Status.st_mtim.tv_nsec;
741 atime_nsec = mtime_nsec = 0;
750 return std::error_code();
753std::error_code
status(
const Twine &Path, file_status &Result,
bool Follow) {
758 int StatRet = (Follow ? ::stat : ::lstat)(
P.begin(), &
Status);
759 return fillStatus(StatRet,
Status, Result);
762std::error_code
status(
int FD, file_status &Result) {
764 int StatRet = ::fstat(FD, &
Status);
765 return fillStatus(StatRet,
Status, Result);
771 unsigned Mask = ::umask(0);
780 if (::chmod(
P.begin(), Permissions))
782 return std::error_code();
786 if (::fchmod(FD, Permissions))
788 return std::error_code();
793#if defined(HAVE_FUTIMENS)
797 if (::futimens(FD, Times))
799 return std::error_code();
800#elif defined(HAVE_FUTIMES)
803 std::chrono::time_point_cast<std::chrono::microseconds>(AccessTime));
805 sys::toTimeVal(std::chrono::time_point_cast<std::chrono::microseconds>(
807 if (::futimes(FD, Times))
809 return std::error_code();
810#elif defined(__MVS__)
812 memset(&Attr, 0,
sizeof(Attr));
813 Attr.att_atimechg = 1;
815 Attr.att_mtimechg = 1;
817 if (::__fchattr(FD, &Attr,
sizeof(Attr)) != 0)
819 return std::error_code();
821#warning Missing futimes() and futimens()
831 int prot = (
Mode ==
readonly) ? PROT_READ : (PROT_READ | PROT_WRITE);
832#if defined(MAP_NORESERVE)
833 flags |= MAP_NORESERVE;
835#if defined(__APPLE__)
846#if defined(MAP_RESILIENT_CODESIGN)
847 flags |= MAP_RESILIENT_CODESIGN;
849#if defined(MAP_RESILIENT_MEDIA)
850 flags |= MAP_RESILIENT_MEDIA;
855 Mapping = ::mmap(
nullptr,
Size, prot, flags, FD,
Offset);
856 if (Mapping == MAP_FAILED)
858 return std::error_code();
862 uint64_t offset, std::error_code &ec)
867 copyFrom(mapped_file_region());
870void mapped_file_region::unmapImpl() {
872 ::munmap(Mapping,
Size);
875void mapped_file_region::dontNeedImpl() {
879#if defined(__MVS__) || defined(_AIX)
881#elif defined(POSIX_MADV_DONTNEED)
882 ::posix_madvise(Mapping,
Size, POSIX_MADV_DONTNEED);
884 ::madvise(Mapping,
Size, MADV_DONTNEED);
888int mapped_file_region::alignment() {
return Process::getPageSizeEstimate(); }
890std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
892 bool follow_symlinks) {
894 DIR *directory = ::opendir(path_null.c_str());
898 it.IterationHandle =
reinterpret_cast<intptr_t
>(directory);
900 path::append(path_null,
".");
901 it.CurrentEntry = directory_entry(path_null.str(), follow_symlinks);
905std::error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
906 if (it.IterationHandle)
907 ::closedir(
reinterpret_cast<DIR *
>(it.IterationHandle));
908 it.IterationHandle = 0;
909 it.CurrentEntry = directory_entry();
910 return std::error_code();
913static file_type direntType(dirent *Entry) {
920 return typeForMode(DTTOIF(
Entry->d_type));
923 return file_type::type_unknown;
927std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
929 dirent *CurDir = ::readdir(
reinterpret_cast<DIR *
>(It.IterationHandle));
930 if (CurDir ==
nullptr && errno != 0) {
932 }
else if (CurDir !=
nullptr) {
934 if ((
Name.size() == 1 &&
Name[0] ==
'.') ||
937 It.CurrentEntry.replace_filename(
Name, direntType(CurDir));
941 return std::error_code();
946 if (
auto EC = fs::status(Path, s, FollowSymlinks))
955#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
956#define TRY_PROC_SELF_FD
959#if !defined(F_GETPATH) && defined(TRY_PROC_SELF_FD)
960static bool hasProcSelfFD() {
963 static const bool Result = (::access(
"/proc/self/fd", R_OK) == 0);
968static int nativeOpenFlags(CreationDisposition Disp, OpenFlags Flags,
973 else if (
Access == FA_Write)
975 else if (
Access == (FA_Read | FA_Write))
980 if (Flags & OF_Append)
983 if (Disp == CD_CreateNew) {
986 }
else if (Disp == CD_CreateAlways) {
989 }
else if (Disp == CD_OpenAlways) {
991 }
else if (Disp == CD_OpenExisting) {
999 if (Flags & OF_Append)
1004 if (!(Flags & OF_ChildInherit))
1012 CreationDisposition Disp, FileAccess
Access,
1013 OpenFlags Flags,
unsigned Mode) {
1020 auto Open = [&]() { return ::open(
P.begin(), OpenFlags,
Mode); };
1021 if ((ResultFD = sys::RetryAfterSignal(-1, Open)) < 0)
1024 if (!(Flags & OF_ChildInherit)) {
1025 int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
1027 assert(r == 0 &&
"fcntl(F_SETFD, FD_CLOEXEC) failed");
1085 if ((Flags & OF_Append) && lseek(ResultFD, 0, SEEK_END) == -1)
1088 if (fstat(ResultFD, &Stat) == -1)
1090 if (S_ISREG(Stat.st_mode)) {
1091 bool DoSetTag = (
Access &
FA_Write) && (Disp != CD_OpenExisting) &&
1092 !Stat.st_tag.ft_txtflag && !Stat.st_tag.ft_ccsid &&
1094 if (Flags & OF_Text) {
1095 if (
auto EC = llvm::enablezOSAutoConversion(ResultFD))
1098 if (
auto EC = llvm::setzOSFileTag(ResultFD, CCSID_IBM_1047,
true))
1102 if (
auto EC = llvm::disablezOSAutoConversion(ResultFD))
1105 if (
auto EC = llvm::setzOSFileTag(ResultFD, FT_BINARY,
false))
1112 return std::error_code();
1116 FileAccess
Access, OpenFlags Flags,
1129 std::error_code
EC =
1130 openFile(
Name, ResultFD, CD_OpenExisting, FA_Read, Flags, 0666);
1136 return std::error_code();
1138#if defined(F_GETPATH)
1142 if (::fcntl(ResultFD, F_GETPATH, Buffer) != -1)
1143 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1146#if defined(TRY_PROC_SELF_FD)
1147 if (hasProcSelfFD()) {
1149 snprintf(ProcPath,
sizeof(ProcPath),
"/proc/self/fd/%d", ResultFD);
1150 ssize_t CharCount = ::readlink(ProcPath, Buffer,
sizeof(Buffer));
1152 RealPath->
append(Buffer, Buffer + CharCount);
1159 if (::realpath(
P.begin(), Buffer) !=
nullptr)
1160 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1161#if defined(TRY_PROC_SELF_FD)
1165 return std::error_code();
1182#if defined(__APPLE__)
1183 size_t Size = std::min<size_t>(Buf.
size(), INT32_MAX);
1187 ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.
data(),
Size);
1188 if (ssize_t(NumRead) == -1)
1192#if defined(__MVS__) || defined(_AIX)
1194 if (fstat(FD, &
Status) == -1)
1196 if (S_ISDIR(
Status.st_mode))
1204#if defined(__APPLE__)
1205 size_t Size = std::min<size_t>(Buf.
size(), INT32_MAX);
1211 sys::RetryAfterSignal(-1, ::pread, FD, Buf.
data(),
Size,
Offset);
1213 if (lseek(FD,
Offset, SEEK_SET) == -1)
1215 ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.
data(),
Size);
1222std::error_code
tryLockFile(
int FD, std::chrono::milliseconds Timeout) {
1223 auto Start = std::chrono::steady_clock::now();
1224 auto End = Start + Timeout;
1227 memset(&Lock, 0,
sizeof(Lock));
1228 Lock.l_type = F_WRLCK;
1229 Lock.l_whence = SEEK_SET;
1232 if (::fcntl(FD, F_SETLK, &Lock) != -1)
1233 return std::error_code();
1236 return std::error_code(
Error, std::generic_category());
1238 }
while (std::chrono::steady_clock::now() <
End);
1244 memset(&Lock, 0,
sizeof(Lock));
1245 Lock.l_type = F_WRLCK;
1246 Lock.l_whence = SEEK_SET;
1249 if (::fcntl(FD, F_SETLKW, &Lock) != -1)
1250 return std::error_code();
1256 Lock.l_type = F_UNLCK;
1257 Lock.l_whence = SEEK_SET;
1260 if (::fcntl(FD, F_SETLK, &Lock) != -1)
1261 return std::error_code();
1268 return Process::SafelyCloseFileDescriptor(TmpF);
1271template <
typename T>
1272static std::error_code remove_directories_impl(
const T &Entry,
1273 bool IgnoreErrors) {
1275 directory_iterator Begin(Entry, EC,
false);
1276 directory_iterator
End;
1277 while (Begin !=
End) {
1278 auto &Item = *Begin;
1282 EC = remove_directories_impl(Item, IgnoreErrors);
1283 if (EC && !IgnoreErrors)
1287 EC = fs::remove(Item.path(),
true);
1288 if (EC && !IgnoreErrors)
1290 }
else if (!IgnoreErrors) {
1294 Begin.increment(EC);
1295 if (EC && !IgnoreErrors)
1298 return std::error_code();
1302 auto EC = remove_directories_impl(path, IgnoreErrors);
1303 if (EC && !IgnoreErrors)
1305 EC = fs::remove(path,
true);
1306 if (EC && !IgnoreErrors)
1308 return std::error_code();
1312 bool expand_tilde) {
1315 return std::error_code();
1320 expandTildeExpr(Storage);
1327 if (::realpath(
P.begin(), Buffer) ==
nullptr)
1329 dest.
append(Buffer, Buffer + strlen(Buffer));
1330 return std::error_code();
1334 auto FChown = [&]() { return ::fchown(FD, Owner, Group); };
1336 if ((sys::RetryAfterSignal(-1, FChown)) < 0)
1338 return std::error_code();
1346 std::unique_ptr<char[]> Buf;
1347 char *RequestedDir = getenv(
"HOME");
1348 if (!RequestedDir) {
1349 long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
1352 Buf = std::make_unique<char[]>(BufSize);
1354 struct passwd *pw =
nullptr;
1355 getpwuid_r(getuid(), &Pwd, Buf.get(), BufSize, &pw);
1356 if (pw && pw->pw_dir)
1357 RequestedDir = pw->pw_dir;
1363 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1368#if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
1371 int ConfName = TempDir ? _CS_DARWIN_USER_TEMP_DIR : _CS_DARWIN_USER_CACHE_DIR;
1372 size_t ConfLen = confstr(ConfName,
nullptr, 0);
1376 ConfLen = confstr(ConfName,
Result.data(),
Result.size());
1377 }
while (ConfLen > 0 && ConfLen !=
Result.size());
1395 append(result,
"Library",
"Preferences");
1401 if (
const char *RequestedDir = getenv(
"XDG_CONFIG_HOME")) {
1403 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1411 append(result,
".config");
1417 if (getDarwinConfDir(
false , result)) {
1423 if (
const char *RequestedDir = getenv(
"XDG_CACHE_HOME")) {
1425 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1432 append(result,
".cache");
1436static const char *getEnvTempDir() {
1439 const char *EnvironmentVariables[] = {
"TMPDIR",
"TMP",
"TEMP",
"TEMPDIR"};
1440 for (
const char *Env : EnvironmentVariables) {
1441 if (
const char *Dir = std::getenv(Env))
1448static const char *getDefaultTempDir(
bool ErasedOnReboot) {
1462 if (ErasedOnReboot) {
1464 if (
const char *RequestedDir = getEnvTempDir()) {
1465 Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
1470 if (getDarwinConfDir(ErasedOnReboot, Result))
1473 const char *RequestedDir = getDefaultTempDir(ErasedOnReboot);
1474 Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
1488 std::string FromS =
From.str();
1489 std::string ToS = To.
str();
1490#if __has_builtin(__builtin_available)
1491 if (__builtin_available(macos 10.12, *)) {
1498 if (!clonefile(FromS.c_str(), ToS.c_str(), 0))
1499 return std::error_code();
1509 return std::error_code(Errno, std::generic_category());
1518 if (!copyfile(FromS.c_str(), ToS.c_str(), NULL, COPYFILE_DATA))
1519 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.