10 #ifndef SRC_INCLUDE_SMASH_FILE_H_
11 #define SRC_INCLUDE_SMASH_FILE_H_
47 if (0 != std::fclose(f)) {
48 throw std::runtime_error(std::strerror(errno));
61 using FilePtr = std::unique_ptr<std::FILE, FileDeleter>;
83 const std::string& mode);
115 FilePtr fopen(
const std::filesystem::path& filename,
const std::string& mode);
A RAII type to replace std::FILE *.
~RenamingFilePtr()
Close the file and rename it.
std::filesystem::path filename_unfinished_
Path of the unfinished file.
std::filesystem::path filename_
Path of the finished file.
FILE * get()
Get the underlying FILE* pointer.
RenamingFilePtr(const std::filesystem::path &filename, const std::string &mode)
Construct a RenamingFilePtr.
int uncaught_exceptions_
Number of uncaught exceptions at the time when the object is created.
FILE * file_
Internal file pointer.
std::unique_ptr< std::FILE, FileDeleter > FilePtr
A RAII type to replace std::FILE *.
FilePtr fopen(const std::filesystem::path &filename, const std::string &mode)
Open a file with given mode.
FileDeleter is the deleter class for std::unique_ptr of std::FILE.
constexpr FileDeleter()=default
The class has no members, so this is a noop.
void operator()(std::FILE *f) const
Frees the std::FILE resource if it is non-zero.