27 #ifndef LLVM_SUPPORT_FILESYSTEM_H
28 #define LLVM_SUPPORT_FILESYSTEM_H
34 #include "llvm/Support/DataTypes.h"
44 #ifdef HAVE_SYS_STAT_H
70 operator int()
const {
return v_;}
109 return static_cast<perms>(
110 static_cast<unsigned short>(l) | static_cast<unsigned short>(r));
113 return static_cast<perms>(
114 static_cast<unsigned short>(l) & static_cast<unsigned short>(r));
125 return static_cast<perms>(~static_cast<
unsigned short>(x));
134 UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
136 return Device == Other.Device && File == Other.File;
140 return Device < Other.Device ||
141 (Device == Other.Device && File < Other.File);
151 #if defined(LLVM_ON_UNIX)
158 #elif defined (LLVM_ON_WIN32)
159 uint32_t LastWriteTimeHigh;
160 uint32_t LastWriteTimeLow;
161 uint32_t VolumeSerialNumber;
162 uint32_t FileSizeHigh;
163 uint32_t FileSizeLow;
164 uint32_t FileIndexHigh;
165 uint32_t FileIndexLow;
174 #if defined(LLVM_ON_UNIX)
176 uid_t UID, gid_t GID, off_t Size)
177 : fs_st_dev(Dev), fs_st_ino(Ino), fs_st_mtime(MTime), fs_st_uid(UID),
178 fs_st_gid(GID), fs_st_size(Size), Type(Type), Perms(Perms) {}
179 #elif defined(LLVM_ON_WIN32)
181 uint32_t LastWriteTimeLow, uint32_t VolumeSerialNumber,
182 uint32_t FileSizeHigh, uint32_t FileSizeLow,
183 uint32_t FileIndexHigh, uint32_t FileIndexLow)
184 : LastWriteTimeHigh(LastWriteTimeHigh),
185 LastWriteTimeLow(LastWriteTimeLow),
186 VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
187 FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
197 #if defined(LLVM_ON_UNIX)
198 uint32_t getUser()
const {
return fs_st_uid; }
199 uint32_t getGroup()
const {
return fs_st_gid; }
200 uint64_t getSize()
const {
return fs_st_size; }
201 #elif defined (LLVM_ON_WIN32)
202 uint32_t getUser()
const {
205 uint32_t getGroup()
const {
208 uint64_t getSize()
const {
209 return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
247 return V ==
unknown ?
false :
true;
252 operator Impl()
const {
return V; }
341 return remove(Path, Existed);
398 return !
exists(path, result) && result;
422 bool equivalent(file_status A, file_status B);
544 Result = Status.getSize();
630 return OpenFlags(
unsigned(A) |
unsigned(B));
639 unsigned Mode = 0666);
699 void *FileMappingHandle;
702 error_code init(
int FD,
bool CloseFD, uint64_t Offset);
707 #if LLVM_HAS_RVALUE_REFERENCES
745 uint64_t
size()
const;
769 bool map_writable,
void *&result);
810 const std::string &
path()
const {
return Path; }
875 if (State == RHS.State)
881 return State->CurrentEntry == RHS.State->CurrentEntry;
885 return !(*
this == RHS);
899 std::stack<directory_iterator, std::vector<directory_iterator> >
Stack;
913 : State(new detail::RecDirIterState) {
922 if (State->HasNoPushRequest)
923 State->HasNoPushRequest =
false;
926 if ((ec = State->Stack.top()->status(st)))
return *
this;
929 if (ec)
return *
this;
930 if (State->Stack.top() != end_itr) {
938 while (!State->Stack.empty()
939 && State->Stack.top().increment(ec) == end_itr) {
945 if (State->Stack.empty())
956 int level()
const {
return State->Level; }
964 assert(State &&
"Cannot pop an end iterator!");
965 assert(State->Level > 0 &&
"Cannot pop an iterator with level < 1");
974 }
while (!State->Stack.empty()
975 && State->Stack.top().increment(ec) == end_itr);
978 if (State->Stack.empty())
983 void no_push() { State->HasNoPushRequest =
true; }
986 return State == RHS.State;
990 return !(*
this == RHS);
bool can_execute(const Twine &Path)
Can we execute this file?
const directory_entry * operator->() const
space_info - Self explanatory.
bool operator<=(const directory_entry &rhs) const
error_code directory_iterator_construct(DirIterState &, StringRef)
error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags, unsigned Mode=0666)
error_code resize_file(const Twine &path, uint64_t size)
Resize path to size. File is resized as if by POSIX truncate().
error_code status(file_status &result) const
Mach-O dynlinked shared lib.
bool operator==(const recursive_directory_iterator &RHS) const
bool operator!=(const UniqueID &Other) const
recursive_directory_iterator(const Twine &path, error_code &ec)
error_code setLastModificationAndAccessTime(int FD, TimeValue Time)
void replace_filename(const Twine &filename, file_status st=file_status())
void pop()
Goes up one level if Level > 0.
UniqueID getUniqueID() const
bool operator<(const UniqueID &Other) const
error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
error_code unmap_file_pages(void *base, size_t size)
Memory unmaps the contents of a file.
error_code openFileForRead(const Twine &Name, int &ResultFD)
ELF Relocatable object file.
bool operator!=(const directory_iterator &RHS) const
const char * const_data() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
bool status_known(file_status s)
Is status available?
void permissions(perms p)
error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
bool operator>=(const directory_entry &rhs) const
std::string str() const
str - Return the twine contents as a std::string.
bool operator==(const directory_entry &rhs) const
perms operator&(perms l, perms r)
error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
bool operator!=(const directory_entry &rhs) const
May access map via data and modify it. Written to path.
bool no_push_request() const
Returns true if no_push has been called for this directory_entry.
error_code directory_iterator_destruct(DirIterState &)
error_code map_file_pages(const Twine &path, off_t file_offset, size_t size, bool map_writable, void *&result)
Memory maps the contents of a file.
bool can_write(const Twine &Path)
Can we write this file?
directory_entry CurrentEntry
const directory_entry * operator->() const
ELF dynamically linked shared lib.
error_code directory_iterator_increment(DirIterState &)
May only access map via const_data as read only.
directory_entry(const Twine &path, file_status st=file_status())
error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to.
Windows compiled resource file (.rc)
error_code getUniqueID(const Twine Path, UniqueID &Result)
std::stack< directory_iterator, std::vector< directory_iterator > > Stack
recursive_directory_iterator & increment(error_code &ec)
std::string getMainExecutable(const char *argv0, void *MainExecAddr)
UniqueID(uint64_t Device, uint64_t File)
error_code status(const Twine &path, file_status &result)
Get file status as if by POSIX stat().
directory_iterator(const Twine &path, error_code &ec)
bool operator<(const directory_entry &rhs) const
void no_push()
Does not go down into the current directory_entry.
file_status(file_type Type)
void assign(const Twine &path, file_status st=file_status())
Mach-O Preloaded Executable.
bool is_other(file_status status)
Does this status represent something that exists but is not a directory, regular file, or symlink?
error_code make_absolute(SmallVectorImpl< char > &path)
Make path an absolute path.
error_code remove_all(const Twine &path, uint32_t &num_removed)
Recursively remove all files below path, then path. Files are removed as if by POSIX remove()...
const directory_entry & operator*() const
friend bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
directory_iterator & increment(error_code &ec)
directory_iterator(const directory_entry &de, error_code &ec)
const directory_entry & operator*() const
perms permissions() const
bool is_symlink(file_status status)
Does status represent a symlink?
const std::string & path() const
perms operator|(perms l, perms r)
error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath)
Create a file in the system temporary directory.
bool is_directory(file_status status)
Does status represent a directory?
error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
recursive_directory_iterator()
StringRef toStringRef(SmallVectorImpl< char > &Out) const
error_code create_directories(const Twine &path, bool &existed)
Create all the non-existent directories in path.
#define LLVM_DELETED_FUNCTION
error_code has_magic(const Twine &path, const Twine &magic, bool &result)
Are path's first bytes magic?
uint64_t getDevice() const
bool is_regular_file(file_status status)
Does status represent a regular file?
May modify via data, but changes are lost on destruction.
directory_iterator()
Construct end iterator.
bool operator!=(const recursive_directory_iterator &RHS) const
bool operator>(const directory_entry &rhs) const
error_code create_directory(const Twine &path, bool &existed)
Create the directory in path.
error_code create_symlink(const Twine &to, const Twine &from)
Create a symbolic link from from to to.
static error_code success()
Mach-O dSYM companion file.
The Mach-O dynamic linker.
int level() const
Gets the current level. Starting path is at level 0.
bool operator==(const UniqueID &Other) const
bool operator==(const directory_iterator &RHS) const
perms & operator&=(perms &l, perms r)
bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
perms & operator|=(perms &l, perms r)
Provides an abstraction for a fixed point in time.
TimeValue getLastModificationTime() const
error_code rename(const Twine &from, const Twine &to)
Rename from to to. Files are renamed as if by POSIX rename().
const StringRef filename(StringRef path)
Get filename.
bool exists(file_status status)
Does file exist?
error_code get_magic(const Twine &path, uint32_t len, SmallVectorImpl< char > &result)
Get path's first len bytes.