File: tempfile.h

package info (click to toggle)
maildrop 0.54a-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 872 kB
  • ctags: 883
  • sloc: cpp: 8,469; ansic: 658; sh: 327; makefile: 82
file content (56 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* DSTART                                                                    */
/*                                                                           */
/*           maildrop - mail delivery agent with filtering abilities         */
/*                                                                           */
/*  Copyright 1998, Double Precision Inc.                                    */
/*                                                                           */
/*  This program is distributed under the terms of the GNU General Public    */
/*  License. See COPYING for additional information.                         */
/* DEND                                                                      */
#ifndef	tempfile_h
#define	tempfile_h

static const char tempfile_h_rcsid[]="$Id: tempfile.h 1.1 1998/04/17 00:08:53 mrsam Exp $";

#include	<sys/types.h>
#include	"autoconf.h"
#include	"exittrap.h"

#if	HAVE_FCNTL_H
#include	<fcntl.h>
#endif

///////////////////////////////////////////////////////////////////////////
//
// We need to keep track of all temporary files we've opened, and close
// them if the process terminates.
//
// A TempFile object represents one temporary file currently in use.
// Open() method, if succesfull, returns a file descriptor, and saves
// the filename internally in the object.
// It is necessary to call Close() to close the descriptor (also saved
// internally) in order to mark the temporary file as no longer being
// in use.  Close() will automatically delete the file.
//
///////////////////////////////////////////////////////////////////////////

class TempFile : public ExitTrap {

protected:
	void	cleanup();
	void	forked();

	char	*filename;
	int	fd;

	int	do_remove;
public:
	TempFile();
	~TempFile();
	int Open(const char *, int, mode_t=0666);
	void name(const char *);	// Partial initialization
	void descriptor(int fd_) { fd=fd_; }
	void Close();
} ;

#endif