ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/mktemp.c
Revision: 2.2
Committed: Tue Nov 24 16:29:46 1992 UTC (31 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +2 -2 lines
Log Message:
eliminated dependency on standard.h

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 greg 2.2 #define NULL 0
12 greg 2.1
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 greg 2.2 if (access(template, 0) == -1)
39 greg 2.1 return(template); /* found unique name */
40     return(NULL); /* failure! */
41     }