Back to index

courier  0.68.2
Defines | Functions
tempname.h File Reference
#include "config.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TEMPNAMEBUFSIZE   64

Functions

int libmail_tempfile (char *)

Define Documentation

#define TEMPNAMEBUFSIZE   64

Definition at line 15 of file tempname.h.


Function Documentation

int libmail_tempfile ( char *  )

Definition at line 29 of file tempname.c.

{
       unsigned long seed;
       int i;
       int fd;

#if HAVE_GETTIMEOFDAY
       struct timeval tv;

       gettimeofday(&tv, NULL);

       seed=tv.tv_sec;
       seed ^= tv.tv_usec << 16;
#else
       time_t t;

       time(&t);
       seed=t;
#endif
       seed ^= getpid();

       for (i=0; i<1000; i++, seed += 5000)
       {
              char *p;
              unsigned long n;

              strcpy(filename_buf, "/tmp/mimegpg.");

              p=filename_buf + strlen(filename_buf);

              n=seed;
              *p++=base64[ n % 64 ]; n /= 64;
              *p++=base64[ n % 64 ]; n /= 64;
              *p++=base64[ n % 64 ]; n /= 64;
              *p++=base64[ n % 64 ]; n /= 64;
              *p++=base64[ n % 64 ]; n /= 64;
              *p++=base64[ n % 64 ];
              *p=0;

              if ((fd=open(filename_buf, O_RDWR | O_CREAT | O_EXCL, 0600))
                  >= 0)
                     return (fd);


              if (errno != EEXIST)
                     break;
       }
       return (-1);
}

Here is the caller graph for this function: