Back to index

courier  0.68.2
Functions | Variables
comtmpfile2.c File Reference
#include "courier_lib_config.h"
#include "courier.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>

Go to the source code of this file.

Functions

char * mktmpfilename ()

Variables

static const char base64 [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-,"

Function Documentation

char* mktmpfilename ( )

Definition at line 34 of file comtmpfile2.c.

{
       unsigned long seed;
       int i;
       int fd;
       char filename_buf[64];

#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/courier.");

              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)
              {
                     char *p;

                     close(fd);

                     p=strdup(filename_buf);
                     if (!p)
                            unlink(filename_buf);
                     return (p);
              }

              if (errno != EEXIST)
                     break;
       }
       return (NULL);
}

Here is the call graph for this function:


Variable Documentation

const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-," [static]

Definition at line 31 of file comtmpfile2.c.