27 #ifndef LLVM_SUPPORT_FILESYSTEM_H
28 #define LLVM_SUPPORT_FILESYSTEM_H
33 #include "llvm/Support/DataTypes.h"
40 #include <system_error>
44 #ifdef HAVE_SYS_STAT_H
99 return static_cast<perms>(
100 static_cast<unsigned short>(l) | static_cast<unsigned short>(r));
103 return static_cast<perms>(
104 static_cast<unsigned short>(l) & static_cast<unsigned short>(r));
115 return static_cast<perms>(~static_cast<
unsigned short>(x));
124 UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
126 return Device == Other.Device && File == Other.File;
130 return std::tie(Device, File) < std::tie(Other.Device, Other.File);
140 #if defined(LLVM_ON_UNIX)
147 #elif defined (LLVM_ON_WIN32)
148 uint32_t LastWriteTimeHigh;
149 uint32_t LastWriteTimeLow;
150 uint32_t VolumeSerialNumber;
151 uint32_t FileSizeHigh;
152 uint32_t FileSizeLow;
153 uint32_t FileIndexHigh;
154 uint32_t FileIndexLow;
160 #if defined(LLVM_ON_UNIX)
161 file_status() : fs_st_dev(0), fs_st_ino(0), fs_st_mtime(0),
162 fs_st_uid(0), fs_st_gid(0), fs_st_size(0),
166 fs_st_uid(0), fs_st_gid(0), fs_st_size(0), Type(Type),
170 uid_t UID, gid_t GID, off_t Size)
171 : fs_st_dev(Dev), fs_st_ino(Ino), fs_st_mtime(MTime), fs_st_uid(UID),
172 fs_st_gid(GID), fs_st_size(Size), Type(Type), Perms(Perms) {}
173 #elif defined(LLVM_ON_WIN32)
174 file_status() : LastWriteTimeHigh(0), LastWriteTimeLow(0),
175 VolumeSerialNumber(0), FileSizeHigh(0), FileSizeLow(0),
180 VolumeSerialNumber(0), FileSizeHigh(0), FileSizeLow(0),
181 FileIndexHigh(0), FileIndexLow(0), Type(Type),
185 uint32_t LastWriteTimeLow, uint32_t VolumeSerialNumber,
186 uint32_t FileSizeHigh, uint32_t FileSizeLow,
187 uint32_t FileIndexHigh, uint32_t FileIndexLow)
188 : LastWriteTimeHigh(LastWriteTimeHigh),
189 LastWriteTimeLow(LastWriteTimeLow),
190 VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
191 FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
201 #if defined(LLVM_ON_UNIX)
202 uint32_t getUser()
const {
return fs_st_uid; }
203 uint32_t getGroup()
const {
return fs_st_gid; }
204 uint64_t getSize()
const {
return fs_st_size; }
205 #elif defined (LLVM_ON_WIN32)
206 uint32_t getUser()
const {
209 uint32_t getGroup()
const {
212 uint64_t getSize()
const {
213 return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
253 return V ==
unknown ?
false :
true;
258 operator Impl()
const {
return V; }
288 bool IgnoreExisting =
true);
324 std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting =
true);
344 std::error_code
resize_file(
int FD, uint64_t Size);
399 bool equivalent(file_status A, file_status B);
489 std::error_code
status(
const Twine &path, file_status &result);
492 std::error_code
status(
int FD, file_status &Result);
502 std::error_code EC =
status(Path, Status);
505 Result = Status.getSize();
506 return std::error_code();
599 return OpenFlags(
unsigned(A) |
unsigned(B));
644 std::error_code init(
int FD, uint64_t Offset,
mapmode Mode);
651 std::error_code &ec);
655 uint64_t
size()
const;
696 const std::string &
path()
const {
return Path; }
761 if (State == RHS.State)
767 return State->CurrentEntry == RHS.State->CurrentEntry;
771 return !(*
this == RHS);
785 std::stack<directory_iterator, std::vector<directory_iterator> >
Stack;
799 : State(new detail::RecDirIterState) {
808 if (State->HasNoPushRequest)
809 State->HasNoPushRequest =
false;
812 if ((ec = State->Stack.top()->status(st)))
return *
this;
815 if (ec)
return *
this;
816 if (State->Stack.top() != end_itr) {
824 while (!State->Stack.empty()
825 && State->Stack.top().increment(ec) == end_itr) {
831 if (State->Stack.empty())
842 int level()
const {
return State->Level; }
850 assert(State &&
"Cannot pop an end iterator!");
851 assert(State->Level > 0 &&
"Cannot pop an iterator with level < 1");
860 }
while (!State->Stack.empty()
861 && State->Stack.top().increment(ec) == end_itr);
864 if (State->Stack.empty())
869 void no_push() { State->HasNoPushRequest =
true; }
872 return State == RHS.State;
876 return !(*
this == RHS);
recursive_directory_iterator(const Twine &path, std::error_code &ec)
F_Append - When opening a file, if it already exists append to the existing file instead of returning...
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
std::error_code create_directories(const Twine &path, bool IgnoreExisting=true)
Create all the non-existent directories in path.
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
Mach-O dynlinked shared lib.
F_Excl - When opening a file, this flag makes raw_fd_ostream report an error if the file already exis...
bool operator==(const recursive_directory_iterator &RHS) const
bool operator!=(const UniqueID &Other) const
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
This class represents a memory mapped file.
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
ELF Relocatable object file.
directory_iterator & increment(std::error_code &ec)
std::error_code make_absolute(SmallVectorImpl< char > &path)
Make path an absolute path.
recursive_directory_iterator - Same as directory_iterator except for it recurses down into child dire...
bool operator!=(const directory_iterator &RHS) const
const char * const_data() const
Get a const view of the data.
file_status - Represents the result of a call to stat and friends.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
bool status_known(file_status s)
Is status available?
std::error_code directory_iterator_increment(DirIterState &)
void permissions(perms p)
bool operator>=(const directory_entry &rhs) const
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
DirIterState - Keeps state for the directory_iterator.
directory_iterator(const Twine &path, std::error_code &ec)
bool operator==(const directory_entry &rhs) const
perms operator&(perms l, perms r)
bool operator!=(const directory_entry &rhs) const
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
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.
bool can_write(const Twine &Path)
Can we write this file?
directory_entry CurrentEntry
const directory_entry * operator->() const
ELF dynamically linked shared lib.
May only access map via const_data as read only.
RefCountedBase - A generic base class for objects that wish to have their lifetimes managed using ref...
directory_entry(const Twine &path, file_status st=file_status())
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true)
Create the directory in path.
Windows compiled resource file (.rc)
std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
Open the file for read and write.
std::stack< directory_iterator, std::vector< directory_iterator > > Stack
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 copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
StringRef filename(StringRef path)
Get filename.
UniqueID(uint64_t Device, uint64_t File)
bool operator<(const directory_entry &rhs) const
The instances of the Type class are immutable: once they are created, they are never changed...
void no_push()
Does not go down into the current directory_entry.
void assign(const Twine &path, file_status st=file_status())
recursive_directory_iterator & increment(std::error_code &ec)
Mach-O Preloaded Executable.
std::error_code directory_iterator_construct(DirIterState &, StringRef)
bool is_other(file_status status)
Does this status represent something that exists but is not a directory, regular file, or symlink?
std::error_code getUniqueID(const Twine Path, UniqueID &Result)
std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
const directory_entry & operator*() const
friend bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
const directory_entry & operator*() const
perms permissions() const
const std::string & path() const
perms operator|(perms l, perms r)
std::error_code setLastModificationAndAccessTime(int FD, TimeValue Time)
Set the file modification and access time.
bool is_directory(file_status status)
Does status represent a directory?
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
recursive_directory_iterator()
RecDirIterState - Keeps state for the recursive_directory_iterator.
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
std::error_code status(file_status &result) const
uint64_t getDevice() const
bool is_regular_file(file_status status)
Does status represent a regular file?
The file should be opened in text mode on platforms that make this distinction.
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
directory_iterator(const directory_entry &de, std::error_code &ec)
std::error_code directory_iterator_destruct(DirIterState &)
directory_iterator - Iterates through the entries in path.
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
file_type
An enumeration for the file system's view of the type.
std::error_code openFileForRead(const Twine &Name, int &ResultFD)
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath)
Create a file in the system temporary directory.
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)
This class is used where a precise fixed point in time is required.
TimeValue getLastModificationTime() const
directory_entry - A single entry in a directory.
std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
StringRef - Represent a constant reference to a string, i.e.
std::error_code status(const Twine &path, file_status &result)
Get file status as if by POSIX stat().
bool exists(file_status status)
Does file exist?
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags, unsigned Mode=0666)