diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /maildrop/tempfile.C | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'maildrop/tempfile.C')
| -rw-r--r-- | maildrop/tempfile.C | 106 | 
1 files changed, 106 insertions, 0 deletions
| diff --git a/maildrop/tempfile.C b/maildrop/tempfile.C new file mode 100644 index 0000000..6af120c --- /dev/null +++ b/maildrop/tempfile.C @@ -0,0 +1,106 @@ +#include "config.h" +#include	"tempfile.h" +#include	"funcs.h" +#include	"mio.h" + + +TempFile::TempFile() : +#if	SHARED_TEMPDIR +		fp(0), +#endif +		filename(0), fd(-1), do_remove(0) +{ +	constructed(); +} + +TempFile::~TempFile() +{ +	destroying(); +	Close(); +	if (filename) +	{ +		delete[] filename; +		filename=0; +	} +} + +int TempFile::Open(const char *fname, int flags, mode_t mode) +{ +	Close(); +	name(fname); + +	fd=mopen(fname, flags, mode); +	if ( fd < 0 ) +		name(0); +	else +		descriptor(fd); +	return (fd); +} + +#if SHARED_TEMPDIR + +int TempFile::Open() +{ +	Close(); +	fp=tmpfile(); +	if (fp == 0)	return (-1); +	fd=fileno(fp); +	return (fd); +} +#endif + + +void TempFile::name(const char *fname) +{ +	do_remove=0; +	if (filename) +		delete[] filename; +	if (!fname) +	{ +		filename=0; +		return; +	} + +	filename=new char[strlen(fname)+1]; + +	if (!filename)	outofmem(); +	strcpy(filename, fname); +	do_remove=1; +} + +void TempFile::Close() +{ +	if (fd >= 0) +	{ +		close(fd); +		fd= -1; +	} + +#if	SHARED_TEMPDIR +	if (fp) +	{ +		fclose(fp); +		fp=0; +	} +#endif + +	if (do_remove) +	{ +		unlink(filename); +		do_remove=0; +	} +} + +void	TempFile::cleanup() +{ +	Close(); +} + +// When forked, the child process should just close the descriptor, do NOT +// remove the file! + +void	TempFile::forked() +{ +	do_remove=0; +	Close(); +} | 
