libept
Namespaces | Macros | Functions
sys.cc File Reference
#include "sys.h"
#include "string.h"
#include <cstddef>
#include <cstring>
#include <exception>
#include <sstream>
#include <system_error>
#include <cerrno>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <alloca.h>

Namespaces

 ept
 String functions.
 
 ept::sys
 

Macros

#define O_PATH   0
 
#define common_stat_body(testfunc)
 

Functions

std::unique_ptr< struct stat > ept::sys::stat (const std::string &pathname)
 stat() the given file and return the struct stat with the results. More...
 
void ept::sys::stat (const std::string &pathname, struct stat &st)
 stat() the given file filling in the given structure. More...
 
bool ept::sys::isdir (const std::string &pathname)
 Returns true if the given pathname is a directory, else false. More...
 
bool ept::sys::isblk (const std::string &pathname)
 Same as isdir but checks for block devices. More...
 
bool ept::sys::ischr (const std::string &pathname)
 Same as isdir but checks for character devices. More...
 
bool ept::sys::isfifo (const std::string &pathname)
 Same as isdir but checks for FIFOs. More...
 
bool ept::sys::islnk (const std::string &pathname)
 Same as isdir but checks for symbolic links. More...
 
bool ept::sys::isreg (const std::string &pathname)
 Same as isdir but checks for regular files. More...
 
bool ept::sys::issock (const std::string &pathname)
 Same as isdir but checks for sockets. More...
 
time_t ept::sys::timestamp (const std::string &file)
 File mtime. More...
 
time_t ept::sys::timestamp (const std::string &file, time_t def)
 File mtime (or def if the file does not exist) More...
 
size_t ept::sys::size (const std::string &file)
 File size. More...
 
size_t ept::sys::size (const std::string &file, size_t def)
 File size (or def if the file does not exist) More...
 
ino_t ept::sys::inode (const std::string &file)
 File inode number. More...
 
ino_t ept::sys::inode (const std::string &file, ino_t def)
 File inode number (or 0 if the file does not exist) More...
 
bool ept::sys::access (const std::string &s, int m)
 access() a filename More...
 
bool ept::sys::exists (const std::string &s)
 Same as access(s, F_OK);. More...
 
std::string ept::sys::getcwd ()
 Get the absolute path of the current working directory. More...
 
std::string ept::sys::abspath (const std::string &pathname)
 Get the absolute path of a file. More...
 
std::string ept::sys::read_file (const std::string &file)
 Read whole file into memory. Throws exceptions on failure. More...
 
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. More...
 
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. More...
 
bool ept::sys::unlink_ifexists (const std::string &file)
 Delete a file if it exists. More...
 
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. More...
 
void ept::sys::mkdir_ifmissing (const char *pathname, mode_t mode=0777)
 Create the given directory, if it does not already exists. More...
 
void ept::sys::mkdir_ifmissing (const std::string &pathname, mode_t mode)
 
void ept::sys::makedirs (const std::string &pathname, mode_t=0777)
 Create all the component of the given directory, including the directory itself. More...
 
std::string ept::sys::which (const std::string &name)
 Compute the absolute path of an executable. More...
 
void ept::sys::unlink (const std::string &pathname)
 Delete the file using unlink() More...
 
void ept::sys::rmdir (const std::string &pathname)
 Remove the directory using rmdir(2) More...
 
void ept::sys::rmtree (const std::string &pathname)
 Delete the directory pathname and all its contents. More...
 

Macro Definition Documentation

◆ common_stat_body

#define common_stat_body (   testfunc)
Value:
struct stat st; \
if (::stat(pathname.c_str(), &st) == -1) { \
if (errno == ENOENT) \
return false; \
else \
throw std::system_error(errno, std::system_category(), "cannot stat " + pathname); \
} \
return testfunc(st.st_mode)
void stat(const std::string &pathname, struct stat &st)
stat() the given file filling in the given structure.
Definition: sys.cc:50

Referenced by ept::sys::isblk(), ept::sys::ischr(), ept::sys::isdir(), ept::sys::isfifo(), ept::sys::islnk(), ept::sys::isreg(), and ept::sys::issock().

◆ O_PATH

#define O_PATH   0

Referenced by ept::sys::Path::Path().