1 /* RCS $Id: tempnam.c,v 1.1.1.1 2000-09-22 15:33:34 hr Exp $
7 -- temp file name generation routines.
10 -- Dennis Vadura, dvadura@dmake.wticorp.com
13 -- http://dmake.wticorp.com/
16 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
18 -- This program is NOT free software; you can redistribute it and/or
19 -- modify it under the terms of the Software License Agreement Provided
20 -- in the file <distribution-root>/readme/license.txt.
23 -- Use cvs log to obtain detailed change logs.
31 #define max(A,B) (((A)<(B))?(B):(A))
33 extern char *mktemp();
37 static char seed
[4]="AAA";
39 /* BSD stdio.h doesn't define P_tmpdir, so let's do it here */
41 static char *P_tmpdir
= "/tmp";
46 char *dir
; /* use this directory please (if non-NULL) */
47 char *prefix
; /* use this (if non-NULL) as filename prefix */
49 register char *p
, *q
, *tmpdir
;
52 pl
= strlen(P_tmpdir
);
54 if( (tmpdir
= getenv("TMPDIR")) != NULL
) tl
= strlen(tmpdir
);
55 if( dir
!= NULL
) dl
= strlen(dir
);
57 if( (p
= malloc((unsigned)(max(max(dl
,tl
),pl
)+16))) == NULL
)
62 if( (tl
== 0) || (access( cpdir(p
, tmpdir
), 3) != 0) )
63 if( (dl
== 0) || (access( cpdir(p
, dir
), 3) != 0) )
64 if( access( cpdir(p
, P_tmpdir
), 3) != 0 )
65 if( access( cpdir(p
, "/tmp"), 3) != 0 )
68 (void) strcat(p
, "/");
71 *(p
+strlen(p
)+5) = '\0';
72 (void)strncat(p
, prefix
, 5);
75 (void)strcat(p
, seed
);
76 (void)strcat(p
, "XXXXXX");
79 while(*q
== 'Z') *q
++ = 'A';
82 if(*mktemp(p
) == '\0') return(NULL
);
97 (void) strcpy(buf
, str
);
98 p
= buf
- 1 + strlen(buf
);
99 if(*p
== '/') *p
= '\0';