ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/mktemp.c
Revision: 2.4
Committed: Tue Feb 25 02:47:21 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.3: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

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