#include <Filesystem.hpp>
|
| | SafeFileWriter (const char *const pathname, const char *const mode="w") |
| | ~SafeFileWriter () |
| bool | ok () const noexcept |
| size_t | write (const void *const ptr, const size_t size, const size_t nmemb=1) const |
|
|
String | filename |
|
FILE *const | fd |
Handy class to help write files in a safe way, which does:
- open pathname + ".tmp" instead of opening a file directly (so partial writes are safe)
- on close, flush data to disk and rename file to remove ".tmp"
To use it, create a local variable (on the stack) and call ok() or manually check fd variable.
file.write("Success!");
SafeFileWriter(const char *const pathname, const char *const mode="w")
Definition Filesystem.hpp:74
◆ SafeFileWriter()
| SafeFileWriter::SafeFileWriter |
( |
const char *const | pathname, |
|
|
const char *const | mode = "w" ) |
|
inline |
Constructor, opening pathname + ".tmp" for writing.
◆ ~SafeFileWriter()
| SafeFileWriter::~SafeFileWriter |
( |
| ) |
|
|
inline |
Destructor, will flush file data contents, close and rename file.
◆ ok()
| bool SafeFileWriter::ok |
( |
| ) |
const |
|
inlinenoexcept |
Check if the file was opened successfully.
◆ write()
| size_t SafeFileWriter::write |
( |
const void *const | ptr, |
|
|
const size_t | size, |
|
|
const size_t | nmemb = 1 ) const |
|
inline |
Wrapper around fwrite, purely for convenience.
The documentation for this struct was generated from the following file: