Annotation of coherent/b/lib/libc/gen/tempnam.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Standard I/O Library.
                      3:  * Create a unique name for a temporary file ala SYS V.
                      4:  * Note: this differs from the real SYS V in that we don't limit the
                      5:  * length of the prefix to be five characters for portability reasons.
                      6:  */
                      7: 
                      8: #include <stdio.h>
                      9: 
                     10: #ifdef GEMDOS
                     11: #define        FSPATHSEP       '\\'
                     12: #ifndef        P_tmpdir
                     13: #define        P_tmpdir        "\\tmp"
                     14: #endif
                     15: #endif
                     16: #ifdef DOS
                     17: #define        FSPATHSEP       '\\'
                     18: #ifndef        P_tmpdir
                     19: #define        P_tmpdir        "\\tmp"
                     20: #endif
                     21: #endif
                     22: #ifndef        FSPATHSEP
                     23: #define        FSPATHSEP       '/'
                     24: #endif
                     25: #ifndef        P_tmpdir
                     26: #define        P_tmpdir        "/tmp"
                     27: #endif
                     28: #ifndef        L_tmpnam
                     29: #define        L_tmpnam        64
                     30: #endif
                     31: #define        TEMPLATE        "XXXXXX"
                     32: #define        PREFIX          "t"
                     33: 
                     34: char   *
                     35: tempnam(dir, pfx)
                     36: char   *dir, *pfx;
                     37: {
                     38:        register char *tbp, *stbp;
                     39:        extern  char *mktemp(), *strcpy();
                     40:        extern  char *malloc(), *getenv();
                     41: 
                     42:        if ((stbp = malloc(L_tmpnam)) != NULL) {
                     43:                if (dir == NULL && (dir = getenv("TMPDIR")) == NULL)
                     44:                        dir = P_tmpdir;
                     45:                if (pfx == NULL)
                     46:                        pfx = PREFIX;
                     47:                for (;;) {
                     48:                        tbp = stbp;
                     49:                        strcpy(tbp, dir);
                     50:                        while (*tbp != 0)
                     51:                                ++tbp;
                     52:                        if (tbp > stbp && tbp[-1] != FSPATHSEP)
                     53:                                *tbp++ = FSPATHSEP;
                     54:                        strcpy(tbp, pfx);
                     55:                        while (*tbp != 0)
                     56:                                ++tbp;
                     57:                        strcpy(tbp, TEMPLATE);
                     58:                        mktemp(stbp);
                     59:                        if (access(stbp, 0) == -1)
                     60:                                break;
                     61:                }
                     62:        }
                     63:        return (stbp);
                     64: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.