ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/mktemp.c
Revision: 2.6
Committed: Fri Nov 5 03:31:36 2004 UTC (19 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.5: +1 -1 lines
State: FILE REMOVED
Error occurred while calculating annotation data.
Log Message:
Removed unused programs and files from distribution (sources to CVS attic)

File Contents

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