Commit bdc40b4b authored by Alexandre Julliard's avatar Alexandre Julliard

tools: Create a temporary directory to store temp files.

parent 52504931
......@@ -319,33 +319,53 @@ static inline char *replace_extension( const char *name, const char *old_ext, co
return strmake( "%.*s%s", name_len, name, new_ext );
}
/* temp files management */
static inline int make_temp_file( const char *prefix, const char *suffix, char **name )
extern const char *temp_dir;
static inline char *make_temp_dir(void)
{
static unsigned int value;
int fd, count;
unsigned int value = time(NULL) + getpid();
int count;
char *name;
const char *tmpdir = NULL;
if (!prefix) prefix = "tmp";
if (!suffix) suffix = "";
value += time(NULL) + getpid();
for (count = 0; count < 0x8000; count++)
{
if (tmpdir)
*name = strmake( "%s/%s-%08x%s", tmpdir, prefix, value, suffix );
name = strmake( "%s/tmp%08x", tmpdir, value );
else
*name = strmake( "%s-%08x%s", prefix, value, suffix );
fd = open( *name, O_RDWR | O_CREAT | O_EXCL, 0600 );
if (fd >= 0) return fd;
name = strmake( "tmp%08x", value );
if (!mkdir( name, 0700 )) return name;
value += 7777;
if (errno == EACCES && !tmpdir && !strchr( prefix, '/' ))
if (errno == EACCES && !tmpdir)
{
if (!(tmpdir = getenv("TMPDIR"))) tmpdir = "/tmp";
}
free( name );
}
fprintf( stderr, "failed to create directory for temp files\n" );
exit(1);
}
static inline int make_temp_file( const char *prefix, const char *suffix, char **name )
{
static unsigned int value;
int fd, count;
if (!temp_dir) temp_dir = make_temp_dir();
if (!suffix) suffix = "";
if (!prefix) prefix = "tmp";
else prefix = get_basename_noext( prefix );
for (count = 0; count < 0x8000; count++)
{
*name = strmake( "%s/%s-%08x%s", temp_dir, prefix, value++, suffix );
fd = open( *name, O_RDWR | O_CREAT | O_EXCL, 0600 );
if (fd >= 0) return fd;
free( *name );
}
fprintf( stderr, "failed to create temp file for %s%s\n", prefix, suffix );
fprintf( stderr, "failed to create temp file for %s%s in %s\n", prefix, suffix, temp_dir );
exit(1);
}
......
......@@ -135,6 +135,7 @@ char *regscript_name;
char *regscript_token;
static char *idfile_name;
char *temp_name;
const char *temp_dir = NULL;
const char *prefix_client = "";
const char *prefix_server = "";
static const char *includedir;
......@@ -931,4 +932,6 @@ static void rm_tempfile(void)
unlink(proxy_name);
if (do_typelib)
unlink(typelib_name);
if (temp_dir)
rmdir(temp_dir);
}
......@@ -29,6 +29,7 @@
#include "build.h"
const char *temp_dir = NULL;
static struct strarray tmp_files;
static const char *output_file_source_name;
......@@ -37,6 +38,7 @@ void cleanup_tmp_files(void)
{
unsigned int i;
for (i = 0; i < tmp_files.count; i++) if (tmp_files.str[i]) unlink( tmp_files.str[i] );
if (temp_dir) rmdir( temp_dir );
}
......
......@@ -147,6 +147,7 @@ static const char *output_file_name;
static const char *output_debug_file;
static const char *output_implib;
static int keep_generated = 0;
const char *temp_dir = NULL;
static struct strarray tmp_files;
#ifdef HAVE_SIGSET_T
static sigset_t signal_mask;
......@@ -222,6 +223,7 @@ static void clean_temp_files(void)
for (i = 0; i < tmp_files.count; i++)
unlink(tmp_files.str[i]);
if (temp_dir) rmdir( temp_dir );
}
/* clean things up when aborting on a signal */
......
......@@ -135,6 +135,7 @@ static char *output_name; /* The name given by the -o option */
const char *input_name = NULL; /* The name given on the command-line */
static char *temp_name = NULL; /* Temporary file for preprocess pipe */
static struct strarray input_files;
const char *temp_dir = NULL;
static int stdinc = 1;
static int po_mode;
......@@ -519,4 +520,5 @@ static void cleanup_files(void)
{
if (output_name) unlink(output_name);
if (temp_name) unlink(temp_name);
if (temp_dir) rmdir(temp_dir);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment