Back to index

lightning-sunbird  0.9+nobinonly
Functions
mktemp.c File Reference
#include "watcomfx.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include "mcom_db.h"
#include <unistd.h>

Go to the source code of this file.

Functions

static int _gettemp (char *path, register int *doopen, int extraFlags)
int mkstemp (char *path)
int mkstempflags (char *path, int extraFlags)
char * mktemp (char *path)

Function Documentation

static int _gettemp ( char *  path,
register int doopen,
int  extraFlags 
) [static]

Definition at line 97 of file mktemp.c.

{    
#if !defined(_WINDOWS) || defined(_WIN32)
       extern int errno;                    
#endif
       register char *start, *trv;
       struct stat sbuf;
       unsigned int pid;

       pid = getpid();
       for (trv = path; *trv; ++trv);            /* extra X's get set to 0's */
       while (*--trv == 'X') {
              *trv = (pid % 10) + '0';
              pid /= 10;
       }

       /*
        * check the target directory; if you have six X's and it
        * doesn't exist this runs for a *very* long time.
        */
       for (start = trv + 1;; --trv) {
              char saved;
              if (trv <= path)
                     break;
              saved = *trv;
              if (saved == '/' || saved == '\\') {
                     int rv;
                     *trv = '\0';
                     rv = stat(path, &sbuf);
                     *trv = saved;
                     if (rv)
                            return(0);
                     if (!S_ISDIR(sbuf.st_mode)) {
                            errno = ENOTDIR;
                            return(0);
                     }
                     break;
              }
       }

       for (;;) {
              if (doopen) {
                     if ((*doopen =
                         open(path, O_CREAT|O_EXCL|O_RDWR|extraFlags, 0600)) >= 0)
                            return(1);
                     if (errno != EEXIST)
                            return(0);
              }
              else if (stat(path, &sbuf))
                     return(errno == ENOENT ? 1 : 0);

              /* tricky little algorithm for backward compatibility */
              for (trv = start;;) {
                     if (!*trv)
                            return(0);
                     if (*trv == 'z')
                            *trv++ = 'a';
                     else {
                            if (isdigit(*trv))
                                   *trv = 'a';
                            else
                                   ++*trv;
                            break;
                     }
              }
       }
       /*NOTREACHED*/
}

Here is the caller graph for this function:

int mkstemp ( char *  path)

Definition at line 66 of file mktemp.c.

{
#ifdef XP_OS2
       FILE *temp = tmpfile();

       return (temp ? fileno(temp) : -1);
#else
       int fd;

       return (_gettemp(path, &fd, 0) ? fd : -1);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mkstempflags ( char *  path,
int  extraFlags 
)

Definition at line 80 of file mktemp.c.

{
       int fd;

       return (_gettemp(path, &fd, extraFlags) ? fd : -1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* mktemp ( char *  path)

Definition at line 88 of file mktemp.c.

{
       return(_gettemp(path, (int *)NULL, 0) ? path : (char *)NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function: