|
|
| |
#include "system.h" | #include "system.h" |
#include <getopt.h> | #include <getopt.h> |
|
#include <stdlib.h> |
| |
static char *program_name = "texindex"; | static char *program_name = "texindex"; |
| |
|
Lines 37-44
static char *program_name = "texindex";
|
Link Here
|
|---|
|
#define memset(ptr, ignore, count) bzero (ptr, count) | #define memset(ptr, ignore, count) bzero (ptr, count) |
#endif | #endif |
| |
char *mktemp (char *); |
|
|
|
#if !defined (SEEK_SET) | #if !defined (SEEK_SET) |
# define SEEK_SET 0 | # define SEEK_SET 0 |
# define SEEK_CUR 1 | # define SEEK_CUR 1 |
|
Lines 146-151
void error (const char *format, const ch
|
Link Here
|
|---|
|
void *xmalloc (), *xrealloc (); | void *xmalloc (), *xrealloc (); |
char *concat (char *s1, char *s2); | char *concat (char *s1, char *s2); |
void flush_tempfiles (int to_count); | void flush_tempfiles (int to_count); |
|
void flush_tempfiles_atexit (); |
| |
#define MAX_IN_CORE_SORT 500000 | #define MAX_IN_CORE_SORT 500000 |
| |
|
Lines 307-312
decode_command (int argc, char **argv)
|
Link Here
|
|---|
|
int arg_index = 1; | int arg_index = 1; |
char **ip; | char **ip; |
char **op; | char **op; |
|
int retries; |
| |
/* Store default values into parameter variables. */ | /* Store default values into parameter variables. */ |
| |
|
Lines 320-327
decode_command (int argc, char **argv)
|
Link Here
|
|---|
|
else | else |
tempdir = concat (tempdir, "/"); | 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; | keep_tempfiles = 0; |
| |
|
atexit(flush_tempfiles_atexit); |
|
|
/* Allocate ARGC input files, which must be enough. */ | /* Allocate ARGC input files, which must be enough. */ |
| |
infiles = (char **) xmalloc (argc * sizeof (char *)); | infiles = (char **) xmalloc (argc * sizeof (char *)); |
|
Lines 389-409
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]; |
|
sprintf (tempsuffix, "/%d", count); |
if (!tempbase) |
return concat (tempdir, tempsuffix); |
{ |
|
int fd; |
|
tempbase = concat (tempdir, "txidxXXXXXX"); |
|
|
|
fd = mkstemp (tempbase); |
|
if (fd == -1) |
|
pfatal_with_name (tempbase); |
|
} |
|
|
|
sprintf (tempsuffix, ".%d", count); |
|
return concat (tempbase, tempsuffix); |
|
} | } |
| |
| |
|
Lines 416-421
flush_tempfiles (int to_count)
|
Link Here
|
|---|
|
return; | return; |
while (last_deleted_tempcount < to_count) | while (last_deleted_tempcount < to_count) |
unlink (maketempname (++last_deleted_tempcount)); | unlink (maketempname (++last_deleted_tempcount)); |
|
rmdir(tempdir); |
|
} |
|
|
|
void |
|
flush_tempfiles_atexit (void) |
|
{ |
|
flush_tempfiles (tempcount); |
} | } |
| |
| |
|
Lines 1622-1628
concat (char *s1, char *s2)
|
Link Here
|
|---|
|
| |
strcpy (result, s1); | strcpy (result, s1); |
strcpy (result + len1, s2); | strcpy (result + len1, s2); |
*(result + len1 + len2) = 0; |
result[len1 + len2] = '\0'; |
| |
return result; | return result; |
} | } |