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(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \
131 defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || \
132 defined(__GNU__) || (defined(__sun__) && defined(__svr4__))
133static int test_dir(
char ret[PATH_MAX],
const char *dir,
const char *bin) {
135 char fullpath[PATH_MAX];
137 int chars = snprintf(fullpath, PATH_MAX,
"%s/%s", dir, bin);
140 if (chars >= PATH_MAX)
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,
'/')) {
164 if (!getcwd(cwd, PATH_MAX))
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__)
198 char exe_path[PATH_MAX];
200 if (_NSGetExecutablePath(exe_path, &size) == 0) {
201 char link_path[PATH_MAX];
202 if (realpath(exe_path, link_path))
205#elif defined(__FreeBSD__)
210 char exe_path[PATH_MAX];
211#if __FreeBSD_version >= 1300057
212 if (elf_aux_info(AT_EXECPATH, exe_path,
sizeof(exe_path)) == 0) {
213 char link_path[PATH_MAX];
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) {
227 char link_path[PATH_MAX];
228 if (realpath((
char *)aux->a_un.a_ptr, link_path))
234 if (getprogpath(exe_path, argv0) != NULL)
236#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__minix) || \
237 defined(__DragonFly__) || defined(__FreeBSD_kernel__) || defined(_AIX)
238 const char *curproc =
"/proc/curproc/file";
239 char exe_path[PATH_MAX];
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__)
254 char exe_path[PATH_MAX];
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(__sun__) && defined(__svr4__)
287 char exe_path[PATH_MAX];
288 const char *aPath =
"/proc/self/execname";
290 int fd = open(aPath, O_RDONLY);
293 if (
read(fd, exe_path,
sizeof(exe_path)) < 0)
298 if (getprogpath(exe_path, argv0) != NULL)
300#elif defined(__MVS__)
303 char exe_path[PS_PATHBLEN];
304 pid_t pid = getpid();
306 memset(&buf, 0,
sizeof(buf));
307 buf.ps_pathptr = exe_path;
308 buf.ps_pathlen =
sizeof(exe_path);
311 if ((token = w_getpsent(token, &buf,
sizeof(buf))) <= 0)
313 if (buf.ps_pid != pid)
320#elif defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
323 int err = dladdr(MainAddr, &DLInfo);
329 char link_path[PATH_MAX];
330 if (realpath(DLInfo.dli_fname, link_path))
333#error GetMainExecutable is not implemented on this host yet.
347 return UniqueID(fs_st_dev, fs_st_ino);
354 if (::STATVFS(
const_cast<char *
>(
Path.str().c_str()), &Vfs))
355 return std::error_code(errno, std::generic_category());
356 auto FrSize = STATVFS_F_FRSIZE(Vfs);
357 space_info SpaceInfo;
358 SpaceInfo.capacity =
static_cast<uint64_t>(Vfs.f_blocks) * FrSize;
359 SpaceInfo.free =
static_cast<uint64_t>(Vfs.f_bfree) * FrSize;
360 SpaceInfo.available =
static_cast<uint64_t>(Vfs.f_bavail) * FrSize;
367 const char *pwd = ::getenv(
"PWD");
373 result.
append(pwd, pwd + strlen(pwd));
374 return std::error_code();
380 if (::getcwd(result.
data(), result.
size()) ==
nullptr) {
382 if (errno != ENOMEM) {
384 return std::error_code(errno, std::generic_category());
393 return std::error_code();
400 if (::chdir(
p.begin()) == -1)
401 return std::error_code(errno, std::generic_category());
403 return std::error_code();
411 if (::mkdir(
p.begin(), Perms) == -1) {
412 if (errno != EEXIST || !IgnoreExisting)
413 return std::error_code(errno, std::generic_category());
416 return std::error_code();
428 if (::symlink(t.
begin(),
f.begin()) == -1)
429 return std::error_code(errno, std::generic_category());
431 return std::error_code();
441 if (::link(t.
begin(),
f.begin()) == -1)
442 return std::error_code(errno, std::generic_category());
444 return std::error_code();
447std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting) {
449 StringRef p = path.toNullTerminatedStringRef(path_storage);
452 if (lstat(
p.begin(), &buf) != 0) {
453 if (errno != ENOENT || !IgnoreNonExisting)
454 return std::error_code(errno, std::generic_category());
455 return std::error_code();
463 if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode))
467 if (errno != ENOENT || !IgnoreNonExisting)
468 return std::error_code(errno, std::generic_category());
471 return std::error_code();
474static bool is_local_impl(
struct STATVFS &Vfs) {
475#if defined(__linux__) || defined(__GNU__)
476#ifndef NFS_SUPER_MAGIC
477#define NFS_SUPER_MAGIC 0x6969
479#ifndef SMB_SUPER_MAGIC
480#define SMB_SUPER_MAGIC 0x517B
482#ifndef CIFS_MAGIC_NUMBER
483#define CIFS_MAGIC_NUMBER 0xFF534D42
490 case NFS_SUPER_MAGIC:
491 case SMB_SUPER_MAGIC:
492 case CIFS_MAGIC_NUMBER:
497#elif defined(__CYGWIN__)
500#elif defined(__Fuchsia__)
503#elif defined(__EMSCRIPTEN__)
506#elif defined(__HAIKU__)
514 return !fstype.equals(
"nfs");
519 size_t BufSize = 2048
u;
520 std::unique_ptr<char[]> Buf;
523 Buf = std::make_unique<char[]>(BufSize);
524 Ret = mntctl(MCTL_QUERY, BufSize, Buf.get());
527 BufSize = *
reinterpret_cast<unsigned int *
>(Buf.get());
536 char *CurObjPtr = Buf.get();
538 struct vmount *Vp =
reinterpret_cast<struct vmount *
>(CurObjPtr);
539 static_assert(
sizeof(Vfs.f_fsid) ==
sizeof(Vp->vmt_fsid),
540 "fsid length mismatch");
541 if (
memcmp(&Vfs.f_fsid, &Vp->vmt_fsid,
sizeof Vfs.f_fsid) == 0)
542 return (Vp->vmt_flags & MNT_REMOTE) == 0;
544 CurObjPtr += Vp->vmt_length;
549#elif defined(__MVS__)
554 return !!(STATVFS_F_FLAG(Vfs) & MNT_LOCAL);
560 if (::STATVFS(
const_cast<char *
>(
Path.str().c_str()), &Vfs))
561 return std::error_code(errno, std::generic_category());
563 Result = is_local_impl(Vfs);
564 return std::error_code();
567std::error_code
is_local(
int FD,
bool &Result) {
569 if (::FSTATVFS(FD, &Vfs))
570 return std::error_code(errno, std::generic_category());
572 Result = is_local_impl(Vfs);
573 return std::error_code();
584 return std::error_code(errno, std::generic_category());
586 return std::error_code();
592 if (::ftruncate(FD,
Size) == -1)
593 return std::error_code(errno, std::generic_category());
595 return std::error_code();
615 return std::error_code(errno, std::generic_category());
620 if (0 != stat(
P.begin(), &buf))
622 if (!S_ISREG(buf.st_mode))
626 return std::error_code();
635 return A.fs_st_dev ==
B.fs_st_dev &&
A.fs_st_ino ==
B.fs_st_ino;
639 file_status fsA, fsB;
640 if (std::error_code ec =
status(
A, fsA))
642 if (std::error_code ec =
status(
B, fsB))
645 return std::error_code();
650 if (PathStr.empty() || !PathStr.startswith(
"~"))
653 PathStr = PathStr.drop_front();
666 Path[0] = Storage[0];
673 std::unique_ptr<char[]> Buf;
674 long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
677 Buf = std::make_unique<char[]>(BufSize);
680 struct passwd *Entry =
nullptr;
681 getpwnam_r(
User.c_str(), &Pwd, Buf.get(), BufSize, &Entry);
683 if (!Entry || !Entry->pw_dir) {
690 Path.append(Entry->pw_dir, Entry->pw_dir + strlen(Entry->pw_dir));
700 expandTildeExpr(dest);
706 else if (S_ISREG(
Mode))
708 else if (S_ISBLK(
Mode))
710 else if (S_ISCHR(
Mode))
712 else if (S_ISFIFO(
Mode))
714 else if (S_ISSOCK(
Mode))
716 else if (S_ISLNK(
Mode))
721static std::error_code fillStatus(
int StatRet,
const struct stat &
Status,
722 file_status &Result) {
724 std::error_code
EC(errno, std::generic_category());
733#if defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
734 atime_nsec =
Status.st_atimespec.tv_nsec;
735 mtime_nsec =
Status.st_mtimespec.tv_nsec;
736#elif defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
737 atime_nsec =
Status.st_atim.tv_nsec;
738 mtime_nsec =
Status.st_mtim.tv_nsec;
740 atime_nsec = mtime_nsec = 0;
749 return std::error_code();
752std::error_code
status(
const Twine &Path, file_status &Result,
bool Follow) {
757 int StatRet = (Follow ? ::stat : ::lstat)(
P.begin(), &
Status);
758 return fillStatus(StatRet,
Status, Result);
761std::error_code
status(
int FD, file_status &Result) {
763 int StatRet = ::fstat(FD, &
Status);
764 return fillStatus(StatRet,
Status, Result);
770 unsigned Mask = ::umask(0);
779 if (::chmod(
P.begin(), Permissions))
780 return std::error_code(errno, std::generic_category());
781 return std::error_code();
785 if (::fchmod(FD, Permissions))
786 return std::error_code(errno, std::generic_category());
787 return std::error_code();
792#if defined(HAVE_FUTIMENS)
796 if (::futimens(FD, Times))
797 return std::error_code(errno, std::generic_category());
798 return std::error_code();
799#elif defined(HAVE_FUTIMES)
802 std::chrono::time_point_cast<std::chrono::microseconds>(AccessTime));
804 sys::toTimeVal(std::chrono::time_point_cast<std::chrono::microseconds>(
806 if (::futimes(FD, Times))
807 return std::error_code(errno, std::generic_category());
808 return std::error_code();
809#elif defined(__MVS__)
811 memset(&Attr, 0,
sizeof(Attr));
812 Attr.att_atimechg = 1;
814 Attr.att_mtimechg = 1;
816 if (::__fchattr(FD, &Attr,
sizeof(Attr)) != 0)
817 return std::error_code(errno, std::generic_category());
818 return std::error_code();
820#warning Missing futimes() and futimens()
830 int prot = (
Mode ==
readonly) ? PROT_READ : (PROT_READ | PROT_WRITE);
831#if defined(MAP_NORESERVE)
832 flags |= MAP_NORESERVE;
834#if defined(__APPLE__)
845#if defined(MAP_RESILIENT_CODESIGN)
846 flags |= MAP_RESILIENT_CODESIGN;
848#if defined(MAP_RESILIENT_MEDIA)
849 flags |= MAP_RESILIENT_MEDIA;
854 Mapping = ::mmap(
nullptr,
Size, prot, flags, FD,
Offset);
855 if (Mapping == MAP_FAILED)
856 return std::error_code(errno, std::generic_category());
857 return std::error_code();
861 uint64_t offset, std::error_code &ec)
866 copyFrom(mapped_file_region());
869void mapped_file_region::unmapImpl() {
871 ::munmap(Mapping,
Size);
874void mapped_file_region::dontNeedImpl() {
878#if defined(__MVS__) || defined(_AIX)
880#elif defined(POSIX_MADV_DONTNEED)
881 ::posix_madvise(Mapping,
Size, POSIX_MADV_DONTNEED);
883 ::madvise(Mapping,
Size, MADV_DONTNEED);
887int mapped_file_region::alignment() {
return Process::getPageSizeEstimate(); }
889std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
891 bool follow_symlinks) {
893 DIR *directory = ::opendir(path_null.c_str());
895 return std::error_code(errno, std::generic_category());
897 it.IterationHandle =
reinterpret_cast<intptr_t
>(directory);
899 path::append(path_null,
".");
900 it.CurrentEntry = directory_entry(path_null.str(), follow_symlinks);
904std::error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
905 if (it.IterationHandle)
906 ::closedir(
reinterpret_cast<DIR *
>(it.IterationHandle));
907 it.IterationHandle = 0;
908 it.CurrentEntry = directory_entry();
909 return std::error_code();
912static file_type direntType(dirent *Entry) {
919 return typeForMode(DTTOIF(Entry->d_type));
922 return file_type::type_unknown;
926std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
928 dirent *CurDir = ::readdir(
reinterpret_cast<DIR *
>(It.IterationHandle));
929 if (CurDir ==
nullptr && errno != 0) {
930 return std::error_code(errno, std::generic_category());
931 }
else if (CurDir !=
nullptr) {
933 if ((
Name.size() == 1 &&
Name[0] ==
'.') ||
936 It.CurrentEntry.replace_filename(
Name, direntType(CurDir));
940 return std::error_code();
945 if (
auto EC = fs::status(Path, s, FollowSymlinks))
954#if !defined(__FreeBSD__)
955#define TRY_PROC_SELF_FD
958#if !defined(F_GETPATH) && defined(TRY_PROC_SELF_FD)
959static bool hasProcSelfFD() {
962 static const bool Result = (::access(
"/proc/self/fd", R_OK) == 0);
967static int nativeOpenFlags(CreationDisposition Disp, OpenFlags
Flags,
970 if (Access == FA_Read)
972 else if (Access == FA_Write)
974 else if (Access == (FA_Read | FA_Write))
979 if (
Flags & OF_Append)
982 if (Disp == CD_CreateNew) {
985 }
else if (Disp == CD_CreateAlways) {
988 }
else if (Disp == CD_OpenAlways) {
990 }
else if (Disp == CD_OpenExisting) {
998 if (
Flags & OF_Append)
1003 if (!(
Flags & OF_ChildInherit))
1011 CreationDisposition Disp, FileAccess Access,
1019 auto Open = [&]() { return ::open(
P.begin(), OpenFlags,
Mode); };
1020 if ((ResultFD = sys::RetryAfterSignal(-1, Open)) < 0)
1021 return std::error_code(errno, std::generic_category());
1023 if (!(
Flags & OF_ChildInherit)) {
1024 int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
1026 assert(r == 0 &&
"fcntl(F_SETFD, FD_CLOEXEC) failed");
1084 if ((
Flags & OF_Append) && lseek(ResultFD, 0, SEEK_END) == -1)
1085 return std::error_code(errno, std::generic_category());
1087 if (fstat(ResultFD, &Stat) == -1)
1088 return std::error_code(errno, std::generic_category());
1089 if (S_ISREG(Stat.st_mode)) {
1090 bool DoSetTag = (Access &
FA_Write) && (Disp != CD_OpenExisting) &&
1091 !Stat.st_tag.ft_txtflag && !Stat.st_tag.ft_ccsid &&
1093 if (
Flags & OF_Text) {
1094 if (
auto EC = llvm::enableAutoConversion(ResultFD))
1097 if (
auto EC = llvm::setFileTag(ResultFD, CCSID_IBM_1047,
true))
1101 if (
auto EC = llvm::disableAutoConversion(ResultFD))
1104 if (
auto EC = llvm::setFileTag(ResultFD, FT_BINARY,
false))
1111 return std::error_code();
1115 FileAccess Access, OpenFlags
Flags,
1128 std::error_code
EC =
1135 return std::error_code();
1137#if defined(F_GETPATH)
1140 char Buffer[PATH_MAX];
1141 if (::fcntl(ResultFD, F_GETPATH, Buffer) != -1)
1142 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1144 char Buffer[PATH_MAX];
1145#if defined(TRY_PROC_SELF_FD)
1146 if (hasProcSelfFD()) {
1148 snprintf(ProcPath,
sizeof(ProcPath),
"/proc/self/fd/%d", ResultFD);
1149 ssize_t CharCount = ::readlink(ProcPath, Buffer,
sizeof(Buffer));
1151 RealPath->
append(Buffer, Buffer + CharCount);
1158 if (::realpath(
P.begin(), Buffer) !=
nullptr)
1159 RealPath->
append(Buffer, Buffer + strlen(Buffer));
1160#if defined(TRY_PROC_SELF_FD)
1164 return std::error_code();
1181#if defined(__APPLE__)
1182 size_t Size = std::min<size_t>(Buf.
size(), INT32_MAX);
1186 ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.
data(),
Size);
1187 if (ssize_t(NumRead) == -1)
1194#if defined(__APPLE__)
1195 size_t Size = std::min<size_t>(Buf.
size(), INT32_MAX);
1201 sys::RetryAfterSignal(-1, ::pread, FD, Buf.
data(),
Size,
Offset);
1203 if (lseek(FD,
Offset, SEEK_SET) == -1)
1205 ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.
data(),
Size);
1212std::error_code
tryLockFile(
int FD, std::chrono::milliseconds Timeout) {
1213 auto Start = std::chrono::steady_clock::now();
1214 auto End = Start + Timeout;
1217 memset(&Lock, 0,
sizeof(Lock));
1218 Lock.l_type = F_WRLCK;
1219 Lock.l_whence = SEEK_SET;
1222 if (::fcntl(FD, F_SETLK, &Lock) != -1)
1223 return std::error_code();
1226 return std::error_code(
Error, std::generic_category());
1228 }
while (std::chrono::steady_clock::now() <
End);
1234 memset(&Lock, 0,
sizeof(Lock));
1235 Lock.l_type = F_WRLCK;
1236 Lock.l_whence = SEEK_SET;
1239 if (::fcntl(FD, F_SETLKW, &Lock) != -1)
1240 return std::error_code();
1242 return std::error_code(
Error, std::generic_category());
1247 Lock.l_type = F_UNLCK;
1248 Lock.l_whence = SEEK_SET;
1251 if (::fcntl(FD, F_SETLK, &Lock) != -1)
1252 return std::error_code();
1253 return std::error_code(errno, std::generic_category());
1259 return Process::SafelyCloseFileDescriptor(TmpF);
1262template <
typename T>
1263static std::error_code remove_directories_impl(
const T &Entry,
1264 bool IgnoreErrors) {
1266 directory_iterator Begin(Entry, EC,
false);
1267 directory_iterator
End;
1268 while (Begin !=
End) {
1269 auto &Item = *Begin;
1273 EC = remove_directories_impl(Item, IgnoreErrors);
1274 if (EC && !IgnoreErrors)
1278 EC = fs::remove(Item.path(),
true);
1279 if (EC && !IgnoreErrors)
1281 }
else if (!IgnoreErrors) {
1285 Begin.increment(EC);
1286 if (EC && !IgnoreErrors)
1289 return std::error_code();
1293 auto EC = remove_directories_impl(path, IgnoreErrors);
1294 if (EC && !IgnoreErrors)
1296 EC = fs::remove(path,
true);
1297 if (EC && !IgnoreErrors)
1299 return std::error_code();
1303 bool expand_tilde) {
1306 return std::error_code();
1311 expandTildeExpr(Storage);
1317 char Buffer[PATH_MAX];
1318 if (::realpath(
P.begin(), Buffer) ==
nullptr)
1319 return std::error_code(errno, std::generic_category());
1320 dest.
append(Buffer, Buffer + strlen(Buffer));
1321 return std::error_code();
1325 auto FChown = [&]() { return ::fchown(FD, Owner, Group); };
1327 if ((sys::RetryAfterSignal(-1, FChown)) < 0)
1328 return std::error_code(errno, std::generic_category());
1329 return std::error_code();
1337 std::unique_ptr<char[]> Buf;
1338 char *RequestedDir = getenv(
"HOME");
1339 if (!RequestedDir) {
1340 long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
1343 Buf = std::make_unique<char[]>(BufSize);
1345 struct passwd *pw =
nullptr;
1346 getpwuid_r(getuid(), &Pwd, Buf.get(), BufSize, &pw);
1347 if (pw && pw->pw_dir)
1348 RequestedDir = pw->pw_dir;
1354 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1359#if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
1362 int ConfName = TempDir ? _CS_DARWIN_USER_TEMP_DIR : _CS_DARWIN_USER_CACHE_DIR;
1363 size_t ConfLen = confstr(ConfName,
nullptr, 0);
1367 ConfLen = confstr(ConfName,
Result.data(),
Result.size());
1368 }
while (ConfLen > 0 && ConfLen !=
Result.size());
1386 append(result,
"Library",
"Preferences");
1392 if (
const char *RequestedDir = getenv(
"XDG_CONFIG_HOME")) {
1394 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1402 append(result,
".config");
1408 if (getDarwinConfDir(
false , result)) {
1414 if (
const char *RequestedDir = getenv(
"XDG_CACHE_HOME")) {
1416 result.
append(RequestedDir, RequestedDir + strlen(RequestedDir));
1423 append(result,
".cache");
1427static const char *getEnvTempDir() {
1430 const char *EnvironmentVariables[] = {
"TMPDIR",
"TMP",
"TEMP",
"TEMPDIR"};
1431 for (
const char *Env : EnvironmentVariables) {
1432 if (
const char *Dir = std::getenv(Env))
1439static const char *getDefaultTempDir(
bool ErasedOnReboot) {
1453 if (ErasedOnReboot) {
1455 if (
const char *RequestedDir = getEnvTempDir()) {
1456 Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
1461 if (getDarwinConfDir(ErasedOnReboot, Result))
1464 const char *RequestedDir = getDefaultTempDir(ErasedOnReboot);
1465 Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
1479 std::string FromS =
From.str();
1480 std::string ToS = To.
str();
1481#if __has_builtin(__builtin_available)
1482 if (__builtin_available(macos 10.12, *)) {
1489 if (!clonefile(FromS.c_str(), ToS.c_str(), 0))
1490 return std::error_code();
1500 return std::error_code(Errno, std::generic_category());
1509 if (!copyfile(FromS.c_str(), ToS.c_str(), NULL, COPYFILE_DATA))
1510 return std::error_code();
1511 return std::error_code(errno, std::generic_category());
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.