libwreport  3.40
Public Member Functions | Protected Attributes
wreport::sys::Tempfile Class Reference

Open a temporary file. More...

#include <sys.h>

Inheritance diagram for wreport::sys::Tempfile:
wreport::sys::File wreport::sys::ManagedNamedFileDescriptor wreport::sys::NamedFileDescriptor wreport::sys::FileDescriptor

Public Member Functions

 Tempfile (const std::filesystem::path &prefix)
 
 Tempfile (const std::string &prefix)
 
 Tempfile (const char *prefix)
 
void unlink_on_exit (bool val)
 Change the unlink-on-exit behaviour.
 
void unlink ()
 Unlink the file right now.
 
- Public Member Functions inherited from wreport::sys::File
 File (File &&)=default
 
 File (const File &)=delete
 
 File (const std::filesystem::path &path)
 Create an unopened File object for the given pathname.
 
 File (const char *path)
 
 File (const std::string &path)
 
 File (const std::filesystem::path &path, int flags, mode_t mode=0777)
 Wrapper around open(2)
 
Fileoperator= (const File &)=delete
 
Fileoperator= (File &&)=default
 
void open (int flags, mode_t mode=0777)
 Wrapper around open(2)
 
bool open_ifexists (int flags, mode_t mode=0777)
 Wrap open(2) and return false instead of throwing an exception if open fails with ENOENT.
 
 ManagedNamedFileDescriptor (ManagedNamedFileDescriptor &&)=default
 
 ManagedNamedFileDescriptor (const ManagedNamedFileDescriptor &)=delete
 
- Public Member Functions inherited from wreport::sys::ManagedNamedFileDescriptor
 ManagedNamedFileDescriptor (ManagedNamedFileDescriptor &&)=default
 
 ManagedNamedFileDescriptor (const ManagedNamedFileDescriptor &)=delete
 
 ~ManagedNamedFileDescriptor ()
 The destructor closes the file descriptor, but does not check errors on ::close(). More...
 
ManagedNamedFileDescriptoroperator= (const ManagedNamedFileDescriptor &)=delete
 
ManagedNamedFileDescriptoroperator= (ManagedNamedFileDescriptor &&)
 
 NamedFileDescriptor (int fd, const std::filesystem::path &path)
 
 NamedFileDescriptor (NamedFileDescriptor &&)
 
 NamedFileDescriptor (const NamedFileDescriptor &o)=default
 
- Public Member Functions inherited from wreport::sys::NamedFileDescriptor
 NamedFileDescriptor (int fd, const std::filesystem::path &path)
 
 NamedFileDescriptor (NamedFileDescriptor &&)
 
NamedFileDescriptoroperator= (NamedFileDescriptor &&)
 
 NamedFileDescriptor (const NamedFileDescriptor &o)=default
 
NamedFileDescriptoroperator= (const NamedFileDescriptor &o)=default
 
virtual void throw_error (const char *desc) override
 Throw an exception based on errno and the given message. More...
 
virtual void throw_runtime_error (const char *desc) override
 Throw a runtime_error unrelated from errno. More...
 
std::string name () const
 Return the file pathname.
 
const std::filesystem::path & path () const
 
- Public Member Functions inherited from wreport::sys::FileDescriptor
 FileDescriptor (FileDescriptor &&o)
 
 FileDescriptor (int fd)
 
 FileDescriptor (const FileDescriptor &o)=default
 
FileDescriptoroperator= (const FileDescriptor &o)=default
 
bool is_open () const
 Check if the file descriptor is open (that is, if it is not -1)
 
void close ()
 Close the file descriptor, setting its value to -1. More...
 
void fstat (struct stat &st)
 
void fchmod (mode_t mode)
 
void futimens (const ::timespec ts[2])
 
void fsync ()
 
void fdatasync ()
 
int dup ()
 
size_t read (void *buf, size_t count)
 
bool read_all_or_retry (void *buf, size_t count)
 Read count bytes into bufr, retrying partial reads, stopping at EOF. More...
 
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)
 
bool ofd_setlk (::flock &)
 Open file description locks F_OFD_SETLK operation. More...
 
bool ofd_setlkw (::flock &, bool retry_on_signal=true)
 Open file description locks F_OFD_SETLKW operation. More...
 
bool ofd_getlk (::flock &)
 Open file description locks F_OFD_GETLK operation. More...
 
int getfl ()
 Get open flags for the file.
 
void setfl (int flags)
 Set open flags for the file.
 
 operator int () const
 

Protected Attributes

bool m_unlink_on_exit = true
 
- Protected Attributes inherited from wreport::sys::NamedFileDescriptor
std::filesystem::path path_
 
- Protected Attributes inherited from wreport::sys::FileDescriptor
int fd = -1
 

Additional Inherited Members

- Static Public Member Functions inherited from wreport::sys::File
static File mkstemp (const std::filesystem::path &prefix)
 
static File mkstemp (const std::string &prefix)
 
static File mkstemp (const char *prefix)
 
static File mkstemp (char *pathname_template)
 

Detailed Description

Open a temporary file.

By default, the temporary file will be deleted when the object is deleted.


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