edelib  2.1.0
Public Member Functions | List of all members
TempFile Class Reference

Temporary file class. More...

#include <edelib/TempFile.h>

Public Member Functions

 TempFile ()
 ~TempFile ()
bool create (const char *prefix, int mode=0600)
 operator bool (void) const
void unlink (void)
bool close (void)
void set_auto_delete (bool v)
void set_no_close (bool n)
FILE * fstream (void)
const char * name (void) const
int handle (void) const
int status (void) const

Detailed Description

Temporary file class.

TempFile is responsible for creating unique temporary file.

TempFile behaves much as mktemp() or mkstemp() functions: you provide location with templated name, and it will try to create the one, by opening it (like mkstemp()). Templated name ends with XXXXXX. On other hand, if you do not provide XXXXXX-es at the end, TempFile will append them.

This class was greatly inspired by KTempFile from kdelibs because I had no clue how to model it ;)

Constructor & Destructor Documentation

TempFile ( )

Constructor. Does nothing, except setting internal values to invalid state

~TempFile ( )

Destructor. Closes file descriptor too

Member Function Documentation

bool close ( void  )

Closes descriptor

bool create ( const char *  prefix,
int  mode = 0600 

Create file and return creation status. prefix is location where file will be created, with given mode. If file could not be created at all, status() will return errno value for further inspection

FILE* fstream ( void  )

Return FILE object or NULL if create() failed

int handle ( void  ) const

Return file descriptor

const char* name ( void  ) const

Return temporary file name. If create() failed, NULL will be returned

operator bool ( void  ) const

Check if create() was successfull

void set_auto_delete ( bool  v)

If set to true, the file will be deleted when TempFile destructor was called. Default is false

void set_no_close ( bool  n)

If set to true, the file descriptors will not be closed when destructor was called. Default is false

int status ( void  ) const

Return errno status

void unlink ( void  )

Removes the file. If file wasn't created successfully before, it will do nothing

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