LLVM 19.0.0git
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
FileSystem.h File Reference
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem/UniqueID.h"
#include "llvm/Support/MD5.h"
#include <cassert>
#include <cstdint>
#include <ctime>
#include <memory>
#include <stack>
#include <string>
#include <system_error>
#include <vector>

Go to the source code of this file.

Classes

struct  llvm::sys::fs::space_info
 space_info - Self explanatory. More...
 
class  llvm::sys::fs::basic_file_status
 Represents the result of a call to directory_iterator::status(). More...
 
class  llvm::sys::fs::file_status
 Represents the result of a call to sys::fs::status(). More...
 
class  llvm::sys::fs::TempFile
 Represents a temporary file. More...
 
class  llvm::sys::fs::FileLocker
 RAII class that facilitates file locking. More...
 
class  llvm::sys::fs::mapped_file_region
 This class represents a memory mapped file. More...
 
class  llvm::sys::fs::directory_entry
 directory_entry - A single entry in a directory. More...
 
struct  llvm::sys::fs::detail::DirIterState
 Keeps state for the directory_iterator. More...
 
class  llvm::sys::fs::directory_iterator
 directory_iterator - Iterates through the entries in path. More...
 
struct  llvm::sys::fs::detail::RecDirIterState
 Keeps state for the recursive_directory_iterator. More...
 
class  llvm::sys::fs::recursive_directory_iterator
 recursive_directory_iterator - Same as directory_iterator except for it recurses down into child directories. More...
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 
namespace  llvm::sys
 
namespace  llvm::sys::fs
 
namespace  llvm::sys::fs::detail
 

Typedefs

using llvm::sys::fs::file_t = int
 

Enumerations

enum class  llvm::sys::fs::file_type {
  llvm::sys::fs::status_error , llvm::sys::fs::file_not_found , llvm::sys::fs::regular_file , llvm::sys::fs::directory_file ,
  llvm::sys::fs::symlink_file , llvm::sys::fs::block_file , llvm::sys::fs::character_file , llvm::sys::fs::fifo_file ,
  llvm::sys::fs::socket_file , llvm::sys::fs::type_unknown
}
 An enumeration for the file system's view of the type. More...
 
enum  llvm::sys::fs::perms {
  llvm::sys::fs::no_perms = 0 , llvm::sys::fs::owner_read = 0400 , llvm::sys::fs::owner_write = 0200 , llvm::sys::fs::owner_exe = 0100 ,
  llvm::sys::fs::owner_all = owner_read | owner_write | owner_exe , llvm::sys::fs::group_read = 040 , llvm::sys::fs::group_write = 020 , llvm::sys::fs::group_exe = 010 ,
  llvm::sys::fs::group_all = group_read | group_write | group_exe , llvm::sys::fs::others_read = 04 , llvm::sys::fs::others_write = 02 , llvm::sys::fs::others_exe = 01 ,
  llvm::sys::fs::others_all = others_read | others_write | others_exe , llvm::sys::fs::all_read = owner_read | group_read | others_read , llvm::sys::fs::all_write = owner_write | group_write | others_write , llvm::sys::fs::all_exe = owner_exe | group_exe | others_exe ,
  llvm::sys::fs::all_all = owner_all | group_all | others_all , llvm::sys::fs::set_uid_on_exe = 04000 , llvm::sys::fs::set_gid_on_exe = 02000 , llvm::sys::fs::sticky_bit = 01000 ,
  llvm::sys::fs::all_perms = all_all | set_uid_on_exe | set_gid_on_exe | sticky_bit , llvm::sys::fs::perms_not_known = 0xFFFF
}
 

Functions

perms llvm::sys::fs::operator| (perms l, perms r)
 
perms llvm::sys::fs::operator& (perms l, perms r)
 
perms & llvm::sys::fs::operator|= (perms &l, perms r)
 
perms & llvm::sys::fs::operator&= (perms &l, perms r)
 
perms llvm::sys::fs::operator~ (perms x)
 
std::error_code llvm::sys::fs::detail::directory_iterator_construct (DirIterState &, StringRef, bool)
 
std::error_code llvm::sys::fs::detail::directory_iterator_increment (DirIterState &)
 
