libwreport  3.6
Data Structures | Public Member Functions
wreport::sys::Path Struct Reference

Wrap a path on the file system opened with O_PATH. More...

#include <sys.h>

Inheritance diagram for wreport::sys::Path:
wreport::sys::NamedFileDescriptor wreport::sys::FileDescriptor

Data Structures

struct  iterator
 Iterator for directory entries. More...
 

Public Member Functions

 Path (const char *pathname, int flags=0)
 Open the given pathname with flags | O_PATH.
 
 Path (const std::string &pathname, int flags=0)
 Open the given pathname with flags | O_PATH.
 
 Path (Path &parent, const char *pathname, int flags=0)
 Open the given pathname calling parent.openat, with flags | O_PATH.
 
 Path (const Path &)=delete
 
 Path (Path &&)=default
 
Pathoperator= (const Path &)=delete
 
Pathoperator= (Path &&)=default
 
 ~Path ()
 The destructor closes the file descriptor, but does not check errors on ::close(). More...
 
DIR * fdopendir ()
 
iterator begin ()
 Begin iterator on all directory entries.
 
iterator end ()
 End iterator on all directory entries.
 
int openat (const char *pathname, int flags, mode_t mode=0777)
 
void fstatat (const char *pathname, struct stat &st)
 
void lstatat (const char *pathname, struct stat &st)
 fstatat with the AT_SYMLINK_NOFOLLOW flag set
 
void unlinkat (const char *pathname)
 
void rmdirat (const char *pathname)
 unlinkat with the AT_REMOVEDIR flag set
 
void rmtree ()
 Delete the directory pointed to by this Path, with all its contents. More...
 
- Public Member Functions inherited from wreport::sys::NamedFileDescriptor
 NamedFileDescriptor (int fd, const std::string &pathname)
 
 NamedFileDescriptor (NamedFileDescriptor &&)
 
NamedFileDescriptoroperator= (NamedFileDescriptor &&)
 
 NamedFileDescriptor (const NamedFileDescriptor &o)=default
 
NamedFileDescriptoroperator= (const NamedFileDescriptor &o)=default
 
virtual void throw_error (const char *desc)
 Throw an exception based on errno and the given message. More...
 
virtual void throw_runtime_error (const char *desc)
 Throw a runtime_error unrelated from errno. More...
 
const std::string & name () const
 Return the file pathname.
 
- Public Member Functions inherited from wreport::sys::FileDescriptor
 FileDescriptor (FileDescriptor &&o)
 
 FileDescriptor (int fd)
 
 FileDescriptor (const FileDescriptor &o)=default
 
FileDescriptoroperator= (const FileDescriptor &o)=default
 
void close ()
 
void fstat (struct stat &st)
 
void fchmod (mode_t mode)
 
int dup ()
 
size_t read (void *buf, size_t count)
 
void read_all_or_throw (void *buf, size_t count)
 Read all the data into buf, throwing runtime_error in case of a partial read.
 
size_t write (const void *buf, size_t count)
 
template<typename Container >
size_t write (const Container &c)
 
void write_all_or_retry (const void *buf, size_t count)
 Write all the data in buf, retrying partial writes.
 
template<typename Container >
void write_all_or_retry (const Container &c)
 
void write_all_or_throw (const void *buf, size_t count)
 Write all the data in buf, throwing runtime_error in case of a partial write.
 
template<typename Container >
void write_all_or_throw (const Container &c)
 
off_t lseek (off_t offset, int whence=SEEK_SET)
 
size_t pread (void *buf, size_t count, off_t offset)
 
size_t pwrite (const void *buf, size_t count, off_t offset)
 
template<typename Container >
size_t pwrite (const Container &c, off_t offset)
 
void ftruncate (off_t length)
 
MMap mmap (size_t length, int prot, int flags, off_t offset=0)
 
 operator int () const
 

Additional Inherited Members

- Protected Attributes inherited from wreport::sys::NamedFileDescriptor
std::string pathname
 
- Protected Attributes inherited from wreport::sys::FileDescriptor
int fd = -1
 

Detailed Description

Wrap a path on the file system opened with O_PATH.

Constructor & Destructor Documentation

◆ ~Path()

wreport::sys::Path::~Path ( )

The destructor closes the file descriptor, but does not check errors on ::close().

In normal program flow, it is a good idea to explicitly call Path::close() in places where it can throw safely.

Member Function Documentation

◆ rmtree()

void wreport::sys::Path::rmtree ( )

Delete the directory pointed to by this Path, with all its contents.

The path must point to a directory.


The documentation for this struct was generated from the following file: