#include "Unix.h"
#include <limits.h>
#include <stdio.h>
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#include <dirent.h>
#include <pwd.h>
#include <sys/file.h>
#ifdef __APPLE__
#include <copyfile.h>
#include <mach-o/dyld.h>
#include <sys/attr.h>
#if __has_include(<sys/clonefile.h>)
#include <sys/clonefile.h>
#endif
#elif defined(__FreeBSD__)
#include <osreldate.h>
#if __FreeBSD_version >= 1300057
#include <sys/auxv.h>
#else
#include <machine/elf.h>
extern char **environ;
#endif
#elif defined(__DragonFly__)
#include <sys/mount.h>
#elif defined(__MVS__)
#include "llvm/Support/AutoConvert.h"
#include <sys/ps.h>
#endif
#undef ferror
#undef feof
#if !defined(PATH_MAX)
#if defined(__GNU__)
#define PATH_MAX …
#elif defined(__MVS__)
#define PATH_MAX …
#endif
#endif
#include <sys/types.h>
#if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && \
!defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX)
#include <sys/statvfs.h>
#define STATVFS …
#define FSTATVFS …
#define STATVFS_F_FRSIZE …
#else
#if defined(__OpenBSD__) || defined(__FreeBSD__)
#include <sys/mount.h>
#include <sys/param.h>
#elif defined(__linux__)
#if defined(HAVE_LINUX_MAGIC_H)
#include <linux/magic.h>
#else
#if defined(HAVE_LINUX_NFS_FS_H)
#include <linux/nfs_fs.h>
#endif
#if defined(HAVE_LINUX_SMB_H)
#include <linux/smb.h>
#endif
#endif
#include <sys/vfs.h>
#elif defined(_AIX)
#include <sys/statfs.h>
typedef uint_t uint;
#include <sys/vmount.h>
#else
#include <sys/mount.h>
#endif
#define STATVFS …
#define FSTATVFS …
#define STATVFS_F_FRSIZE(vfs) …
#endif
#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
defined(__MVS__)
#define STATVFS_F_FLAG …
#else
#define STATVFS_F_FLAG(vfs) …
#endif
usingnamespacellvm;
namespace llvm {
namespace sys {
namespace fs {
const file_t kInvalidFile = …;
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
defined(__FreeBSD_kernel__) || defined(__linux__) || defined(__CYGWIN__) || \
defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || \
(defined(__sun__) && defined(__svr4__) || defined(__HAIKU__))
static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { … }
static char *getprogpath(char ret[PATH_MAX], const char *bin) { … }
#endif
std::string getMainExecutable(const char *argv0, void *MainAddr) { … }
TimePoint<> basic_file_status::getLastAccessedTime() const { … }
TimePoint<> basic_file_status::getLastModificationTime() const { … }
UniqueID file_status::getUniqueID() const { … }
uint32_t file_status::getLinkCount() const { … }
ErrorOr<space_info> disk_space(const Twine &Path) { … }
std::error_code current_path(SmallVectorImpl<char> &result) { … }
std::error_code set_current_path(const Twine &path) { … }
std::error_code create_directory(const Twine &path, bool IgnoreExisting,
perms Perms) { … }
std::error_code create_link(const Twine &to, const Twine &from) { … }
std::error_code create_hard_link(const Twine &to, const Twine &from) { … }
std::error_code remove(const Twine &path, bool IgnoreNonExisting) { … }
static bool is_local_impl(struct STATVFS &Vfs) { … }
std::error_code is_local(const Twine &Path, bool &Result) { … }
std::error_code is_local(int FD, bool &Result) { … }
std::error_code rename(const Twine &from, const Twine &to) { … }
std::error_code resize_file(int FD, uint64_t Size) { … }
static int convertAccessMode(AccessMode Mode) { … }
std::error_code access(const Twine &Path, AccessMode Mode) { … }
bool can_execute(const Twine &Path) { … }
bool equivalent(file_status A, file_status B) { … }
std::error_code equivalent(const Twine &A, const Twine &B, bool &result) { … }
static void expandTildeExpr(SmallVectorImpl<char> &Path) { … }
void expand_tilde(const Twine &path, SmallVectorImpl<char> &dest) { … }
static file_type typeForMode(mode_t Mode) { … }
static std::error_code fillStatus(int StatRet, const struct stat &Status,
file_status &Result) { … }
std::error_code status(const Twine &Path, file_status &Result, bool Follow) { … }
std::error_code status(int FD, file_status &Result) { … }
unsigned getUmask() { … }
std::error_code setPermissions(const Twine &Path, perms Permissions) { … }
std::error_code setPermissions(int FD, perms Permissions) { … }
std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
TimePoint<> ModificationTime) { … }
std::error_code mapped_file_region::init(int FD, uint64_t Offset,
mapmode Mode) { … }
mapped_file_region::mapped_file_region(int fd, mapmode mode, size_t length,
uint64_t offset, std::error_code &ec)
: … { … }
void mapped_file_region::unmapImpl() { … }
void mapped_file_region::dontNeedImpl() { … }
int mapped_file_region::alignment() { … }
std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
StringRef path,
bool follow_symlinks) { … }
std::error_code detail::directory_iterator_destruct(detail::DirIterState &it) { … }
static file_type direntType(dirent *Entry) { … }
std::error_code detail::directory_iterator_increment(detail::DirIterState &It) { … }
ErrorOr<basic_file_status> directory_entry::status() const { … }
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
#define TRY_PROC_SELF_FD
#endif
#if !defined(F_GETPATH) && defined(TRY_PROC_SELF_FD)
static bool hasProcSelfFD() { … }
#endif
static int nativeOpenFlags(CreationDisposition Disp, OpenFlags Flags,
FileAccess Access) { … }
std::error_code openFile(const Twine &Name, int &ResultFD,
CreationDisposition Disp, FileAccess Access,
OpenFlags Flags, unsigned Mode) { … }
Expected<int> openNativeFile(const Twine &Name, CreationDisposition Disp,
FileAccess Access, OpenFlags Flags,
unsigned Mode) { … }
std::error_code openFileForRead(const Twine &Name, int &ResultFD,
OpenFlags Flags,
SmallVectorImpl<char> *RealPath) { … }
Expected<file_t> openNativeFileForRead(const Twine &Name, OpenFlags Flags,
SmallVectorImpl<char> *RealPath) { … }
file_t getStdinHandle() { … }
file_t getStdoutHandle() { … }
file_t getStderrHandle() { … }
Expected<size_t> readNativeFile(file_t FD, MutableArrayRef<char> Buf) { … }
Expected<size_t> readNativeFileSlice(file_t FD, MutableArrayRef<char> Buf,
uint64_t Offset) { … }
std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout) { … }
std::error_code lockFile(int FD) { … }
std::error_code unlockFile(int FD) { … }
std::error_code closeFile(file_t &F) { … }
template <typename T>
static std::error_code remove_directories_impl(const T &Entry,
bool IgnoreErrors) { … }
std::error_code remove_directories(const Twine &path, bool IgnoreErrors) { … }
std::error_code real_path(const Twine &path, SmallVectorImpl<char> &dest,
bool expand_tilde) { … }
std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group) { … }
}
namespace path {
bool home_directory(SmallVectorImpl<char> &result) { … }
static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) { … }
bool user_config_directory(SmallVectorImpl<char> &result) { … }
bool cache_directory(SmallVectorImpl<char> &result) { … }
static const char *getEnvTempDir() { … }
static const char *getDefaultTempDir(bool ErasedOnReboot) { … }
void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl<char> &Result) { … }
}
namespace fs {
#ifdef __APPLE__
std::error_code copy_file(const Twine &From, const Twine &To) {
std::string FromS = From.str();
std::string ToS = To.str();
#if __has_builtin(__builtin_available)
if (__builtin_available(macos 10.12, *)) {
if (!clonefile(FromS.c_str(), ToS.c_str(), 0))
return std::error_code();
auto Errno = errno;
switch (Errno) {
case EEXIST:
case ENOTSUP:
case EXDEV:
break;
default:
return std::error_code(Errno, std::generic_category());
}
}
#endif
if (!copyfile(FromS.c_str(), ToS.c_str(), NULL, COPYFILE_DATA))
return std::error_code();
return errnoAsErrorCode();
}
#endif
}
}
}