|
|
/* Directory to use for temporary files. On Unix, it ends with a slash. */ | /* Directory to use for temporary files. On Unix, it ends with a slash. */ |
char *tempdir; | char *tempdir; |
| |
|
/* Basename for temp files inside of tempdir. */ |
|
char *tempbase; |
|
|
/* Number of last temporary file. */ | /* Number of last temporary file. */ |
int tempcount; | int tempcount; |
| |
|
Lines 190-195
main (int argc, char **argv)
|
Link Here
|
|---|
|
| |
decode_command (argc, argv); | decode_command (argc, argv); |
| |
|
/* XXX mkstemp not appropriate, as we need to have somewhat predictable |
|
* names. But race condition was fixed, see maketempname. |
|
*/ |
|
tempbase = mktemp ("txidxXXXXXX"); |
|
|
/* Process input files completely, one by one. */ | /* Process input files completely, one by one. */ |
| |
for (i = 0; i < num_infiles; i++) | for (i = 0; i < num_infiles; i++) |
|
Lines 392-412
For more information about these matters
|
Link Here
|
|---|
|
static char * | static char * |
maketempname (int count) | maketempname (int count) |
{ | { |
static char *tempbase = NULL; |
|
char tempsuffix[10]; | char tempsuffix[10]; |
|
char *name, *tmp_name; |
if (!tempbase) |
int fd; |
{ |
|
int fd; |
|
tempbase = concat (tempdir, "txidxXXXXXX"); |
|
|
|
fd = mkstemp (tempbase); |
|
if (fd == -1) |
|
pfatal_with_name (tempbase); |
|
} |
|
| |
sprintf (tempsuffix, ".%d", count); | sprintf (tempsuffix, ".%d", count); |
return concat (tempbase, tempsuffix); |
tmp_name = concat (tempdir, tempbase); |
|
name = concat (tmp_name, tempsuffix); |
|
free(tmp_name); |
|
|
|
fd = mkstemp (name); |
|
if (fd == -1) |
|
pfatal_with_name (name); |
|
|
|
return name; |
} | } |
| |
| |