KJB
|
This class safely opens a temporary file in TEMP_DIR (usually /tmp). More...
#include <l_stdio_wrap.h>
Public Member Functions | |
Temporary_File () | |
int | close () |
close file before destruction; rarely needed; safe to do twice. More... | |
const std::string & | get_filename () const |
Public Member Functions inherited from kjb::File_Ptr | |
virtual | ~File_Ptr () |
dtor can simply call close() because closing a null ptr is OK. More... | |
operator FILE * () const | |
transparently use this object wherever a FILE* is used! More... | |
Additional Inherited Members | |
Protected Member Functions inherited from kjb::File_Ptr | |
void | throw_io_error (const std::string &pathname, const char *mode) |
this is what we do when things go terribly wrong More... | |
File_Ptr (const std::string &pathname, const char *mode) | |
ctor needs the pathname and a mode; mode is set by derived class More... | |
File_Ptr () | |
default ctor wraps a null pointer (to set up a later swap maybe) More... | |
void | swap (File_Ptr &that) |
swap the contents of two wrappers More... | |
This class safely opens a temporary file in TEMP_DIR (usually /tmp).
This class is a wrapper around Unix system call mkstemp which securely generates a unique temporary filename and opens the file too, so that there is no race condition.
This object deletes its underlying file only when the object is destroyed. If the program aborts, the temporary file might not be deleted. In that case, you might want to clean up files called /tmp/libkjb-XXXXXX manually, where XXXXXX denotes any arbitrary combination of six printable characters.
Example usage:
|
inline |
|
inlinevirtual |
close file before destruction; rarely needed; safe to do twice.
Reimplemented from kjb::File_Ptr.
|
inline |