1 /**********
2 Copyright 1990 Regents of the University of California.  All rights reserved.
3 **********/
4 
5 /*
6  * A more portable version of the standard "mktemp( )" function
7  *
8  * FIXME: remove smktemp() and adjust all callers to use tmpfile(3).
9  */
10 
11 #include "ngspice/ngspice.h"
12 #include "mktemp.h"
13 
14 #ifdef HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17 
18 #ifndef TEMPFORMAT
19 #define TEMPFORMAT "temp%s%d"
20 #endif
21 #ifndef TEMPFORMAT2
22 #define TEMPFORMAT "temp%s%d_%d"
23 #endif
24 
25 
26 char *
smktemp(char * id)27 smktemp(char *id)
28 {
29     if (!id)
30         id = "sp";
31     const char* const home = getenv("HOME");
32     if (home) {
33         return tprintf("%s"TEMPFORMAT, home, id, getpid());
34     }
35     const char* const usr = getenv("USERPROFILE");
36     if (usr) {
37         return tprintf("%s\\"TEMPFORMAT, usr, id, getpid());
38     }
39     return tprintf(TEMPFORMAT, id, getpid());
40 }
41 
42 
43 char*
smktemp2(char * id,int n)44 smktemp2(char* id, int n)
45 {
46     if (!id)
47         id = "sp";
48     const char* const home = getenv("HOME");
49     if (home) {
50         return tprintf("%s"TEMPFORMAT2, home, id, getpid(), n);
51     }
52     const char* const usr = getenv("USERPROFILE");
53     if (usr) {
54         return tprintf("%s\\"TEMPFORMAT2, usr, id, getpid(), n);
55     }
56     return tprintf(TEMPFORMAT2, id, getpid(), n);
57 }
58 
59