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

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

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)

◆ O_PATH

#define O_PATH   0