Back to index

courier  0.68.2
tempfile.h
Go to the documentation of this file.
00001 #ifndef       tempfile_h
00002 #define       tempfile_h
00003 
00004 
00005 #include      "config.h"
00006 #include      <sys/types.h>
00007 #include      "exittrap.h"
00008 
00009 #if    HAVE_FCNTL_H
00010 #include      <fcntl.h>
00011 #endif
00012 
00013 #if    SHARED_TEMPDIR
00014 #include      <stdio.h>
00015 #endif
00016 
00018 //
00019 // We need to keep track of all temporary files we've opened, and close
00020 // them if the process terminates.
00021 //
00022 // A TempFile object represents one temporary file currently in use.
00023 // Open() method, if succesfull, returns a file descriptor, and saves
00024 // the filename internally in the object.
00025 // It is necessary to call Close() to close the descriptor (also saved
00026 // internally) in order to mark the temporary file as no longer being
00027 // in use.  Close() will automatically delete the file.
00028 //
00030 
00031 class TempFile : public ExitTrap {
00032 
00033 protected:
00034        void   cleanup();
00035        void   forked();
00036 
00037 #if    SHARED_TEMPDIR
00038        FILE   *fp;          /* tmpfile() output */
00039 #endif
00040        char   *filename;
00041        int    fd;
00042 
00043        int    do_remove;
00044 public:
00045        TempFile();
00046        ~TempFile();
00047        int Open(const char *, int, mode_t=0666);
00048 #if    SHARED_TEMPDIR
00049        int Open();
00050 #endif
00051 
00052 protected:
00053        void name(const char *);    // Partial initialization
00054        void descriptor(int fd_) { fd=fd_; }
00055 public:
00056        void Close();
00057 } ;
00058 
00059 #endif