Merge pull request #2699 from colinleroy/fix-temp-files-again
Fix temporary filenames again.
This commit is contained in:
@@ -156,15 +156,22 @@ char* MakeTmpFilename (const char *Directory, const char *Origin, const char* Ex
|
|||||||
{
|
{
|
||||||
char* Out;
|
char* Out;
|
||||||
size_t Len = 0;
|
size_t Len = 0;
|
||||||
|
static unsigned int Counter = 0;
|
||||||
|
|
||||||
/* Allocate template */
|
/* Allocate enough for the directory, ... */
|
||||||
if (Directory != NULL) {
|
if (Directory != NULL) {
|
||||||
Len = strlen (Directory);
|
Len = strlen (Directory);
|
||||||
}
|
}
|
||||||
Len += strlen (Origin) + strlen (".2147483648") + strlen (Ext) + 1;
|
|
||||||
|
/* ... plus the the original name, the maximum length of the PID, the
|
||||||
|
* maximum length of the counter, the extension, and the terminator.
|
||||||
|
*/
|
||||||
|
Len += strlen (Origin) + (strlen (".2147483648") * 2) + strlen (Ext) + 1;
|
||||||
Out = xmalloc (Len);
|
Out = xmalloc (Len);
|
||||||
|
|
||||||
snprintf (Out, Len, "%s%s.%u%s", (Directory != NULL ? Directory : ""),
|
snprintf (Out, Len, "%s%s.%u%u%s", (Directory != NULL ? Directory : ""),
|
||||||
FindName(Origin), getpid(), Ext);
|
FindName(Origin), getpid(), Counter, Ext);
|
||||||
|
Counter++;
|
||||||
|
|
||||||
return Out;
|
return Out;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user