forked from pool/texinfo
94 lines
2.0 KiB
Diff
94 lines
2.0 KiB
Diff
--- util/texindex.c
|
||
+++ util/texindex.c 2005-10-06 15:47:13.000000000 +0200
|
||
@@ -20,6 +20,7 @@
|
||
|
||
#include "system.h"
|
||
#include <getopt.h>
|
||
+#include <stdlib.h>
|
||
|
||
static char *program_name = "texindex";
|
||
|
||
@@ -37,8 +38,6 @@
|
||
#define memset(ptr, ignore, count) bzero (ptr, count)
|
||
#endif
|
||
|
||
-char *mktemp (char *);
|
||
-
|
||
#if !defined (SEEK_SET)
|
||
# define SEEK_SET 0
|
||
# define SEEK_CUR 1
|
||
@@ -99,6 +98,10 @@
|
||
/* Directory to use for temporary files. On Unix, it ends with a slash. */
|
||
char *tempdir;
|
||
|
||
+/* The base directory for the temporary files located in tempdir */
|
||
+
|
||
+static char *tempbase = NULL;
|
||
+
|
||
/* Number of last temporary file. */
|
||
int tempcount;
|
||
|
||
@@ -146,6 +149,7 @@
|
||
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
|
||
|
||
@@ -321,6 +325,7 @@
|
||
tempdir = concat (tempdir, "/");
|
||
|
||
keep_tempfiles = 0;
|
||
+ atexit(flush_tempfiles_atexit);
|
||
|
||
/* Allocate ARGC input files, which must be enough. */
|
||
|
||
@@ -384,25 +389,25 @@
|
||
usage (1);
|
||
}
|
||
|
||
+
|
||
/* Return a name for temporary file COUNT. */
|
||
|
||
static char *
|
||
maketempname (int count)
|
||
{
|
||
- static char *tempbase = NULL;
|
||
- char tempsuffix[10];
|
||
+ char tempsuffix[20];
|
||
|
||
if (!tempbase)
|
||
{
|
||
- int fd;
|
||
- tempbase = concat (tempdir, "txidxXXXXXX");
|
||
+ char *td;
|
||
+ tempbase = concat (tempdir, "txdirXXXXXX");
|
||
|
||
- fd = mkstemp (tempbase);
|
||
- if (fd == -1)
|
||
+ td = mkdtemp (tempbase);
|
||
+ if (td == (char*)0)
|
||
pfatal_with_name (tempbase);
|
||
}
|
||
|
||
- sprintf (tempsuffix, ".%d", count);
|
||
+ sprintf (tempsuffix, "/txidx.%d", count);
|
||
return concat (tempbase, tempsuffix);
|
||
}
|
||
|
||
@@ -418,6 +423,13 @@
|
||
unlink (maketempname (++last_deleted_tempcount));
|
||
}
|
||
|
||
+void
|
||
+flush_tempfiles_atexit (void)
|
||
+{
|
||
+ flush_tempfiles (tempcount);
|
||
+ if (tempbase && !keep_tempfiles)
|
||
+ (void)rmdir(tempbase);
|
||
+}
|
||
|
||
/* Compare LINE1 and LINE2 according to the specified set of keyfields. */
|
||
|