http://bugs.gentoo.org/114499 --- texinfo-4.8/util/texindex.c +++ texinfo-4.8/util/texindex.c @@ -20,6 +20,7 @@ #include "system.h" #include +#include static char *program_name = "texindex"; @@ -37,8 +38,6 @@ static char *program_name = "texindex"; #define memset(ptr, ignore, count) bzero (ptr, count) #endif -char *mktemp (char *); - #if !defined (SEEK_SET) # define SEEK_SET 0 # define SEEK_CUR 1 @@ -146,6 +145,7 @@ void error (const char *format, const ch void *xmalloc (), *xrealloc (); char *concat (char *s1, char *s2); void flush_tempfiles (int to_count); +void flush_tempfiles_atexit (); #define MAX_IN_CORE_SORT 500000 @@ -307,6 +307,7 @@ decode_command (int argc, char **argv) int arg_index = 1; char **ip; char **op; + int retries; /* Store default values into parameter variables. */ @@ -320,8 +321,26 @@ decode_command (int argc, char **argv) else tempdir = concat (tempdir, "/"); + tempdir = concat (tempdir, "txidx.XXXXXX"); + retries = 0x1000; + + do + { + char *dot; + if (mktemp(tempdir) == NULL || !tempdir[0]) + fatal("mktemp failed for '%s'", tempdir); + if (mkdir(tempdir, 0700) == 0) break; + if (errno != EEXIST || !--retries) + pfatal_with_name(tempdir); + if ((dot = strrchr (tempdir, "."))) + strcpy (dot, ".XXXXXX"); + } + while (1); + keep_tempfiles = 0; + atexit(flush_tempfiles_atexit); + /* Allocate ARGC input files, which must be enough. */ infiles = (char **) xmalloc (argc * sizeof (char *)); @@ -389,21 +408,9 @@ For more information about these matters static char * maketempname (int count) { - static char *tempbase = NULL; char tempsuffix[10]; - - if (!tempbase) - { - int fd; - tempbase = concat (tempdir, "txidxXXXXXX"); - - fd = mkstemp (tempbase); - if (fd == -1) - pfatal_with_name (tempbase); - } - - sprintf (tempsuffix, ".%d", count); - return concat (tempbase, tempsuffix); + sprintf (tempsuffix, "/%d", count); + return concat (tempdir, tempsuffix); } @@ -416,6 +423,13 @@ flush_tempfiles (int to_count) return; while (last_deleted_tempcount < to_count) unlink (maketempname (++last_deleted_tempcount)); + rmdir(tempdir); +} + +void +flush_tempfiles_atexit (void) +{ + flush_tempfiles (tempcount); } @@ -1622,7 +1636,7 @@ concat (char *s1, char *s2) strcpy (result, s1); strcpy (result + len1, s2); - *(result + len1 + len2) = 0; + result[len1 + len2] = '\0'; return result; }