#include <streambuf_tmpnam.h>
Inheritance diagram for rpa::filgen_mkstemp_base:
Public Member Functions | |
void | open (const char *filNam) |
int | operator() (void) const |
void | close (const char *filNam) |
Private Attributes | |
int | _fd |
char | _filename [FILENAME_MAX] |
void rpa::filgen_mkstemp_base::close | ( | const char * | filNam | ) |
Because the file is created and opened in this class, it must be closed and removed here too.
void rpa::filgen_mkstemp_base::open | ( | const char * | filNam | ) |
The mkstemp() function replaces the contents of the string pointed to by template by a unique file name, and returns a file descriptor for the file open for reading and writing. The function thus prevents any possible race condition between testing whether the file exists and opening it for use. The string in template should look like a file name with six trailing 'X's; mkstemp() replaces each 'X' with a character from the portable file name character set. The characters are chosen such that the resulting name does not duplicate the name of an existing file.
We should theoretically ensure that 'umask' is '0600', or that 'mkstemp' fixed this security hole.
int rpa::filgen_mkstemp_base::operator() | ( | void | ) | const [inline] |
The inline code is smaller and faster than a method call. This method can and must be called without side effects. Hence 'const'.
Paranoid check, to detect erratic pointers, etc... ;);)
int rpa::filgen_mkstemp_base::_fd [private] |
char rpa::filgen_mkstemp_base::_filename[FILENAME_MAX] [private] |
The name of the file which is created. It is necessary to store it because, as this class is responsible for its atomic creation (With 'mkstemp'), it is therefore responsible of its removal.