27 #ifndef LLVM_SUPPORT_FILESYSTEM_H
28 #define LLVM_SUPPORT_FILESYSTEM_H
42 #include <system_error>
46 #ifdef HAVE_SYS_STAT_H
101 return static_cast<perms>(
static_cast<unsigned short>(l) |
102 static_cast<unsigned short>(r));
105 return static_cast<perms>(
static_cast<unsigned short>(l) &
106 static_cast<unsigned short>(r));
117 return static_cast<perms>(~static_cast<
unsigned short>(x));
126 UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
129 return Device == Other.Device && File == Other.File;
133 return std::tie(Device, File) < std::tie(Other.Device, Other.File);
144 #if defined(LLVM_ON_UNIX)
152 #elif defined (LLVM_ON_WIN32)
168 #if defined(LLVM_ON_UNIX)
170 : fs_st_dev(0), fs_st_ino(0), fs_st_atime(0), fs_st_mtime(0),
171 fs_st_uid(0), fs_st_gid(0), fs_st_size(0),
175 : fs_st_dev(0), fs_st_ino(0), fs_st_atime(0), fs_st_mtime(0),
176 fs_st_uid(0), fs_st_gid(0), fs_st_size(0), Type(Type),
180 time_t MTime, uid_t UID, gid_t GID, off_t Size)
181 : fs_st_dev(Dev), fs_st_ino(Ino), fs_st_atime(ATime), fs_st_mtime(MTime),
182 fs_st_uid(UID), fs_st_gid(GID), fs_st_size(Size), Type(Type),
184 #elif defined(LLVM_ON_WIN32)
186 : LastAccessedTimeHigh(0), LastAccessedTimeLow(0), LastWriteTimeHigh(0),
187 LastWriteTimeLow(0), VolumeSerialNumber(0), FileSizeHigh(0),
188 FileSizeLow(0), FileIndexHigh(0), FileIndexLow(0),
192 : LastAccessedTimeHigh(0), LastAccessedTimeLow(0), LastWriteTimeHigh(0),
193 LastWriteTimeLow(0), VolumeSerialNumber(0), FileSizeHigh(0),
194 FileSizeLow(0), FileIndexHigh(0), FileIndexLow(0), Type(Type),
202 : LastAccessedTimeHigh(LastAccessTimeHigh), LastAccessedTimeLow(LastAccessTimeLow),
203 LastWriteTimeHigh(LastWriteTimeHigh),
204 LastWriteTimeLow(LastWriteTimeLow),
205 VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
206 FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
217 #if defined(LLVM_ON_UNIX)
218 uint32_t getUser()
const {
return fs_st_uid; }
219 uint32_t getGroup()
const {
return fs_st_gid; }
220 uint64_t getSize()
const {
return fs_st_size; }
221 #elif defined (LLVM_ON_WIN32)
228 uint64_t getSize()
const {
229 return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
276 operator Impl()
const {
return V; }
320 bool IgnoreExisting =
true,
366 std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting =
true);
386 std::error_code
resize_file(
int FD, uint64_t Size);
439 bool equivalent(file_status A, file_status B);
529 std::error_code
status(
const Twine &path, file_status &result);
532 std::error_code
status(
int FD, file_status &Result);
542 std::error_code EC =
status(Path, Status);
545 Result = Status.getSize();
546 return std::error_code();
645 return OpenFlags(
unsigned(A) |
unsigned(B));
709 std::error_code &ec);
713 uint64_t
size()
const;
754 const std::string &
path()
const {
return Path; }
787 std::shared_ptr<detail::DirIterState> State;
791 State = std::make_shared<detail::DirIterState>();
798 State = std::make_shared<detail::DirIterState>();
815 if (State == RHS.State)
821 return State->CurrentEntry == RHS.State->CurrentEntry;
825 return !(*
this == RHS);
834 std::stack<directory_iterator, std::vector<directory_iterator>>
Stack;
843 std::shared_ptr<detail::RecDirIterState> State;
848 : State(std::make_shared<detail::RecDirIterState>()) {
858 if (State->HasNoPushRequest)
859 State->HasNoPushRequest =
false;
862 if ((ec = State->Stack.top()->status(st)))
return *
this;
865 if (ec)
return *
this;
866 if (State->Stack.top() != end_itr) {
874 while (!State->Stack.empty()
875 && State->Stack.top().increment(ec) == end_itr) {
881 if (State->Stack.empty())
892 int level()
const {
return State->Level; }
900 assert(State &&
"Cannot pop an end iterator!");
901 assert(State->Level > 0 &&
"Cannot pop an iterator with level < 1");
910 }
while (!State->Stack.empty()
911 && State->Stack.top().increment(ec) == end_itr);
914 if (State->Stack.empty())
919 void no_push() { State->HasNoPushRequest =
true; }
922 return State == RHS.State;
926 return !(*
this == RHS);
938 #endif // LLVM_SUPPORT_FILESYSTEM_H
recursive_directory_iterator(const Twine &path, std::error_code &ec)
recursive_directory_iterator()=default
std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
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
Represents either an error or a value T.
space_info - Self explanatory.
bool operator<=(const directory_entry &rhs) const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
std::error_code openFileForRead(const Twine &Name, int &ResultFD, SmallVectorImpl< char > *RealPath=nullptr)
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
mapped_file_region & operator=(mapped_file_region &)=delete
bool operator<(const UniqueID &Other) const
This class represents a memory mapped file.
std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time)
Set the file modification and access time.
opt Optimize addressing mode
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
ELF Relocatable object file.
directory_iterator & increment(std::error_code &ec)
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.
bool status_known(file_status s)
Is status available?
mapped_file_region()=delete
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.
struct fuzzer::@269 Flags
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
directory_entry(const Twine &path, file_status st=file_status())
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.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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.
Microsoft cl.exe's intermediate code file.
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?
TimePoint getLastAccessedTime() const
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?
std::error_code getPathFromOpenFD(int FD, SmallVectorImpl< char > &ResultPath)
Fetch a path to an open file, as specified by a file descriptor.
std::error_code make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
const directory_entry & operator*() const
perms permissions() const
const std::string & path() const
perms operator|(perms l, perms r)
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.
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.
bool operator!=(const recursive_directory_iterator &RHS) const
bool operator>(const directory_entry &rhs) const
ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
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 createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath)
Create a file in the system temporary directory.
Mach-O dSYM companion file.
TimePoint getLastModificationTime() const
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
The Mach-O dynamic linker.
int level() const
Gets the current level. Starting path is at level 0.
bool operator==(const UniqueID &Other) const
Provides ErrorOr<T> smart pointer.
bool operator==(const directory_iterator &RHS) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
directory_entry()=default
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?
directory_iterator()=default
Construct end iterator.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags, unsigned Mode=0666)