1 /* RCS $Id: tempnam.c,v 1.1.1.1 2000-09-22 15:33:29 hr Exp $
7 -- temp file name generation code.
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.
34 #define max(A,B) (((A)<(B))?(B):(A))
36 extern char *mktemp();
40 /* Zortech C stdio.h doesn't define P_tmpdir, so let's do it here */
41 /* Under DOS leave the default tmpdir pointing here! */
42 static char *P_tmpdir
= "";
46 const char *dir
; /* use this directory please (if non-NULL) */
47 const char *prefix
; /* use this (if non-NULL) as filename prefix */
50 register char *p
, *q
, *tmpdir
;
54 pl
= strlen(P_tmpdir
);
56 if( (tmpdir
= getenv("TMPDIR")) != NULL
) tl
= strlen(tmpdir
);
57 else if( (tmpdir
= getenv("TMP")) != NULL
) tl
= strlen(tmpdir
);
58 if( dir
!= NULL
) dl
= strlen(dir
);
60 if( (p
= malloc((unsigned)(max(max(dl
,tl
),pl
)+13))) == NULL
)
65 if( (tl
== 0) || (d_access( strcpy(p
, tmpdir
), 0) != 0) )
66 if( (dl
== 0) || (d_access( strcpy(p
, dir
), 0) != 0) )
67 if( d_access( strcpy(p
, P_tmpdir
), 0) != 0 )
73 *(p
+strlen(p
)+2) = '\0';
74 (void)strncat(p
, prefix
, 2);
77 sprintf( buf
, "%08x", _psp
);
79 (void)strcat(p
, buf
);
80 sprintf( buf
, "%04d", count
++ );
82 *q
++ = buf
[0]; *q
++ = buf
[1];
83 *q
++ = buf
[2]; *q
++ = buf
[3];
85 if( (q
= strrchr(p
,'.')) != NULL
) *q
= '\0';
92 d_access( name
, flag
)
96 extern char *DirSepStr
;
100 if( name
== NULL
|| !*name
) return(1); /* NULL dir means current dir */
101 r
= access( name
, flag
);
102 p
= name
+strlen(name
)-1;
103 if(*p
!= '/' && *p
!= '\\') strcat( p
, DirSepStr
);