LLVM: llvm::sys::fs Namespace Reference (original) (raw)

Classes
class basic_file_status
Represents the result of a call to directory_iterator::status(). More...
class directory_entry
directory_entry - A single entry in a directory. More...
class directory_iterator
directory_iterator - Iterates through the entries in path. More...
class file_status
Represents the result of a call to sys::fs::status(). More...
class FileLocker
RAII class that facilitates file locking. More...
class mapped_file_region
This class represents a memory mapped file. More...
class recursive_directory_iterator
recursive_directory_iterator - Same as directory_iterator except for it recurses down into child directories. More...
struct space_info
space_info - Self explanatory. More...
class TempFile
Represents a temporary file. More...
class UniqueID
Typedefs
using file_t = int
Enumerations
enum class file_type { status_error, file_not_found, regular_file, directory_file, symlink_file, block_file, character_file, fifo_file, socket_file, type_unknown }
An enumeration for the file system's view of the type. More...
enum perms { no_perms = 0 , owner_read = 0400 , owner_write = 0200 , owner_exe = 0100 , owner_all = owner_read | owner_write owner_exe , group_read = 040 , group_write = 020 , group_exe = 010 , group_all = group_read group_write group_exe , others_read = 04 , others_write = 02 , others_exe = 01 , others_all = others_read others_write others_exe , all_read = owner_read group_read others_read , all_write = owner_write group_write others_write , all_exe = owner_exe group_exe others_exe , all_all = owner_all group_all others_all , set_uid_on_exe = 04000 , set_gid_on_exe = 02000 , sticky_bit = 01000 , all_perms = all_all set_uid_on_exe set_gid_on_exe sticky_bit , perms_not_known = 0xFFFF }
Functions
perms operator| (perms l, perms r)
perms operator& (perms l, perms r)
perms & operator|= (perms &l, perms r)
perms & operator&= (perms &l, perms r)
perms operator~ (perms x)
static std::error_code createTemporaryFile (const Twine &Model, int &ResultFD, llvm::SmallVectorImpl< char > &ResultPath, FSEntity Type, sys::fs::OpenFlags Flags=sys::fs::OF_None)
static std::error_code createTemporaryFile (const Twine &Prefix, StringRef Suffix, int &ResultFD, llvm::SmallVectorImpl< char > &ResultPath, FSEntity Type, sys::fs::OpenFlags Flags=sys::fs::OF_None)
static std::error_code copy_file_internal (int ReadFD, int WriteFD)
Physical Operators
LLVM_ABI std::error_code make_absolute (SmallVectorImpl< char > &path)
Make path an absolute path.
LLVM_ABI 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.
LLVM_ABI std::error_code create_directory (const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
LLVM_ABI std::error_code create_link (const Twine &to, const Twine &from)
Create a link from from to to.
LLVM_ABI std::error_code create_hard_link (const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
LLVM_ABI std::error_code real_path (const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
LLVM_ABI void expand_tilde (const Twine &path, SmallVectorImpl< char > &output)
Expands ~ expressions to the user's home directory.
LLVM_ABI std::error_code current_path (SmallVectorImpl< char > &result)
Get the current path.
LLVM_ABI std::error_code set_current_path (const Twine &path)
Set the current path.
LLVM_ABI std::error_code remove (const Twine &path, bool IgnoreNonExisting=true)
Remove path.
LLVM_ABI std::error_code remove_directories (const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
LLVM_ABI std::error_code rename (const Twine &from, const Twine &to)
Rename from to to.
LLVM_ABI std::error_code copy_file (const Twine &From, const Twine &To)
Copy the contents of From to To.
LLVM_ABI std::error_code copy_file (const Twine &From, int ToFD)
Copy the contents of From to To.
LLVM_ABI std::error_code resize_file (int FD, uint64_t Size)
Resize path to size.
LLVM_ABI std::error_code resize_file_sparse (int FD, uint64_t Size)
Resize path to size with sparse files explicitly enabled.
std::error_code resize_file_before_mapping_readwrite (int FD, uint64_t Size)
Resize FD to Size before mapping mapped_file_region::readwrite.
LLVM_ABI ErrorOr< MD5::MD5Result > md5_contents (int FD)
Compute an MD5 hash of a file's contents.
LLVM_ABI ErrorOr< MD5::MD5Result > md5_contents (const Twine &Path)
Version of compute_md5 that doesn't require an open file descriptor.
Physical Observers
enum class AccessMode { Exist, Write, Execute }
enum CreationDisposition : unsigned { CD_CreateAlways = 0 , CD_CreateNew = 1 , CD_OpenExisting = 2 , CD_OpenAlways = 3 }
enum FileAccess : unsigned { FA_Read = 1 , FA_Write = 2 }
enum OpenFlags : unsigned { OF_None = 0 , OF_Text = 1 , OF_CRLF = 2 , OF_TextWithCRLF = OF_Text | OF_CRLF , OF_Append = 4 , OF_Delete = 8 , OF_ChildInherit = 16 , OF_UpdateAtime = 32 }
enum : size_t { DefaultReadChunkSize = 4 * 4096 }
Default chunk size for readNativeFileToEOF(). More...
enum class LockKind { Exclusive, Shared }
An enumeration for the lock kind. More...
LLVM_ABI bool exists (const basic_file_status &status)
Does file exist?
LLVM_ABI std::error_code access (const Twine &Path, AccessMode Mode)
Can the file be accessed?
bool exists (const Twine &Path)
Does file exist?
LLVM_ABI bool can_execute (const Twine &Path)
Can we execute this file?
bool can_write (const Twine &Path)
Can we write this file?
LLVM_ABI bool equivalent (file_status A, file_status B)
Do file_status's represent the same thing?
LLVM_ABI std::error_code equivalent (const Twine &A, const Twine &B, bool &result)
Do paths represent the same thing?
bool equivalent (const Twine &A, const Twine &B)
Simpler version of equivalent for clients that don't need to differentiate between an error and false.
LLVM_ABI std::error_code is_local (const Twine &path, bool &result)
Is the file mounted on a local filesystem?
LLVM_ABI std::error_code is_local (int FD, bool &result)
Version of is_local accepting an open file descriptor.
bool is_local (const Twine &Path)
Simpler version of is_local for clients that don't need to differentiate between an error and false.
bool 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.
LLVM_ABI file_type get_file_type (const Twine &Path, bool Follow=true)
Does status represent a directory?
LLVM_ABI bool is_directory (const basic_file_status &status)
Does status represent a directory?
LLVM_ABI std::error_code is_directory (const Twine &path, bool &result)
Is path a directory?
bool is_directory (const Twine &Path)
Simpler version of is_directory for clients that don't need to differentiate between an error and false.
LLVM_ABI bool is_regular_file (const basic_file_status &status)
Does status represent a regular file?
LLVM_ABI std::error_code is_regular_file (const Twine &path, bool &result)
Is path a regular file?
bool 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.
LLVM_ABI bool is_symlink_file (const basic_file_status &status)
Does status represent a symlink file?
LLVM_ABI std::error_code is_symlink_file (const Twine &path, bool &result)
Is path a symlink file?
bool 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.
LLVM_ABI bool is_other (const basic_file_status &status)
Does this status represent something that exists but is not a directory or regular file?
LLVM_ABI std::error_code is_other (const Twine &path, bool &result)
Is path something that exists but is not a directory, regular file, or symlink?
LLVM_ABI std::error_code status (const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ABI std::error_code status (int FD, file_status &Result)
A version for when a file descriptor is already available.
LLVM_ABI unsigned getUmask ()
Get file creation mode mask of the process.
LLVM_ABI std::error_code setPermissions (const Twine &Path, perms Permissions)
Set file permissions.
LLVM_ABI std::error_code setPermissions (int FD, perms Permissions)
Vesion of setPermissions accepting a file descriptor.
LLVM_ABI ErrorOr< perms > getPermissions (const Twine &Path)
Get file permissions.
std::error_code file_size (const Twine &Path, uint64_t &Result)
Get file size.
LLVM_ABI std::error_code setLastAccessAndModificationTime (int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
std::error_code setLastAccessAndModificationTime (int FD, TimePoint<> Time)
Simpler version that sets both file modification and access time to the same time.
LLVM_ABI bool status_known (const basic_file_status &s)
Is status available?
LLVM_ABI std::error_code status_known (const Twine &path, bool &result)
Is status available?
LLVM_ABI void createUniquePath (const Twine &Model, SmallVectorImpl< char > &ResultPath, bool MakeAbsolute)
Create a potentially unique file name but does not create it.
LLVM_ABI std::error_code createUniqueFile (const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None, unsigned Mode=all_read|all_write)
Create a uniquely named file.
LLVM_ABI std::error_code createUniqueFile (const Twine &Model, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Simpler version for clients that don't want an open file.
LLVM_ABI std::error_code createTemporaryFile (const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
Create a file in the system temporary directory.
LLVM_ABI std::error_code createTemporaryFile (const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
Simpler version for clients that don't want an open file.
LLVM_ABI std::error_code createUniqueDirectory (const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
LLVM_ABI std::error_code getPotentiallyUniqueFileName (const Twine &Model, SmallVectorImpl< char > &ResultPath)
Get a unique name, not currently exisiting in the filesystem.
LLVM_ABI std::error_code getPotentiallyUniqueTempFileName (const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath)
Get a unique temporary file name, not currently exisiting in the filesystem.
OpenFlags operator| (OpenFlags A, OpenFlags B)
OpenFlags & operator|= (OpenFlags &A, OpenFlags B)
FileAccess operator| (FileAccess A, FileAccess B)
FileAccess & operator|= (FileAccess &A, FileAccess B)
LLVM_ABI std::error_code 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.
LLVM_ABI Expected< file_t > 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.
LLVM_ABI file_t convertFDToNativeFile (int FD)
Converts from a Posix file descriptor number to a native file handle.
LLVM_ABI file_t getStdinHandle ()
Return an open handle to standard in.
LLVM_ABI file_t getStdoutHandle ()
Return an open handle to standard out.
LLVM_ABI file_t getStderrHandle ()
Return an open handle to standard error.
LLVM_ABI Expected< size_t > readNativeFile (file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
LLVM_ABI Error readNativeFileToEOF (file_t FileHandle, SmallVectorImpl< char > &Buffer, ssize_t ChunkSize=DefaultReadChunkSize)
Reads from FileHandle until EOF, appending to Buffer in chunks of size ChunkSize.
LLVM_ABI Expected< size_t > readNativeFileSlice (file_t FileHandle, MutableArrayRef< char > Buf, uint64_t Offset)
Reads Buf.size() bytes from FileHandle at offset Offset into Buf.
std::error_code 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 > 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 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 > 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.
LLVM_ABI std::error_code 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.
LLVM_ABI Expected< file_t > 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.
LLVM_ABI std::error_code tryLockFile (int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), LockKind Kind=LockKind::Exclusive)
Try to locks the file during the specified time.
LLVM_ABI std::error_code lockFile (int FD, LockKind Kind=LockKind::Exclusive)
Lock the file.
LLVM_ABI std::error_code unlockFile (int FD)
Unlock the file.
LLVM_ABI std::error_code closeFile (file_t &F)
Close the file object.
LLVM_ABI std::error_code changeFileOwnership (int FD, uint32_t Owner, uint32_t Group)
Change ownership of a file.
LLVM_ABI std::error_code getUniqueID (const Twine Path, UniqueID &Result)
LLVM_ABI ErrorOr< space_info > disk_space (const Twine &Path)
Get disk space usage information.
LLVM_ABI 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 address of main itself.

file_t

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

anonymous enum

Default chunk size for readNativeFileToEOF().

Enumerator
DefaultReadChunkSize

Definition at line 1017 of file FileSystem.h.

AccessMode

CreationDisposition

Enumerator
CD_CreateAlways CD_CreateAlways - When opening a file: If it already exists, truncate it. If it does not already exist, create a new file.
CD_CreateNew CD_CreateNew - When opening a file: If it already exists, fail. If it does not already exist, create a new file.
CD_OpenExisting CD_OpenExisting - When opening a file: If it already exists, open the file with the offset set to 0. If it does not already exist, fail.
CD_OpenAlways CD_OpenAlways - When opening a file: If it already exists, open the file with the offset set to 0. If it does not already exist, create a new file.

Definition at line 723 of file FileSystem.h.

file_type

An enumeration for the file system's view of the type.

Enumerator
status_error
file_not_found
regular_file
directory_file
symlink_file
block_file
character_file
fifo_file
socket_file
type_unknown

Definition at line 62 of file FileSystem.h.

FileAccess

LockKind

An enumeration for the lock kind.

Enumerator
Exclusive
Shared

Definition at line 1168 of file FileSystem.h.

OpenFlags

Enumerator
OF_None
OF_Text The file should be opened in text mode on platforms like z/OS that make this distinction.
OF_CRLF The file should use a carriage linefeed '\r'. This flag should only be used with OF_Text. Only makes a difference on Windows.
OF_TextWithCRLF The file should be opened in text mode and use a carriage linefeed '\r'. This flag has the same functionality as OF_Text on z/OS but adds a carriage linefeed on Windows.
OF_Append The file should be opened in append mode.
OF_Delete The returned handle can be used for deleting the file. Only makes a difference on windows.
OF_ChildInherit When a child process is launched, this file should remain open in the child process.
OF_UpdateAtime Force files Atime to be updated on access. Only makes a difference on Windows.

Definition at line 750 of file FileSystem.h.

perms

Enumerator
no_perms
owner_read
owner_write
owner_exe
owner_all
group_read
group_write
group_exe
group_all
others_read
others_write
others_exe
others_all
all_read
all_write
all_exe
all_all
set_uid_on_exe
set_gid_on_exe
sticky_bit
all_perms
perms_not_known

Definition at line 82 of file FileSystem.h.

access()

can_execute()

can_write()

Can we write this file?

Parameters

Returns

True if we can write to it, false otherwise.

Definition at line 469 of file FileSystem.h.

References access(), and Write.

changeFileOwnership()

Change ownership of a file.

Parameters

Owner The owner of the file to change to.
Group The group of the file to change to.

Returns

errc::success if successfully updated file ownership, otherwise an error code is returned.

References LLVM_ABI, and Owner.

Referenced by llvm::FilePermissionsApplier::apply().

closeFile()

LLVM_ABI std::error_code llvm::sys::fs::closeFile ( file_t & F )

Close the file object.

This should be used instead of ::close for portability. On error, the caller should assume the file is closed, as is the case for Process::SafelyCloseFileDescriptor

Parameters

F On input, this is the file to close. On output, the file is set to kInvalidFile.

Returns

An error code if closing the file failed. Typically, an error here means that the filesystem may have failed to perform some buffered writes.

References F, and LLVM_ABI.

Referenced by llvm::cas::ondisk::UnifiedOnDiskCache::close(), llvm::sys::fs::TempFile::discard(), llvm::NewArchiveMember::getFile(), llvm::MemoryBuffer::getFileAsStream(), getFileAux(), llvm::sys::fs::TempFile::keep(), llvm::cas::ondisk::OnDiskGraphDB::load(), llvm::orc::loadLinkableFile(), llvm::orc::loadMachORelocatableObject(), llvm::xray::loadProfile(), llvm::xray::loadTraceFile(), loadYAML(), llvm::localCache(), llvm::streamFile(), llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded(), and llvm::InteractiveModelRunner::~InteractiveModelRunner().

convertFDToNativeFile()

file_t llvm::sys::fs::convertFDToNativeFile ( int FD) inline

Converts from a Posix file descriptor number to a native file handle.

On Windows, this retreives the underlying handle. On non-Windows, this is a no-op.

Definition at line 991 of file FileSystem.h.

Referenced by areFilesDifferent(), llvm::cas::ondisk::UnifiedOnDiskCache::close(), llvm::cas::MappedFileRegionArena::create(), llvm::LTOModule::createFromOpenFileSlice(), createOnDiskBuffer(), createTempFile(), llvm::sys::fs::TempFile::discard(), llvm::sys::fs::TempFile::keep(), llvm::localCache(), llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded(), and llvm::InteractiveModelRunner::~InteractiveModelRunner().

copy_file() [1/2]

copy_file() [2/2]

std::error_code llvm::sys::fs::copy_file ( const Twine & From,
int ToFD )

Copy the contents of From to To.

Parameters

From The path to copy from.
ToFD The open file descriptor of the destination file.

Definition at line 1035 of file Path.cpp.

References copy_file_internal(), OF_None, and openFileForRead().

copy_file_internal()

std::error_code llvm::sys::fs::copy_file_internal ( int ReadFD, int WriteFD ) static

create_directories()

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.

Parameters

path Directories to create.

Returns

errc::success if is_directory(path), otherwise a platform specific error_code. If IgnoreExisting is false, also returns error if the directory already existed.

Definition at line 967 of file Path.cpp.

References create_directories(), create_directory(), llvm::StringRef::empty(), llvm::no_such_file_or_directory, P, and llvm::sys::path::parent_path().

Referenced by codegen(), llvm::FileCollector::copyFiles(), create_directories(), createDirectoriesOnDemand(), llvm::logicalview::LVSplitContext::createSplitFolder(), llvm::lto::getThinLTOOutputFile(), llvm::localCache(), llvm::cas::ondisk::OnDiskGraphDB::open(), llvm::cas::ondisk::OnDiskKeyValueDB::open(), llvm::cas::ondisk::UnifiedOnDiskCache::open(), prepareDumpIRFileDescriptor(), llvm::ThinLTOCodeGenerator::run(), and llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded().

create_directory()

Create a hard link from from to to, or return an error.

Parameters

to The path to hard link to.
from The path to hard link from. This is created.

Returns

errc::success if the link was created, otherwise a platform specific error_code.

References LLVM_ABI.

Referenced by llvm::ThinLTOCodeGenerator::writeGeneratedObject().

Create a link from from to to.

The link may be a soft or a hard link, depending on the platform. The caller may not assume which one. Currently on windows it creates a hard link since soft links require extra privileges. On unix, it creates a soft link since hard links don't work on SMB file systems.

Parameters

to The path to hard link to.
from The path to hard link from. This is created.

Returns

errc::success if the link was created, otherwise a platform specific error_code.

References LLVM_ABI.

Referenced by llvm::unittest::TempLink::TempLink(), and llvm::LockFileManager::tryLock().

createTemporaryFile() [1/4]

createTemporaryFile() [2/4]

createTemporaryFile() [3/4]

Create a file in the system temporary directory.

The filename is of the form prefix-random_chars.suffix. Since the directory is not know to the caller, Prefix and Suffix cannot have path separators. The files are created with mode 0600.

This should be used for things like a temporary .s that is removed after running the assembler.

Definition at line 912 of file Path.cpp.

References createTemporaryFile(), and FS_File.

Referenced by collectAddressSymbols(), llvm::createGraphFilename(), createTemporaryFile(), createTemporaryFile(), createTemporaryFile(), getPotentiallyUniqueTempFileName(), llvm::prepareTempFiles(), llvm::unittest::TempFile::TempFile(), and validateOutOfProcess().

createTemporaryFile() [4/4]

Simpler version for clients that don't want an open file.

An empty file will still be created.

Definition at line 920 of file Path.cpp.

References createTemporaryFile().

createUniqueDirectory()

createUniqueFile() [1/2]

Create a uniquely named file.

Generates a unique path suitable for a temporary file and then opens it as a file. The name is based on Model with '' replaced by a random char in [0-9a-f]. If Model is not an absolute path, the temporary file will be created in the current directory.

Example: clang-%%-%%-%%-%%-%%.s => clang-a0-b1-c2-d3-e4.s

This is an atomic operation. Either the file is created and opened, or the file system is left untouched.

The intended use is for files that are to be kept, possibly after renaming them. For example, when running 'clang -c foo.o', the file can be first created as foo-abc123.o and then renamed.

Parameters

Model Name to base unique path off of.
ResultFD Set to the opened file's file descriptor.
ResultPath Set to the opened file's absolute path.
Flags Set to the opened file's flags.
Mode Set to the opened file's permissions.

Returns

errc::success if Result{FD,Path} have been successfully set, otherwise a platform-specific error_code.

Definition at line 871 of file Path.cpp.

References createUniqueEntity(), and FS_File.

Referenced by llvm::sys::fs::TempFile::create(), createUniqueFile(), and llvm::LockFileManager::tryLock().

createUniqueFile() [2/2]

createUniquePath()

Create a potentially unique file name but does not create it.

Generates a unique path suitable for a temporary file but does not open or create the file. The name is based on Model with '' replaced by a random char in [0-9a-f]. If MakeAbsolute is true then the system's temp directory is prepended first. If MakeAbsolute is false the current directory will be used instead.

This function does not check if the file exists. If you want to be sure that the file does not yet exist, you should use enough '' characters in your model to ensure this. Each '' gives 4-bits of entropy so you can use 32 of them to get 128 bits of entropy.

Example: clang-%%-%%-%%-%%-%%.s => clang-a0-b1-c2-d3-e4.s

Parameters

Model Name to base unique path off of.
ResultPath Set to the file's path.
MakeAbsolute Whether to use the system temp directory.

Definition at line 845 of file Path.cpp.

References llvm::sys::path::append(), llvm::sys::Process::GetRandomNumber(), llvm::sys::path::is_absolute(), llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::SmallVectorImpl< T >::swap(), and llvm::sys::path::system_temp_directory().

Referenced by createUniqueEntity(), and llvm::DotCfgChangeReporter::handleFunctionCompare().

current_path()

Get the current path.

Parameters

result Holds the current path on return.

Returns

errc::success if the current path has been stored in result, otherwise a platform-specific error_code.

References LLVM_ABI.

Referenced by llvm::orc::createComponent(), and make_absolute().

disk_space()

Get disk space usage information.

Note: Users must be careful about "Time Of Check, Time Of Use" kind of bug. Note: Windows reports results according to the quota allocated to the user.

Parameters

Returns

a space_info structure filled with the capacity, free, and available space on the device Path is on. A platform specific error_code is returned on error.

References LLVM_ABI.

Referenced by llvm::pruneCache().

equivalent() [1/3]

Simpler version of equivalent for clients that don't need to differentiate between an error and false.

Definition at line 499 of file FileSystem.h.

References A(), B(), and equivalent().

equivalent() [2/3]

Do paths represent the same thing?

assert(status_known(A) || status_known(B));

Parameters

A Input path A.
B Input path B.
result Set to true if stat(A) and stat(B) have the same device and inode (or equivalent).

Returns

errc::success if result has been successfully set, otherwise a platform-specific error_code.

References A(), B(), and LLVM_ABI.

equivalent() [3/3]

exists() [1/2]

Does file exist?

Parameters

Returns

True if the file represented by status exists, false if it does not.

Definition at line 1077 of file Path.cpp.

References file_not_found, status(), and status_known().

Referenced by llvm::ListeningSocket::createUnix(), llvm::object::BuildIDFetcher::fetch(), llvm::sys::Process::FindInEnvPath(), findInputFile(), is_other(), llvm::pdb::InputFile::open(), llvm::orc::DumpObjects::operator()(), printMarkupStackTrace(), printSymbolizedStackTrace(), searchForObj(), llvm::LockFileManager::tryLock(), llvm::cas::ondisk::OnDiskGraphDB::validate(), and llvm::ThinLTOCodeGenerator::writeGeneratedObject().

exists() [2/2]

Does file exist?

Parameters

Returns

True if it exists, false otherwise.

Definition at line 455 of file FileSystem.h.

References access(), and Exist.

expand_tilde()

file_size()

get_file_type()

getMainExecutable()

LLVM_ABI std::string llvm::sys::fs::getMainExecutable ( const char * argv0,
void * MainExecAddr )

getPermissions()

Get file permissions.

Parameters

Path File to get permissions from.

Returns

the permissions if they were successfully retrieved, otherwise a platform-specific error_code.

Note

On Windows, if the file does not have the FILE_ATTRIBUTE_READONLY attribute, all_all will be returned. Otherwise, all_read | all_exe will be returned.

Definition at line 1151 of file Path.cpp.

References status().

Referenced by llvm::FileCollector::copyFiles().

getPotentiallyUniqueFileName()

Get a unique name, not currently exisiting in the filesystem.

Subject to race conditions, prefer to use createUniqueFile instead.

Similar to createUniqueFile, but instead of creating a file only checks if it exists. This function is subject to race conditions, if you want to use the returned name to actually create a file, use createUniqueFile instead.

Definition at line 942 of file Path.cpp.

References createUniqueEntity(), and FS_Name.

getPotentiallyUniqueTempFileName()

Get a unique temporary file name, not currently exisiting in the filesystem.

Subject to race conditions, prefer to use createTemporaryFile instead.

Similar to createTemporaryFile, but instead of creating a file only checks if it exists. This function is subject to race conditions, if you want to use the returned name to actually create a file, use createTemporaryFile instead.

Definition at line 949 of file Path.cpp.

References createTemporaryFile(), and FS_Name.

getStderrHandle()

LLVM_ABI file_t llvm::sys::fs::getStderrHandle ( )

Return an open handle to standard error.

On Unix, this is typically FD 2. Returns kInvalidFile when the stream is closed.

References LLVM_ABI.

getStdinHandle()

LLVM_ABI file_t llvm::sys::fs::getStdinHandle ( )

getStdoutHandle()

LLVM_ABI file_t llvm::sys::fs::getStdoutHandle ( )

Return an open handle to standard out.

On Unix, this is typically FD 1. Returns kInvalidFile when the stream is closed.

References LLVM_ABI.

getUmask()

Get file creation mode mask of the process.

Returns

Mask reported by umask(2)

Note

There is no umask on Windows. This function returns 0 always on Windows. This function does not return an error_code because umask(2) never fails. It is not thread safe.

References LLVM_ABI.

Referenced by llvm::FilePermissionsApplier::apply().

getUniqueID()

is_directory() [1/3]

is_directory() [2/3]

Simpler version of is_directory for clients that don't need to differentiate between an error and false.

Definition at line 555 of file FileSystem.h.

References is_directory().

is_directory() [3/3]

std::error_code llvm::sys::fs::is_directory ( const Twine & path,
bool & result )

Is path a directory?

Parameters

path Input path.
result Set to true if path is a directory (after following symlinks, false if it is not. Undefined otherwise.

Returns

errc::success if result has been successfully set, otherwise a platform-specific error_code.

Definition at line 1096 of file Path.cpp.

References is_directory(), and status().

is_local() [1/4]

Simpler version of is_local for clients that don't need to differentiate between an error and false.

Definition at line 518 of file FileSystem.h.

References is_local().

is_local() [2/4]

Is the file mounted on a local filesystem?

Parameters

path Input path.
result Set to true if path is on fixed media such as a hard disk, false if it is not.

Returns

errc::success if result has been successfully set, otherwise a platform specific error_code.

References LLVM_ABI.

Referenced by is_local(), and is_local().

is_local() [3/4]

bool llvm::sys::fs::is_local ( int FD) inline

Simpler version of is_local accepting an open file descriptor for clients that don't need to differentiate between an error and false.

Definition at line 525 of file FileSystem.h.

References is_local().

is_local() [4/4]

LLVM_ABI std::error_code llvm::sys::fs::is_local ( int FD,
bool & result )

Version of is_local accepting an open file descriptor.

References LLVM_ABI.

is_other() [1/2]

is_other() [2/2]

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?

Parameters

path Input path.
result Set to true if path exists, but is not a directory, regular file, or a symlink, false if it does not. Undefined otherwise.

Returns

errc::success if result has been successfully set, otherwise a platform-specific error_code.

Definition at line 1134 of file Path.cpp.

References is_other(), and status().

is_regular_file() [1/3]

is_regular_file() [2/3]

Simpler version of is_regular_file for clients that don't need to differentiate between an error and false.

Definition at line 577 of file FileSystem.h.

References is_regular_file().

is_regular_file() [3/3]

std::error_code llvm::sys::fs::is_regular_file ( const Twine & path,
bool & result )

Is path a regular file?

Parameters

path Input path.
result Set to true if path is a regular file (after following symlinks), false if it is not. Undefined otherwise.

Returns

errc::success if result has been successfully set, otherwise a platform-specific error_code.

Definition at line 1108 of file Path.cpp.

References is_regular_file(), and status().

Simpler version of is_symlink_file for clients that don't need to differentiate between an error and false.

Definition at line 601 of file FileSystem.h.

References is_symlink_file().

std::error_code llvm::sys::fs::is_symlink_file ( const Twine & path,
bool & result )

Is path a symlink file?

Parameters

path Input path.
result Set to true if path is a symlink file, false if it is not. Undefined otherwise.

Returns

errc::success if result has been successfully set, otherwise a platform-specific error_code.

Definition at line 1120 of file Path.cpp.

References is_symlink_file(), and status().

lockFile()

LLVM_ABI std::error_code llvm::sys::fs::lockFile ( int FD,
LockKind Kind = LockKind::Exclusive )

make_absolute()

Make path an absolute path.

Makes path absolute using the current directory if it is not already. An empty path will result in the current directory.

/absolute/path => /absolute/path relative/../path => /relative/../path

Parameters

path A path that is modified to be an absolute path.

Returns

errc::success if path has been made absolute, otherwise a platform-specific error_code.

Definition at line 955 of file Path.cpp.

References current_path(), llvm::sys::path::is_absolute(), and llvm::sys::path::make_absolute().

Referenced by llvm::canonicalizePath(), llvm::cas::createOnDiskCAS(), emitExternalFile(), llvm::AsmPrinter::emitRemarksSection(), findSrcDirMap(), llvm::MachO::make_relative(), llvm::vfs::OnDiskOutputBackend::makeAbsolute(), llvm::DotCfgChangeReporter::registerCallbacks(), and llvm::LockFileManager::tryLock().

md5_contents() [1/2]

md5_contents() [2/2]

openFile()

Opens a file with the specified creation disposition, access mode, and flags and returns a file descriptor.

The caller is responsible for closing the file descriptor once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
ResultFD If the file could be opened successfully, its descriptor is stored in this location. Otherwise, this is set to -1.
Disp Value specifying the existing-file behavior.
Access Value specifying whether to open the file in read, write, or read-write mode.
Flags Additional flags.
Mode The access permissions of the file, represented in octal.

Returns

errc::success if Name has been opened, otherwise a platform-specific error_code.

References Access, LLVM_ABI, and Mode.

Referenced by openFileForReadWrite(), openFileForWrite(), and prepareDumpIRFileDescriptor().

openFileForRead()

Opens the file with the given name in a read-only mode, returning its open file descriptor.

The caller is responsible for closing the file descriptor once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
ResultFD If the file could be opened successfully, its descriptor is stored in this location. Otherwise, this is set to -1.
RealPath If nonnull, extra work is done to determine the real path of the opened file, and that path is stored in this location.

Returns

errc::success if Name has been opened, otherwise a platform-specific error_code.

References LLVM_ABI, and OF_None.

Referenced by areFilesDifferent(), copy_file(), copy_file(), and md5_contents().

openFileForReadWrite()

std::error_code llvm::sys::fs::openFileForReadWrite ( const Twine & Name, int & ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode = 0666 ) inline

Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.

If the file does not exist, it is created.

The caller is responsible for closing the file descriptor once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
ResultFD If the file could be opened successfully, its descriptor is stored in this location. Otherwise, this is set to -1.
Flags Additional flags used to determine whether the file should be opened in, for example, read-write or in write-only mode.
Mode The access permissions of the file, represented in octal.

Returns

errc::success if Name has been opened, otherwise a platform-specific error_code.

Definition at line 1106 of file FileSystem.h.

References FA_Read, FA_Write, Mode, and openFile().

Referenced by createUniqueEntity(), getFD(), llvm::cas::ondisk::UnifiedOnDiskCache::open(), and llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded().

openFileForWrite()

std::error_code llvm::sys::fs::openFileForWrite ( const Twine & Name, int & ResultFD, CreationDisposition Disp = CD_CreateAlways, OpenFlags Flags = OF_None, unsigned Mode = 0666 ) inline

Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.

If the file does not exist, it is created.

The caller is responsible for closing the file descriptor once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
ResultFD If the file could be opened successfully, its descriptor is stored in this location. Otherwise, this is set to -1.
Flags Additional flags used to determine whether the file should be opened in, for example, read-write or in write-only mode.
Mode The access permissions of the file, represented in octal.

Returns

errc::success if Name has been opened, otherwise a platform-specific error_code.

Definition at line 1065 of file FileSystem.h.

References CD_CreateAlways, FA_Write, Mode, OF_None, and openFile().

Referenced by llvm::FilePermissionsApplier::apply(), copy_file(), copyAccessAndModificationTime(), getFD(), llvm::prepareTempFiles(), llvm::unittest::TempFile::TempFile(), and llvm::WriteGraph().

openNativeFile()

Opens a file with the specified creation disposition, access mode, and flags and returns a platform-specific file object.

The caller is responsible for closing the file object once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
Disp Value specifying the existing-file behavior.
Access Value specifying whether to open the file in read, write, or read-write mode.
Flags Additional flags.
Mode The access permissions of the file, represented in octal.

Returns

errc::success if Name has been opened, otherwise a platform-specific error_code.

References Access, LLVM_ABI, and Mode.

Referenced by openNativeFileForReadWrite(), and openNativeFileForWrite().

openNativeFileForRead()

Opens the file with the given name in a read-only mode, returning its open file descriptor.

The caller is responsible for closing the freeing the file once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
RealPath If nonnull, extra work is done to determine the real path of the opened file, and that path is stored in this location.

Returns

a platform-specific file descriptor if Name has been opened, otherwise an error object.

References OF_None.

Referenced by llvm::NewArchiveMember::getFile(), llvm::MemoryBuffer::getFileAsStream(), getFileAux(), llvm::cas::ondisk::OnDiskGraphDB::load(), llvm::xray::loadInstrumentationMap(), llvm::orc::loadLinkableFile(), llvm::orc::loadMachORelocatableObject(), llvm::xray::loadProfile(), llvm::xray::loadTraceFile(), llvm::localCache(), and llvm::streamFile().

openNativeFileForReadWrite()

Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.

If the file does not exist, it is created.

The caller is responsible for closing the freeing the file once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
Flags Additional flags used to determine whether the file should be opened in, for example, read-write or in write-only mode.
Mode The access permissions of the file, represented in octal.

Returns

a platform-specific file descriptor if Name has been opened, otherwise an error object.

Definition at line 1126 of file FileSystem.h.

References FA_Read, FA_Write, Mode, and openNativeFile().

Referenced by getReadWriteFile().

openNativeFileForWrite()

Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.

If the file does not exist, it is created.

The caller is responsible for closing the freeing the file once they are finished with it.

Parameters

Name The path of the file to open, relative or absolute.
Flags Additional flags used to determine whether the file should be opened in, for example, read-write or in write-only mode.
Mode The access permissions of the file, represented in octal.

Returns

a platform-specific file descriptor if Name has been opened, otherwise an error object.

Definition at line 1084 of file FileSystem.h.

References FA_Write, Mode, and openNativeFile().

operator&()

perms llvm::sys::fs::operator& ( perms l, perms r ) inline

operator&=()

perms & llvm::sys::fs::operator&= ( perms & l, perms r ) inline

operator|() [1/3]

FileAccess llvm::sys::fs::operator| ( FileAccess A, FileAccess B ) inline

operator|() [2/3]

OpenFlags llvm::sys::fs::operator| ( OpenFlags A, OpenFlags B ) inline

operator|() [3/3]

perms llvm::sys::fs::operator| ( perms l, perms r ) inline

operator|=() [1/3]

FileAccess & llvm::sys::fs::operator|= ( FileAccess & A, FileAccess B ) inline

operator|=() [2/3]

OpenFlags & llvm::sys::fs::operator|= ( OpenFlags & A, OpenFlags B ) inline

operator|=() [3/3]

perms & llvm::sys::fs::operator|= ( perms & l, perms r ) inline

operator~()

perms llvm::sys::fs::operator~ ( perms x) inline

readNativeFile()

Reads Buf.size() bytes from FileHandle into Buf.

Returns the number of bytes actually read. On Unix, this is equivalent to return ::read(FD, / Buf.data(), Buf.size()), with error reporting. Returns 0 when reaching EOF.

@param FileHandle File to read from. @param Buf Buffer to read into. @returns The number of bytes read, or error.

References LLVM_ABI.

Referenced by readNativeFileToEOF().

readNativeFileSlice()

Reads Buf.size() bytes from FileHandle at offset Offset into Buf.

If 'pread' is available, this will use that, otherwise it will use 'lseek'. Returns the number of bytes actually read. Returns 0 when reaching EOF.

Parameters

FileHandle File to read from.
Buf Buffer to read into.
Offset Offset into the file at which the read should occur.

Returns

The number of bytes read, or error.

References LLVM_ABI, and llvm::Offset.

Referenced by llvm::cas::MappedFileRegionArena::create(), and getOpenFileImpl().

readNativeFileToEOF()

Reads from FileHandle until EOF, appending to Buffer in chunks of size ChunkSize.

This calls readNativeFile() in a loop. On Error, previous chunks that were read successfully are left in Buffer and returned.

Note: For reading the final chunk at EOF, Buffer's capacity needs extra storage of ChunkSize.

Parameters

FileHandle File to read from.
Buffer Where to put the file content.
ChunkSize Size of chunks.

Returns

The error if EOF was not found.

Definition at line 1174 of file Path.cpp.

References llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::make_scope_exit(), llvm::MutableArrayRef(), readNativeFile(), llvm::SmallVectorImpl< T >::resize_for_overwrite(), Size, llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::Error::success(), llvm::Expected< T >::takeError(), and llvm::SmallVectorImpl< T >::truncate().

Referenced by getMemoryBufferForStream(), and llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded().

real_path()

remove()

Remove path.

Equivalent to POSIX remove().

Parameters

Returns

errc::success if path has been removed or didn't exist, otherwise a platform-specific error code. If IgnoreNonExisting is false, also returns error if the file didn't exist.

References LLVM_ABI.

Referenced by cleanUpTempFilesImpl(), llvm::LTOCodeGenerator::compileOptimized(), llvm::sys::fs::TempFile::discard(), ExecGraphViewer(), llvm::DotCfgChangeReporter::handleFunctionCompare(), llvm::pruneCache(), llvm::FileRemover::setFile(), llvm::LockFileManager::tryLock(), llvm::LockFileManager::unsafeMaybeUnlock(), llvm::ThinLTOCodeGenerator::writeGeneratedObject(), llvm::CleanupInstaller::~CleanupInstaller(), llvm::FileRemover::~FileRemover(), llvm::LockFileManager::~LockFileManager(), llvm::unittest::TempFile::~TempFile(), and llvm::unittest::TempLink::~TempLink().

remove_directories()

rename()

resize_file()

resize_file_before_mapping_readwrite()

std::error_code llvm::sys::fs::resize_file_before_mapping_readwrite ( int FD, uint64_t Size ) inline

resize_file_sparse()

LLVM_ABI std::error_code llvm::sys::fs::resize_file_sparse ( int FD,
uint64_t Size )

set_current_path()

Set the current path.

Parameters

Returns

errc::success if the current path was successfully set, otherwise a platform-specific error_code.

References LLVM_ABI.

setLastAccessAndModificationTime() [1/2]

LLVM_ABI std::error_code llvm::sys::fs::setLastAccessAndModificationTime ( int FD,
TimePoint<> AccessTime,
TimePoint<> ModificationTime )

setLastAccessAndModificationTime() [2/2]

std::error_code llvm::sys::fs::setLastAccessAndModificationTime ( int FD, TimePoint<> Time ) inline

Simpler version that sets both file modification and access time to the same time.

Definition at line 704 of file FileSystem.h.

References setLastAccessAndModificationTime().

setPermissions() [1/2]

Set file permissions.

Parameters

Path File to set permissions on.
Permissions New file permissions.

Returns

errc::success if the permissions were successfully set, otherwise a platform-specific error_code.

Note

On Windows, all permissions except *_write are ignored. Using any of owner_write, group_write, or all_write will make the file writable. Otherwise, the file will be marked as read-only.

References LLVM_ABI.

Referenced by llvm::FilePermissionsApplier::apply(), and llvm::FileCollector::copyFiles().

setPermissions() [2/2]

LLVM_ABI std::error_code llvm::sys::fs::setPermissions ( int FD,
perms Permissions )

Vesion of setPermissions accepting a file descriptor.

TODO Delete the path based overload once we implement the FD based overload on Windows.

References LLVM_ABI.

status() [1/2]

Get file status as if by POSIX stat().

Parameters

path Input path.
result Set to the file status.
follow When true, follows symlinks. Otherwise, the symlink itself is statted.

Returns

errc::success if result has been successfully set, otherwise a platform-specific error_code.

References LLVM_ABI.

Referenced by llvm::FilePermissionsApplier::apply(), areFilesDifferent(), llvm::FileCollector::copyFiles(), llvm::FileOutputBuffer::create(), llvm::FilePermissionsApplier::create(), exists(), file_size(), llvm::object::MachOObjectFile::findDsymObjectMembers(), get_file_type(), llvm::cas::ondisk::getBootTime(), llvm::NewArchiveMember::getFile(), getOpenFileImpl(), getPermissions(), getReadWriteFile(), getUniqueID(), llvm::sys::fs::recursive_directory_iterator::increment(), is_directory(), is_directory(), is_other(), is_other(), is_regular_file(), is_regular_file(), is_symlink_file(), is_symlink_file(), llvm::cas::ondisk::OnDiskGraphDB::load(), llvm::pruneCache(), llvm::MachO::shouldSkipSymLink(), and shouldUseMmap().

status() [2/2]

A version for when a file descriptor is already available.

References LLVM_ABI.

status_known() [1/2]

status_known() [2/2]

Is status available?

Parameters

path Input path.
result Set to true if status() != status_error.

Returns

errc::success if result has been successfully set, otherwise a platform-specific error_code.

References LLVM_ABI.

tryLockFile()

LLVM_ABI std::error_code llvm::sys::fs::tryLockFile ( int FD,
std::chrono::milliseconds Timeout = std::chrono::milliseconds(0),
LockKind Kind = LockKind::Exclusive )

Try to locks the file during the specified time.

This function implements advisory locking on entire file. If it returns errc::success, the file is locked by the calling process. Until the process unlocks the file by calling unlockFile, all attempts to lock the same file will fail/block. The process that locked the file may assume that none of other processes read or write this file, provided that all processes lock the file prior to accessing its content.

Parameters

FD The descriptor representing the file to lock.
Timeout Time in milliseconds that the process should wait before reporting lock failure. Zero value means try to get lock only once.
Kind The kind of the lock used (exclusive/shared).

Returns

errc::success if lock is successfully obtained, errc::no_lock_available if the file cannot be locked, or platform-specific error_code otherwise.

Note

Care should be taken when using this function in a multithreaded context, as it may not prevent other threads in the same process from obtaining a lock on the same file, even if they are using a different file descriptor.

References Exclusive, and llvm::Timeout.

Referenced by llvm::cas::ondisk::tryLockFileThreadSafe(), and llvm::raw_fd_ostream::tryLockFor().

unlockFile()

LLVM_ABI std::error_code llvm::sys::fs::unlockFile ( int FD )

kInvalidFile