std::error_code llvm::sys::fs::detail::directory_iterator_destruct (DirIterState &)
 
Physical Operators
void llvm::sys::fs::make_absolute (const Twine &current_directory, SmallVectorImpl< char > &path)
 Make path an absolute path.
 
std::error_code llvm::sys::fs::make_absolute (SmallVectorImpl< char > &path)
 Make path an absolute path.
 
std::error_code llvm::sys::fs::create_directories (const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
 Create all the non-existent directories in path.
 
std::error_code llvm::sys::fs::create_directory (const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
 Create the directory in path.
 
std::error_code llvm::sys::fs::create_link (const Twine &to, const Twine &from)
 Create a link from from to to.
 
std::error_code llvm::sys::fs::create_hard_link (const Twine &to, const Twine &from)
 Create a hard link from from to to, or return an error.
 
std::error_code llvm::sys::fs::real_path (const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
 Collapse all .
 
void llvm::sys::fs::expand_tilde (const Twine &path, SmallVectorImpl< char > &output)
 Expands ~ expressions to the user's home directory.
 
std::error_code llvm::sys::fs::current_path (SmallVectorImpl< char > &result)
 Get the current path.
 
std::error_code llvm::sys::fs::set_current_path (const Twine &path)
 Set the current path.
 
std::error_code llvm::sys::fs::remove (const Twine &path, bool IgnoreNonExisting=true)
 Remove path.
 
std::error_code llvm::sys::fs::remove_directories (const Twine &path, bool IgnoreErrors=true)
 Recursively delete a directory.
 
std::error_code llvm::sys::fs::rename (const Twine &from, const Twine &to)
 Rename from to to.
 
std::error_code llvm::sys::fs::copy_file (const Twine &From, const Twine &To)
 Copy the contents of From to To.
 
std::error_code llvm::sys::fs::copy_file (const Twine &From, int ToFD)
 Copy the contents of From to To.
 
std::error_code llvm::sys::fs::resize_file (int FD, uint64_t Size)
 Resize path to size.
 
std::error_code llvm::sys::fs::resize_file_before_mapping_readwrite (int FD, uint64_t Size)
 Resize FD to Size before mapping mapped_file_region::readwrite.
 
ErrorOr< MD5::MD5Resultllvm::sys::fs::md5_contents (int FD)
 Compute an MD5 hash of a file's contents.
 
ErrorOr< MD5::MD5Resultllvm::sys::fs::md5_contents (const Twine &Path)
 Version of compute_md5 that doesn't require an open file descriptor.
 

Variables

const file_t llvm::sys::fs::kInvalidFile
 

Physical Observers

enum class  llvm::sys::fs::AccessMode { llvm::sys::fs::Exist , llvm::sys::fs::Write , llvm::sys::fs::Execute }
 
enum  llvm::sys::fs::CreationDisposition : unsigned { llvm::sys::fs::CD_CreateAlways = 0 , llvm::sys::fs::CD_CreateNew = 1 , llvm::sys::fs::CD_OpenExisting = 2 , llvm::sys::fs::CD_OpenAlways = 3 }
 
enum  llvm::sys::fs::FileAccess : unsigned { llvm::sys::fs::FA_Read = 1 , llvm::sys::fs::FA_Write = 2 }
 
enum  llvm::sys::fs::OpenFlags : unsigned {
  llvm::sys::fs::OF_None = 0 , llvm::sys::fs::OF_Text = 1 , llvm::sys::fs::OF_CRLF = 2 , llvm::sys::fs::OF_TextWithCRLF = OF_Text | OF_CRLF ,
  llvm::sys::fs::OF_Append = 4 , llvm::sys::fs::OF_Delete = 8 , llvm::sys::fs::OF_ChildInherit = 16 , llvm::sys::fs::OF_UpdateAtime = 32
}
 
enum  : size_t { llvm::sys::fs::DefaultReadChunkSize = 4 * 4096 }
 Default chunk size for readNativeFileToEOF(). More...
 
bool llvm::sys::fs::exists (const basic_file_status &status)
 Does file exist?
 
std::error_code llvm::sys::fs::access (const Twine &Path, AccessMode Mode)
 Can the file be accessed?
 
bool llvm::sys::fs::exists (const Twine &Path)
 Does file exist?
 
bool llvm::sys::fs::can_execute (const Twine &Path)
 Can we execute this file?
 
bool llvm::sys::fs::can_write (const Twine &Path)
 Can we write this file?
 
bool llvm::sys::fs::equivalent (file_status A, file_status B)
 Do file_status's represent the same thing?
 
std::error_code llvm::sys::fs::equivalent (const Twine &A, const Twine &B, bool &result)
 Do paths represent the same thing?
 
bool llvm::sys::fs::equivalent (const Twine &A, const Twine &B)
 Simpler version of equivalent for clients that don't need to differentiate between an error and false.
 
std::error_code llvm::sys::fs::is_local (const Twine &path, bool &result)
 Is the file mounted on a local filesystem?
 
std::error_code llvm::sys::fs::is_local (int FD, bool &result)
 Version of is_local accepting an open file descriptor.
 
bool llvm::sys::fs::is_local (const Twine &Path)
 Simpler version of is_local for clients that don't need to differentiate between an error and false.
 
bool llvm::sys::fs::is_local (int FD)
 Simpler version of is_local accepting an open file descriptor for clients that don't need to differentiate between an error and false.
 
file_type llvm::sys::fs::get_file_type (const Twine &Path, bool Follow=true)
 Does status represent a directory?
 
bool llvm::sys::fs::is_directory (const basic_file_status &status)
 Does status represent a directory?
 
std::error_code llvm::sys::fs::is_directory (const Twine &path, bool &result)
 Is path a directory?
 
bool llvm::sys::fs::is_directory (const Twine &Path)
 Simpler version of is_directory for clients that don't need to differentiate between an error and false.
 
bool llvm::sys::fs::is_regular_file (const basic_file_status &status)
 Does status represent a regular file?
 
std::error_code llvm::sys::fs::is_regular_file (const Twine &path, bool &result)
 Is path a regular file?
 
bool llvm::sys::fs::is_regular_file (const Twine &Path)
 Simpler version of is_regular_file for clients that don't need to differentiate between an error and false.
 
bool llvm::sys::fs::is_symlink_file (const basic_file_status &status)
 Does status represent a symlink file?
 
std::error_code llvm::sys::fs::is_symlink_file (const Twine &path, bool &result)
 Is path a symlink file?
 
bool llvm::sys::fs::is_symlink_file (const Twine &Path)
 Simpler version of is_symlink_file for clients that don't need to differentiate between an error and false.
 
bool llvm::sys::fs::is_other (const basic_file_status &status)
 Does this status represent something that exists but is not a directory or regular file?
 
std::error_code llvm::sys::fs::is_other (const Twine &path, bool &result)
 Is path something that exists but is not a directory, regular file, or symlink?
 
std::error_code llvm::sys::fs::status (const Twine &path, file_status &result, bool follow=true)
 Get file status as if by POSIX stat().
 
std::error_code llvm::sys::fs::status (int FD, file_status &Result)
 A version for when a file descriptor is already available.
 
unsigned llvm::sys::fs::getUmask ()
 Get file creation mode mask of the process.
 
std::error_code llvm::sys::fs::setPermissions (const Twine &Path, perms Permissions)
 Set file permissions.
 
std::error_code llvm::sys::fs::setPermissions (int FD, perms Permissions)
 Vesion of setPermissions accepting a file descriptor.
 
ErrorOr< perms > llvm::sys::fs::getPermissions (const Twine &Path)
 Get file permissions.
 
std::error_code llvm::sys::fs::file_size (const Twine &Path, uint64_t &Result)
 Get file size.
 
std::error_code llvm::sys::fs::setLastAccessAndModificationTime (int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
 Set the file modification and access time.
 
std::error_code llvm::sys::fs::setLastAccessAndModificationTime (int FD, TimePoint<> Time)
 Simpler version that sets both file modification and access time to the same time.
 
bool llvm::sys::fs::status_known (const basic_file_status &s)
 Is status available?
 
std::error_code llvm::sys::fs::status_known (const Twine &path, bool &result)
 Is status available?
 
void llvm::sys::fs::createUniquePath (const Twine &Model, SmallVectorImpl< char > &ResultPath, bool MakeAbsolute)
 Create a potentially unique file name but does not create it.
 
std::error_code llvm::sys::fs::createUniqueFile (const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None, unsigned Mode=all_read|all_write)
 Create a uniquely named file.
 
std::error_code llvm::sys::fs::createUniqueFile (const Twine &Model, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
 Simpler version for clients that don't want an open file.
 
std::error_code llvm::sys::fs::createTemporaryFile (const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
 Create a file in the system temporary directory.
 
std::error_code llvm::sys::fs::createTemporaryFile (const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
 Simpler version for clients that don't want an open file.
 
std::error_code llvm::sys::fs::createUniqueDirectory (const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
 
std::error_code llvm::sys::fs::getPotentiallyUniqueFileName (const Twine &Model, SmallVectorImpl< char > &ResultPath)
 Get a unique name, not currently exisiting in the filesystem.
 
std::error_code llvm::sys::fs::getPotentiallyUniqueTempFileName (const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath)
 Get a unique temporary file name, not currently exisiting in the filesystem.
 
OpenFlags llvm::sys::fs::operator| (OpenFlags A, OpenFlags B)
 
OpenFlags & llvm::sys::fs::operator|= (OpenFlags &A, OpenFlags B)
 
FileAccess llvm::sys::fs::operator| (FileAccess A, FileAccess B)
 
FileAccess & llvm::sys::fs::operator|= (FileAccess &A, FileAccess B)
 
std::error_code llvm::sys::fs::openFile (const Twine &Name, int &ResultFD, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
 Opens a file with the specified creation disposition, access mode, and flags and returns a file descriptor.
 
Expected< file_t > llvm::sys::fs::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-specific file object.
 
file_t llvm::sys::fs::convertFDToNativeFile (int FD)
 Converts from a Posix file descriptor number to a native file handle.
 
file_t llvm::sys::fs::getStdinHandle ()
 Return an open handle to standard in.
 
file_t llvm::sys::fs::getStdoutHandle ()
 Return an open handle to standard out.
 
file_t llvm::sys::fs::getStderrHandle ()
 Return an open handle to standard error.
 
Expected< size_t > llvm::sys::fs::readNativeFile (file_t FileHandle, MutableArrayRef< char > Buf)
 Reads Buf.size() bytes from FileHandle into Buf.
 
Error llvm::sys::fs::readNativeFileToEOF (file_t FileHandle, SmallVectorImpl< char > &Buffer, ssize_t ChunkSize=DefaultReadChunkSize)
 Reads from FileHandle until EOF, appending to Buffer in chunks of size ChunkSize.
 
Expected< size_t > llvm::sys::fs::readNativeFileSlice (file_t FileHandle, MutableArrayRef< char > Buf, uint64_t Offset)
 Reads Buf.size() bytes from FileHandle at offset Offset into Buf.
 
std::error_code llvm::sys::fs::openFileForWrite (const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
 Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.
 
Expected< file_t > llvm::sys::fs::openNativeFileForWrite (const Twine &Name, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
 Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.
 
std::error_code llvm::sys::fs::openFileForReadWrite (const Twine &Name, int &ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
 Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.
 
Expected< file_t > llvm::sys::fs::openNativeFileForReadWrite (const Twine &Name, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
 Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.
 
std::error_code llvm::sys::fs::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.
 
Expected< file_t > llvm::sys::fs::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 llvm::sys::fs::tryLockFile (int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
 Try to locks the file during the specified time.
 
std::error_code llvm::sys::fs::lockFile (int FD)
 Lock the file.
 
std::error_code llvm::sys::fs::unlockFile (int FD)
 Unlock the file.
 
std::error_code llvm::sys::fs::closeFile (file_t &F)
 Close the file object.
 
std::error_code llvm::sys::fs::changeFileOwnership (int FD, uint32_t Owner, uint32_t Group)
 Change ownership of a file.
 
std::error_code llvm::sys::fs::getUniqueID (const Twine Path, UniqueID &Result)
 
ErrorOr< space_info > llvm::sys::fs::disk_space (const Twine &Path)
 Get disk space usage information.
 
std::string llvm::sys::fs::getMainExecutable (const char *argv0, void *MainExecAddr)
 Return the path to the main executable, given the value of argv[0] from program startup and the address of main itself.