104 |
|
static char * |
105 |
|
prepare_tmpname(char *s, size_t len, char *templ) |
106 |
|
{ |
107 |
< |
static char lp[PATH_MAX] = "\0"; /* remember what we found last time */ |
107 |
> |
static char lp[PATH_MAX] = "\0"; |
108 |
|
char *ts = NULL; |
109 |
|
|
110 |
|
if (s == NULL) { /* return our static string */ |
143 |
|
/* WARNING: On Windows, there's a maximum of 27 unique names within |
144 |
|
one process for the same template. */ |
145 |
|
int |
146 |
< |
temp_file(char *s, size_t len, char *templ) |
146 |
> |
temp_fd(char *s, size_t len, char *templ) |
147 |
|
{ |
148 |
|
char *ts = NULL; |
149 |
|
|
152 |
|
#ifdef _WIN32 |
153 |
|
ts = mktemp(ts); |
154 |
|
if (ts == NULL) return -1; |
155 |
< |
return fopen(ts, "r+b"); /* XXX des "b" need to be an option? */ |
155 |
> |
return open(ts, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
156 |
|
#else |
157 |
|
return mkstemp(ts); |
158 |
|
#endif |
159 |
+ |
} |
160 |
+ |
|
161 |
+ |
/* As above, but returns a file pointer instead of a descriptor */ |
162 |
+ |
FILE * |
163 |
+ |
temp_fp(char *s, size_t len, char *templ) |
164 |
+ |
{ |
165 |
+ |
int fd = temp_file(s, len, templ); |
166 |
+ |
if (fd < 0) return NULL; |
167 |
+ |
return fdopen(fd, "w+"); |
168 |
|
} |
169 |
|
|
170 |
|
|