ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/mktemp.c
Revision: 2.1
Committed: Mon Oct 5 11:38:00 1992 UTC (31 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 2.1 /* Copyright (c) 1992 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Replacement mktemp(3) function for systems without
9     */
10    
11     #include "standard.h"
12    
13    
14     char *
15     mktemp(template) /* make a unique filename from template */
16     char *template;
17     {
18     register char *tb, *te, *p;
19     int pid;
20     /* find string of 6 (opt) X's */
21     for (te = template; *te; te++)
22     ;
23     while (te > template && te[-1] != 'X')
24     te--;
25     if (te == template)
26     return(template); /* no X's! */
27     for (tb = te; tb > template && tb[-1] == 'X'; tb--)
28     ;
29     if (te-tb > 6) /* only need 6 chars */
30     tb = te-6;
31     pid = getpid(); /* 5 (opt) chars of pid */
32     for (p = te-2; p >= tb; p--) {
33     *p = pid%10 + '0';
34     pid /= 10;
35     }
36     p = te-1; /* final character */
37     for (*p = 'a'; *p <= 'z'; (*p)++)
38     if (access(template, F_OK) == -1)
39     return(template); /* found unique name */
40     return(NULL); /* failure! */
41     }