LLVM API Documentation
#include <Path.h>
Collaboration diagram for llvm::sys::Path:
Constructors | |
Path () | |
Construct an empty (and invalid) path. | |
Path (std::string unverified_path) | |
Construct a Path from a string. | |
static Path | GetRootDirectory () |
static Path | GetTemporaryDirectory () |
Constrct a path to an new, unique, existing temporary directory. | |
static Path | GetLibraryPath (const std::string &basename, const std::vector< std::string > &LibPaths) |
Locate a library in a platform specific manner. | |
static Path | GetSystemLibraryPath1 () |
Construct a path to the first system library directory. | |
static Path | GetSystemLibraryPath2 () |
Construct a path to the second system library directory. | |
static Path | GetLLVMDefaultConfigDir () |
Construct a path to the default LLVM configuration directory. | |
static Path | GetLLVMConfigDir () |
Construct a path to the LLVM installed configuration directory. | |
static Path | GetUserHomeDirectory () |
Construct a path to the current user's "home" directory. | |
static std::string | GetDLLSuffix () |
Return the dynamic link library suffix. | |
Public Member Functions | |
Operators | |
Path & | operator= (const Path &that) |
Assignment Operator. | |
bool | operator== (const Path &that) const |
Equality Operator. | |
bool | operator!= (const Path &that) const |
Inequality Operator. | |
bool | operator< (const Path &that) const |
Less Than Operator. | |
Accessors | |
bool | isValid () const |
Determine if a path is syntactically valid or not. | |
bool | isEmpty () const |
Determines if the path name is empty (invalid). | |
bool | isFile () const |
Determines if the path name references a file. | |
bool | isDirectory () const |
Determines if the path name references a directory. | |
bool | isRootDirectory () const |
Determines if the path references the root directory. | |
bool | hasMagicNumber (const std::string &magic) const |
Determine if file has a specific magic number. | |
bool | getMagicNumber (std::string &Magic, unsigned len) const |
Get the file's magic number. | |
bool | isArchive () const |
Determine if the path references an archive file. | |
bool | isBytecodeFile () const |
Determine if the path references a bytecode file. | |
bool | exists () const |
Determines if the path is a file or directory in the file system. | |
bool | readable () const |
Determines if the path is a readable file or directory in the file system. | |
bool | writable () const |
Determines if the path is a writable file or directory in the file system. | |
bool | executable () const |
Determines if the path is an executable file in the file system. | |
std::string | get () const |
Returns the path as a std::string. | |
std::string | getLast () const |
Returns the last component of the path name. | |
std::string | getBasename () const |
Get the base name of the path. | |
bool | getDirectoryContents (std::set< Path > &paths) const |
Build a list of directory's contents. | |
const char *const | c_str () const |
Returns the path as a C string. | |
Mutators | |
void | clear () |
void | getStatusInfo (StatusInfo &info) const |
Get file status. | |
bool | setDirectory (const std::string &unverified_path) |
Set a full path from a std::string. | |
bool | setFile (const std::string &unverified_path) |
Set a full path from a std::string. | |
bool | appendDirectory (const std::string &dirname) |
Adds the name of a directory to a Path. | |
bool | elideDirectory () |
Removes the last directory component of the Path. | |
bool | appendFile (const std::string &filename) |
Appends the name of a file. | |
bool | elideFile () |
Removes the last file component of the path. | |
bool | appendSuffix (const std::string &suffix) |
Adds a period and the suffix to the end of the pathname. | |
bool | elideSuffix () |
Remove the suffix from a path name. | |
bool | createDirectory (bool create_parents=false) |
Create the directory this Path refers to. | |
bool | createFile () |
Create the file this Path refers to. | |
bool | createTemporaryFile () |
Create a unique temporary file. | |
bool | destroyDirectory (bool destroy_contents=false) |
Removes the file or directory from the filesystem. | |
bool | destroyFile () |
Destroy the file this Path refers to. | |
bool | renameFile (const Path &newName) |
Rename one file as another. | |
bool | setStatusInfo (const StatusInfo &si) const |
Set file times and mode. | |
Classes | |
struct | StatusInfo |
File status structure. More... |
This class provides an abstraction for the path to a file or directory in the operating system's filesystem and provides various basic operations on it. Note that this class only represents the name of a path to a file or directory which may or may not be valid for a given machine's file system. A Path ensures that the name it encapsulates is syntactical valid for the operating system it is running on but does not ensure correctness for any particular file system. A Path either references a file or a directory and the distinction is consistently maintained. Most operations on the class have invariants that require the Path object to be either a file path or a directory path, but not both. Those operations will also leave the object as either a file path or object path. There is exactly one invalid Path which is the empty path. The class should never allow any other syntactically invalid non-empty path name to be assigned. Empty paths are required in order to indicate an error result. If the path is empty, the isValid operation will return false. All operations will fail if isValid is false. Operations that change the path will either return false if it would cause a syntactically invalid path name (in which case the Path object is left unchanged) or throw an std::string exception indicating the error.
Definition at line 46 of file Path.h.
|
Construct an empty (and invalid) path. This is one of the very few ways in which a path can be constructed with a syntactically invalid name. The only *legal* invalid name is an empty one. Other invalid names are not permitted. Empty paths are provided so that they can be used to indicate null or error results in other lib/System functionality.
Definition at line 159 of file Path.h. Referenced by GetLLVMDefaultConfigDir(), GetSystemLibraryPath1(), and GetSystemLibraryPath2(). |
|
Construct a Path from a string. This constructor will accept a std::string as a path but if verifies that the path string has a legal syntax for the operating system on which it is running. This allows a path to be taken in from outside the program. However, if the path is not valid, the Path object will be set to an empty string and an exception will be thrown.
Definition at line 31 of file Unix/Path.cpp. References ThrowErrno(). |
|
Adds the name of a directory to a Path.
The
Definition at line 331 of file Unix/Path.cpp. |
|
Appends the name of a file.
The
Definition at line 360 of file Unix/Path.cpp. References isDirectory(), isValid(), and path. Referenced by llvm::sys::Program::FindProgramByName(), llvm::sys::IsLibrary(), and llvm::IsLibrary(). |
|
Adds a period and the
A period and the
Definition at line 384 of file Unix/Path.cpp. References isDirectory(), isValid(), and path. Referenced by llvm::sys::IsLibrary(), and llvm::IsLibrary(). |
|
Returns the path as a C string. Obtain a 'C' string for the path name.
Definition at line 353 of file Path.h. Referenced by llvm::sys::Program::ExecuteAndWait(), renameFile(), and llvm::Archive::writeToDisk(). |
|
The path name is cleared and becomes empty. This is an invalid path name but is the *only* invalid path name. This is provided so that path objects can be used to indicate the lack of a valid path being found. Definition at line 363 of file Path.h. Referenced by GetLibraryPath(), llvm::sys::IsLibrary(), and llvm::IsLibrary(). |
|
Create the directory this Path refers to.
This method attempts to create a directory in the file system with the same name as the Path object. The
Definition at line 412 of file Unix/Path.cpp. References isDirectory(), llvm::next(), and ThrowErrno(). |
|
Create the file this Path refers to. This method attempts to create a file in the file system with the same name as the Path object. The intermediate directories must all exist at the time this method is called. Use createDirectories to accomplish that. The created file will be empty upon return from this function.
Definition at line 453 of file Unix/Path.cpp. References isFile(), and ThrowErrno(). |
|
Create a unique temporary file.
This is like createFile except that it creates a temporary file. A unique temporary file name is generated based on the contents of
Definition at line 467 of file Unix/Path.cpp. References isFile(), and ThrowErrno(). Referenced by llvm::Archive::writeToDisk(). |
|
Removes the file or directory from the filesystem.
This method attempts to destroy the directory named by the last in the Path name. If
Definition at line 486 of file Unix/Path.cpp. References exists(), isDirectory(), and ThrowErrno(). |
|
Destroy the file this Path refers to. This method attempts to destroy the file named by the last item in the Path name.
Definition at line 514 of file Unix/Path.cpp. References isFile(), and ThrowErrno(). Referenced by llvm::Archive::writeToDisk(). |
|
Removes the last directory component of the Path. One directory component is removed from the Path name. The Path must refer to a non-root directory name (i.e. isDirectory() returns true but isRootDirectory() returns false). Upon exit, the Path will refer to the directory above it.
Definition at line 345 of file Unix/Path.cpp. References isFile(). |
|
Removes the last file component of the path. One file component is removed from the Path name. The Path must refer to a file (i.e. isFile() returns true). Upon exit, the Path will refer to the directory above it.
Definition at line 373 of file Unix/Path.cpp. References isDirectory(). Referenced by llvm::sys::IsLibrary(), and llvm::IsLibrary(). |
|
Remove the suffix from a path name. The suffix of the filename is removed. The suffix begins with and includes the last . character in the filename after the last directory separator and extends until the end of the name. If no . character is after the last directory separator, then the file name is left unchanged (i.e. it was already without a suffix) but the function returns false.
Definition at line 398 of file Unix/Path.cpp. References isDirectory(). Referenced by llvm::sys::IsLibrary(), and llvm::IsLibrary(). |
|
Determines if the path is an executable file in the file system. This function determines if the path name references an executable file in the file system. Unlike isFile and isDirectory, this function actually checks for the existence and executability (by the current program) of the file.
Definition at line 228 of file Unix/Path.cpp. Referenced by llvm::sys::Program::ExecuteAndWait(), and llvm::sys::Program::FindProgramByName(). |
|
Determines if the path is a file or directory in the file system. This function determines if the path name references an existing file or directory in the file system. Unlike isFile and isDirectory, this function actually checks for the existence of the file or directory.
Definition at line 213 of file Unix/Path.cpp. Referenced by llvm::Archive::addFileBefore(), destroyDirectory(), llvm::ArchiveMember::replaceWith(), and llvm::Archive::writeToDisk(). |
|
Returns the path as a std::string. This function returns the current contents of the path as a std::string. This allows the underlying path string to be manipulated by other software.
Definition at line 325 of file Path.h. Referenced by llvm::Archive::addFileBefore(), llvm::sys::Program::ExecuteAndWait(), llvm::Archive::fillHeader(), llvm::Archive::findModuleDefiningSymbol(), llvm::Archive::findModulesDefiningSymbols(), llvm::Archive::getAllModules(), llvm::GetBytecodeSymbols(), llvm::ArchiveMember::getMemberSize(), llvm::sys::MappedFile::map(), llvm::sys::RemoveFileOnSignal(), renameFile(), llvm::ArchiveMember::replaceWith(), llvm::Archive::writeMember(), and llvm::Archive::writeToDisk(). |
|
Get the base name of the path. This function strips off the path and suffix of the file name and returns just the basename.
Definition at line 148 of file Unix/Path.cpp. Referenced by llvm::LinkModules(). |
|
Build a list of directory's contents. This function builds a list of paths that are the names of the files and directories in a directory.
Definition at line 271 of file Unix/Path.cpp. References isDirectory(), path, and ThrowErrno(). |
|
Return the dynamic link library suffix. Return the suffix commonly used on file names that contain a shared object, shared archive, or dynamic link library. Such files are linked at runtime into a process and their code images are shared between processes.
Definition at line 52 of file AIX/Path.cpp. Referenced by llvm::sys::IsLibrary(), and llvm::IsLibrary(). |
|
Returns the last component of the path name. This function returns the last component of the path name. If the isDirectory() function would return true then this returns the name of the last directory in the path. If the isFile() function would return true then this function returns the name of the file without any of the preceding directories.
Definition at line 233 of file Unix/Path.cpp. Referenced by llvm::sys::Program::ExecuteAndWait(). |
|
Locate a library in a platform specific manner. Determine the platform-specific location of a library by first searching a list of library paths, then searching a list of "well known" paths for the platform. T
Definition at line 75 of file Unix/Path.cpp. References clear(), E, I, llvm::sys::IsLibrary(), LLVM_LIBDIR, and setDirectory(). |
|
Construct a path to the LLVM installed configuration directory. Construct a path to the LLVM installed configuration directory. The implementation must ensure that this refers to the "etc" directory of the LLVM installation. This is the location where configuration files will be located for a particular installation of LLVM on a machine.
Definition at line 119 of file Unix/Path.cpp. References GetLLVMDefaultConfigDir(), LLVM_ETCDIR, and setDirectory(). |
|
Construct a path to the default LLVM configuration directory. Construct a path to the default LLVM configuration directory. The implementation must ensure that this is a well-known (same on many systems) directory in which llvm configuration files exist. For example, on Unix, the /etc/llvm directory has been selected.
Definition at line 114 of file Unix/Path.cpp. References Path(). Referenced by GetLLVMConfigDir(). |
|
Get the file's magic number.
This function retrieves the first
Definition at line 173 of file Unix/Path.cpp. References isFile(). Referenced by llvm::Archive::addFileBefore(), and llvm::ArchiveMember::replaceWith(). |
|
Construct a path to the root directory of the file system. The root directory is a top level directory above which there are no more directories. For example, on UNIX, the root directory is /. On Windows it is C:\. Other operating systems may have different notions of what the root directory is.
Definition at line 44 of file Unix/Path.cpp. References setDirectory(). Referenced by GetUserHomeDirectory(). |
|
Get file status. This function returns status information about the file. The type of path (file or directory) is updated to reflect the actual contents of the file system. If the file does not exist, false is returned. For other (hard I/O) errors, a std::string is throwing indicating the problem.
Definition at line 255 of file Unix/Path.cpp. References llvm::sys::Path::StatusInfo::fileSize, llvm::sys::TimeValue::fromEpochTime(), llvm::sys::Path::StatusInfo::group, llvm::sys::Path::StatusInfo::isDir, llvm::sys::Path::StatusInfo::mode, llvm::sys::Path::StatusInfo::modTime, ThrowErrno(), and llvm::sys::Path::StatusInfo::user. Referenced by llvm::Archive::addFileBefore(), and llvm::ArchiveMember::replaceWith(). |
|
Construct a path to the first system library directory. Construct a path to the first system library directory. The implementation of Path on a given platform must ensure that this directory both exists and also contains standard system libraries suitable for linking into programs.
Definition at line 104 of file Unix/Path.cpp. References Path(). |
|
Construct a path to the second system library directory. Construct a path to the second system library directory. The implementation of Path on a given platform must ensure that this directory both exists and also contains standard system libraries suitable for linking into programs. Note that the "second" system library directory may or may not be different from the first.
Definition at line 109 of file Unix/Path.cpp. References Path(). |
|
Constrct a path to an new, unique, existing temporary directory. Construct a path to a unique temporary directory that is created in a "standard" place for the operating system. The directory is guaranteed to be created on exit from this function. If the directory cannot be created, the function will throw an exception.
Definition at line 36 of file AIX/Path.cpp. References isValid(), setDirectory(), and ThrowErrno(). |
|
Construct a path to the current user's "home" directory. Construct a path to the current user's home directory. The implementation must use an operating system specific mechanism for determining the user's home directory. For example, the environment variable "HOME" could be used on Unix. If a given operating system does not have the concept of a user's home directory, this static constructor must provide the same result as GetRootDirectory.
Definition at line 127 of file Unix/Path.cpp. References GetRootDirectory(), and setDirectory(). |
|
Determine if file has a specific magic number.
This function opens the file associated with the path name provided by the Path object and reads its magic number. If the magic number at the start of the file matches
Definition at line 159 of file Unix/Path.cpp. Referenced by isArchive(). |
|
Determine if the path references an archive file. This function determines if the path name in the object references an archive file by looking at its magic number.
Definition at line 205 of file Unix/Path.cpp. References hasMagicNumber(), and readable(). |
|
Determine if the path references a bytecode file. This function determines if the path name in the object references an LLVM Bytecode file by looking at its magic number.
Definition at line 192 of file Unix/Path.cpp. References ThrowErrno(). |
|
Determines if the path name references a directory. This function determines if the path name in this object is intended to reference a legal directory name (as opposed to a file name). This function does not verify anything with the file system, it merely determines if the syntax of the path represents a directory name or not.
Definition at line 143 of file Unix/Path.cpp. References isValid(). Referenced by appendFile(), appendSuffix(), createDirectory(), destroyDirectory(), elideFile(), elideSuffix(), getDirectoryContents(), and llvm::sys::RemoveDirectoryOnSignal(). |
|
Determines if the path name is empty (invalid). This function determines if the contents of the path name are empty. That is, the path has a zero length.
Definition at line 228 of file Path.h. Referenced by llvm::LinkModules(). |
|
Determines if the path name references a file. This function determines if the path name in this object is intended to reference a legal file name (as opposed to a directory name). This function does not verify anything with the file system, it merely determines if the syntax of the path represents a file name or not.
Definition at line 138 of file Unix/Path.cpp. References isValid(). Referenced by appendDirectory(), createFile(), createTemporaryFile(), destroyFile(), elideDirectory(), getMagicNumber(), renameFile(), and setStatusInfo(). |
|
Determines if the path references the root directory. This function determines if the path name in this object references the root (top level directory) of the file system. The details of what is considered the "root" may vary from system to system so this method will do the necessary checking.
|
|
Determine if a path is syntactically valid or not.
This function will use an operating system specific algorithm to determine if the current value of
Definition at line 27 of file AIX/Path.cpp. Referenced by appendDirectory(), appendFile(), appendSuffix(), GetTemporaryDirectory(), isDirectory(), isFile(), setDirectory(), and setFile(). |
|
Inequality Operator.
Compares
Definition at line 196 of file Path.h. References path. |
|
Less Than Operator.
Determines if
Definition at line 207 of file Path.h. References path. |
|
Assignment Operator.
Makes a copy of
Definition at line 179 of file Path.h. References path. |
|
Equality Operator.
Compares
Definition at line 188 of file Path.h. References path. |
|
Determines if the path is a readable file or directory in the file system. This function determines if the path name references a readable file or directory in the file system. Unlike isFile and isDirectory, this function actually checks for the existence and readability (by the current program) of the file or directory.
Definition at line 218 of file Unix/Path.cpp. Referenced by isArchive(), llvm::sys::IsLibrary(), and llvm::IsLibrary(). |
|
Rename one file as another.
This method renames the file referenced by
Definition at line 522 of file Unix/Path.cpp. References c_str(), get(), isFile(), and ThrowErrno(). Referenced by llvm::Archive::writeToDisk(). |
|
Set a full path from a std::string.
This method attempts to set the Path object to
Definition at line 298 of file Unix/Path.cpp. References isValid(), and path. Referenced by llvm::sys::Program::FindProgramByName(), GetLibraryPath(), GetLLVMConfigDir(), GetRootDirectory(), GetTemporaryDirectory(), and GetUserHomeDirectory(). |
|
Set a full path from a std::string.
This method attempts to set the Path object to
Definition at line 314 of file Unix/Path.cpp. References isValid(), and path. Referenced by llvm::sys::Program::FindProgramByName(), llvm::LinkModules(), and llvm::Archive::parseMemberHeader(). |
|
Set file times and mode.
This method sets the access time, modification time, and permission mode of the file associated with
Definition at line 530 of file Unix/Path.cpp. References isFile(), llvm::sys::Path::StatusInfo::mode, llvm::sys::Path::StatusInfo::modTime, ThrowErrno(), and llvm::sys::TimeValue::toPosixTime(). |
|
Determines if the path is a writable file or directory in the file system. This function determines if the path name references a writable file or directory in the file system. Unlike isFile and isDirectory, this function actually checks for the existence and writability (by the current program) of the file or directory.
Definition at line 223 of file Unix/Path.cpp. |