libept
|
Classes | |
class | File |
open(2) file descriptors More... | |
class | FileDescriptor |
Common operations on file descriptors. More... | |
class | MMap |
Wraps a mmapped memory area, unmapping it on destruction. More... | |
class | NamedFileDescriptor |
File descriptor with a name. More... | |
struct | Path |
Wrap a path on the file system opened with O_PATH. More... | |
Functions | |
std::unique_ptr< struct stat > | stat (const std::string &pathname) |
stat() the given file and return the struct stat with the results. More... | |
void | stat (const std::string &pathname, struct stat &st) |
stat() the given file filling in the given structure. More... | |
bool | isdir (const std::string &pathname) |
Returns true if the given pathname is a directory, else false. More... | |
bool | isblk (const std::string &pathname) |
Same as isdir but checks for block devices. More... | |
bool | ischr (const std::string &pathname) |
Same as isdir but checks for character devices. More... | |
bool | isfifo (const std::string &pathname) |
Same as isdir but checks for FIFOs. More... | |
bool | islnk (const std::string &pathname) |
Same as isdir but checks for symbolic links. More... | |
bool | isreg (const std::string &pathname) |
Same as isdir but checks for regular files. More... | |
bool | issock (const std::string &pathname) |
Same as isdir but checks for sockets. More... | |
time_t | timestamp (const std::string &file) |
File mtime. More... | |
time_t | timestamp (const std::string &file, time_t def) |
File mtime (or def if the file does not exist) More... | |
size_t | size (const std::string &file) |
File size. More... | |
size_t | size (const std::string &file, size_t def) |
File size (or def if the file does not exist) More... | |
ino_t | inode (const std::string &file) |
File inode number. More... | |
ino_t | inode (const std::string &file, ino_t def) |
File inode number (or 0 if the file does not exist) More... | |
bool | access (const std::string &s, int m) |
access() a filename More... | |
bool | exists (const std::string &s) |
Same as access(s, F_OK);. More... | |
std::string | getcwd () |
Get the absolute path of the current working directory. More... | |
std::string | abspath (const std::string &pathname) |
Get the absolute path of a file. More... | |
std::string | read_file (const std::string &file) |
Read whole file into memory. Throws exceptions on failure. More... | |
void | write_file (const std::string &file, const std::string &data, mode_t mode=0777) |
Write data to file, replacing existing contents if it already exists. More... | |
void | write_file_atomically (const std::string &file, const std::string &data, mode_t mode=0777) |
Write data to file, replacing existing contents if it already exists. More... | |
bool | unlink_ifexists (const std::string &file) |
Delete a file if it exists. More... | |
bool | rename_ifexists (const std::string &src, const std::string &dst) |
Move src to dst, without raising exception if src does not exist. More... | |
void | mkdir_ifmissing (const char *pathname, mode_t mode=0777) |
Create the given directory, if it does not already exists. More... | |
void | mkdir_ifmissing (const std::string &pathname, mode_t mode) |
void | makedirs (const std::string &pathname, mode_t=0777) |
Create all the component of the given directory, including the directory itself. More... | |
std::string | which (const std::string &name) |
Compute the absolute path of an executable. More... | |
void | unlink (const std::string &pathname) |
Delete the file using unlink() More... | |
void | rmdir (const std::string &pathname) |
Remove the directory using rmdir(2) More... | |
void | rmtree (const std::string &pathname) |
Delete the directory pathname and all its contents. More... | |
std::string ept::sys::abspath | ( | const std::string & | pathname | ) |
Get the absolute path of a file.
References getcwd(), ept::str::joinpath(), and ept::str::normpath().
Referenced by which().
bool ept::sys::access | ( | const std::string & | s, |
int | m | ||
) |
bool ept::sys::exists | ( | const std::string & | file | ) |
Same as access(s, F_OK);.
References access().
Referenced by ept::debtags::Debtags::Debtags(), ept::debtags::Vocabulary::load(), and ept::tests::ActualFunction::throws().
std::string ept::sys::getcwd | ( | ) |
ino_t ept::sys::inode | ( | const std::string & | file, |
ino_t | def | ||
) |
bool ept::sys::isblk | ( | const std::string & | pathname | ) |
Same as isdir but checks for block devices.
References common_stat_body.
Referenced by ept::sys::Path::iterator::operator->().
bool ept::sys::ischr | ( | const std::string & | pathname | ) |
Same as isdir but checks for character devices.
References common_stat_body.
Referenced by ept::sys::Path::iterator::operator->().
bool ept::sys::isdir | ( | const std::string & | pathname | ) |
Returns true if the given pathname is a directory, else false.
It also returns false if the pathname does not exist.
References common_stat_body.
Referenced by ept::sys::Path::iterator::operator->().
bool ept::sys::isfifo | ( | const std::string & | pathname | ) |
Same as isdir but checks for FIFOs.
References common_stat_body.
Referenced by ept::sys::Path::iterator::operator->().
bool ept::sys::islnk | ( | const std::string & | pathname | ) |
Same as isdir but checks for symbolic links.
References common_stat_body.
Referenced by ept::sys::Path::iterator::operator->().
bool ept::sys::isreg | ( | const std::string & | pathname | ) |
Same as isdir but checks for regular files.
References common_stat_body.
Referenced by ept::sys::Path::iterator::operator->().
bool ept::sys::issock | ( | const std::string & | pathname | ) |
Same as isdir but checks for sockets.
References common_stat_body.
Referenced by ept::sys::Path::iterator::operator->().
void ept::sys::makedirs | ( | const std::string & | pathname, |
mode_t | = 0777 |
||
) |
Create all the component of the given directory, including the directory itself.
References ept::str::dirname(), and mkdir_ifmissing().
void ept::sys::mkdir_ifmissing | ( | const char * | pathname, |
mode_t | mode = 0777 |
||
) |
Create the given directory, if it does not already exists.
It will complain if the given pathname already exists but is not a directory.
Referenced by makedirs().
void ept::sys::mkdir_ifmissing | ( | const std::string & | pathname, |
mode_t | mode | ||
) |
std::string ept::sys::read_file | ( | const std::string & | file | ) |
Read whole file into memory. Throws exceptions on failure.
References ept::sys::FileDescriptor::fstat(), ept::sys::FileDescriptor::mmap(), and stat().
bool ept::sys::rename_ifexists | ( | const std::string & | src, |
const std::string & | dst | ||
) |
Move src to dst, without raising exception if src does not exist.
void ept::sys::rmdir | ( | const std::string & | pathname | ) |
Remove the directory using rmdir(2)
Referenced by ept::sys::Path::rmtree().
void ept::sys::rmtree | ( | const std::string & | pathname | ) |
Delete the directory pathname and all its contents.
References ept::sys::Path::rmtree().
Referenced by ept::sys::Path::iterator::operator->().
size_t ept::sys::size | ( | const std::string & | file | ) |
File size.
References stat().
Referenced by getcwd(), ept::apt::RecordParser::index(), and ept::apt::localityCompare().
size_t ept::sys::size | ( | const std::string & | file, |
size_t | def | ||
) |
std::unique_ptr< struct stat > ept::sys::stat | ( | const std::string & | pathname | ) |
stat() the given file and return the struct stat with the results.
If the file does not exist, return NULL. Raises exceptions in case of errors.
References res.
Referenced by inode(), ept::sys::Path::iterator::isblk(), ept::sys::Path::iterator::ischr(), ept::sys::Path::iterator::isdir(), ept::sys::Path::iterator::isfifo(), ept::sys::Path::iterator::islnk(), ept::sys::Path::iterator::isreg(), ept::sys::Path::iterator::issock(), ept::sys::Path::iterator::operator->(), read_file(), size(), stat(), and timestamp().
void ept::sys::stat | ( | const std::string & | pathname, |
struct stat & | st | ||
) |
time_t ept::sys::timestamp | ( | const std::string & | file | ) |
File mtime.
References stat().
Referenced by ept::debtags::Debtags::load(), and ept::debtags::Vocabulary::load().
time_t ept::sys::timestamp | ( | const std::string & | file, |
time_t | def | ||
) |
void ept::sys::unlink | ( | const std::string & | pathname | ) |
Delete the file using unlink()
Referenced by unlink_ifexists().
bool ept::sys::unlink_ifexists | ( | const std::string & | file | ) |
Delete a file if it exists.
If it does not exist, do nothing.
References unlink().
std::string ept::sys::which | ( | const std::string & | name | ) |
Compute the absolute path of an executable.
If name is specified as a partial path, it ensures it is made absolute. If name is not specified as a path, it looks for the executable in $PATH and return its absolute pathname.
References abspath(), access(), ept::str::joinpath(), and ept::sys::NamedFileDescriptor::name().
void ept::sys::write_file | ( | const std::string & | file, |
const std::string & | data, | ||
mode_t | mode = 0777 |
||
) |
Write data to file, replacing existing contents if it already exists.
New files are created with the given permission mode, honoring umask. Permissions of existing files do not change.
References ept::sys::FileDescriptor::close(), and ept::sys::FileDescriptor::write_all().
void ept::sys::write_file_atomically | ( | const std::string & | file, |
const std::string & | data, | ||
mode_t | mode = 0777 |
||
) |
Write data to file, replacing existing contents if it already exists.
Files are created with the given permission mode, honoring umask. If the file already exists, its mode is ignored.
Data is written to a temporary file, then moved to its final destination, to ensure an atomic operation.
References ept::sys::FileDescriptor::close(), ept::sys::FileDescriptor::fchmod(), ept::sys::File::mkstemp(), ept::sys::NamedFileDescriptor::name(), and ept::sys::FileDescriptor::write_all().
Referenced by ept::debtags::Vocabulary::write().