1 #ifndef tempfile_h 2 #define tempfile_h 3 4 static const char tempfile_h_rcsid[]="$Id: tempfile.h,v 1.3 1999/09/10 02:10:05 mrsam Exp $"; 5 6 #include <sys/types.h> 7 #include "config.h" 8 #include "exittrap.h" 9 10 #if HAVE_FCNTL_H 11 #include <fcntl.h> 12 #endif 13 14 #if SHARED_TEMPDIR 15 #include <stdio.h> 16 #endif 17 18 /////////////////////////////////////////////////////////////////////////// 19 // 20 // We need to keep track of all temporary files we've opened, and close 21 // them if the process terminates. 22 // 23 // A TempFile object represents one temporary file currently in use. 24 // Open() method, if succesfull, returns a file descriptor, and saves 25 // the filename internally in the object. 26 // It is necessary to call Close() to close the descriptor (also saved 27 // internally) in order to mark the temporary file as no longer being 28 // in use. Close() will automatically delete the file. 29 // 30 /////////////////////////////////////////////////////////////////////////// 31 32 class TempFile : public ExitTrap { 33 34 protected: 35 void cleanup(); 36 void forked(); 37 38 #if SHARED_TEMPDIR 39 FILE *fp; /* tmpfile() output */ 40 #endif 41 char *filename; 42 int fd; 43 44 int do_remove; 45 public: 46 TempFile(); 47 ~TempFile(); 48 int Open(const char *, int, mode_t=0666); 49 #if SHARED_TEMPDIR 50 int Open(); 51 #endif 52 53 protected: 54 void name(const char *); // Partial initialization descriptor(int fd_)55 void descriptor(int fd_) { fd=fd_; } 56 public: 57 void Close(); 58 } ; 59 60 #endif 61