winebuild: Fix the creation of temp files in /tmp.

This commit is contained in:
Alexandre Julliard 2011-05-26 12:20:37 +02:00
parent dbbed381d0
commit 2f4f9ee1cb
1 changed files with 15 additions and 10 deletions

View File

@ -410,25 +410,30 @@ const char *get_nm_command(void)
char *get_temp_file_name( const char *prefix, const char *suffix ) char *get_temp_file_name( const char *prefix, const char *suffix )
{ {
char *name; char *name;
const char *ext; const char *ext, *basename;
int fd; int fd;
if (!nb_tmp_files && !save_temps) atexit( cleanup_tmp_files ); if (!nb_tmp_files && !save_temps) atexit( cleanup_tmp_files );
if (!prefix || !prefix[0]) prefix = "winebuild"; if (!prefix || !prefix[0]) prefix = "winebuild";
if (!suffix) suffix = ""; if (!suffix) suffix = "";
if (!(ext = strchr( prefix, '.' ))) ext = prefix + strlen(prefix); if ((basename = strrchr( prefix, '/' ))) basename++;
else basename = prefix;
if (!(ext = strchr( basename, '.' ))) ext = prefix + strlen(prefix);
name = xmalloc( sizeof("/tmp/") + (ext - prefix) + sizeof(".XXXXXX") + strlen(suffix) ); name = xmalloc( sizeof("/tmp/") + (ext - prefix) + sizeof(".XXXXXX") + strlen(suffix) );
strcpy( name, "/tmp/" ); memcpy( name, prefix, ext - prefix );
memcpy( name + 5, prefix, ext - prefix ); strcpy( name + (ext - prefix), ".XXXXXX" );
strcpy( name + 5 + (ext - prefix), ".XXXXXX" );
strcat( name, suffix ); strcat( name, suffix );
/* first try without the /tmp/ prefix */ if ((fd = mkstemps( name, strlen(suffix) )) == -1)
if ((fd = mkstemps( name + 5, strlen(suffix) )) != -1) {
name += 5; strcpy( name, "/tmp/" );
else if ((fd = mkstemps( name, strlen(suffix) )) == -1) memcpy( name + 5, basename, ext - basename );
fatal_error( "could not generate a temp file\n" ); strcpy( name + 5 + (ext - basename), ".XXXXXX" );
strcat( name, suffix );
if ((fd = mkstemps( name, strlen(suffix) )) == -1)
fatal_error( "could not generate a temp file\n" );
}
close( fd ); close( fd );
if (nb_tmp_files >= max_tmp_files) if (nb_tmp_files >= max_tmp_files)