winebuild: Add a helper function to open a temporary file as output.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-03-04 14:46:02 +01:00
parent aa0572f0a2
commit 67f6c6c0c9
3 changed files with 25 additions and 23 deletions

View File

@ -260,6 +260,7 @@ extern FILE *open_input_file( const char *srcdir, const char *name );
extern void close_input_file( FILE *file );
extern void open_output_file(void);
extern void close_output_file(void);
extern char *open_temp_output_file( const char *suffix );
extern void dump_bytes( const void *buffer, unsigned int size );
extern int remove_stdcall_decoration( char *name );
extern void assemble_file( const char *src_file, const char *obj_file );

View File

@ -489,22 +489,20 @@ static char *create_undef_symbols_file( DLLSPEC *spec )
char *as_file, *obj_file;
int i;
unsigned int j;
FILE *f;
as_file = get_temp_file_name( output_file_name, ".s" );
if (!(f = fopen( as_file, "w" ))) fatal_error( "Cannot create %s\n", as_file );
fprintf( f, "\t.data\n" );
as_file = open_temp_output_file( ".s" );
output( "\t.data\n" );
for (i = 0; i < spec->nb_entry_points; i++)
{
ORDDEF *odp = &spec->entry_points[i];
if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
if (odp->flags & FLAG_FORWARD) continue;
fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
}
for (j = 0; j < extra_ld_symbols.count; j++)
fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols.str[j]) );
fclose( f );
output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols.str[j]) );
fclose( output_file );
obj_file = get_temp_file_name( output_file_name, ".o" );
assemble_file( as_file, obj_file );
@ -1332,13 +1330,12 @@ void output_imports( DLLSPEC *spec )
}
/* create a new asm temp file */
static void new_output_as_file( const char *prefix )
static void new_output_as_file(void)
{
char *name = get_temp_file_name( prefix, ".s" );
char *name;
if (output_file) fclose( output_file );
if (!(output_file = fopen( name, "w" )))
fatal_error( "Unable to create output file '%s'\n", name );
name = open_temp_output_file( ".s" );
strarray_add( &as_files, name, NULL );
}
@ -1381,9 +1378,7 @@ static void build_windows_import_lib( DLLSPEC *spec )
char *def_file;
const char *as_flags, *m_flag;
def_file = get_temp_file_name( output_file_name, ".def" );
if (!(output_file = fopen( def_file, "w" )))
fatal_error( "Unable to create output file '%s'\n", def_file );
def_file = open_temp_output_file( ".def" );
output_def_file( spec, 0 );
fclose( output_file );
@ -1442,7 +1437,7 @@ static void build_unix_import_lib( DLLSPEC *spec )
case TYPE_CDECL:
case TYPE_STDCALL:
prefix = (!odp->name || (odp->flags & FLAG_ORDINAL)) ? import_ord_prefix : import_func_prefix;
new_output_as_file( spec->file_name );
new_output_as_file();
output( "\t.text\n" );
output( "\n\t.align %d\n", get_alignment( get_ptr_size() ));
output( "\t%s\n", func_declaration( name ) );
@ -1461,7 +1456,7 @@ static void build_unix_import_lib( DLLSPEC *spec )
if (!as_files.count) /* create a dummy file to avoid empty import libraries */
{
new_output_as_file( spec->file_name );
new_output_as_file();
output( "\t.text\n" );
}

View File

@ -734,16 +734,10 @@ void open_output_file(void)
if (output_file_name)
{
if (strendswith( output_file_name, ".o" ))
{
output_file_source_name = get_temp_file_name( output_file_name, ".s" );
if (!(output_file = fopen( output_file_source_name, "w" )))
fatal_error( "Unable to create output file '%s'\n", output_file_name );
}
output_file_source_name = open_temp_output_file( ".s" );
else
{
if (!(output_file = fopen( output_file_name, "w" )))
fatal_error( "Unable to create output file '%s'\n", output_file_name );
}
}
else output_file = stdout;
}
@ -761,6 +755,18 @@ void close_output_file(void)
}
/*******************************************************************
* open_temp_output_file
*/
char *open_temp_output_file( const char *suffix )
{
char *tmp_file = get_temp_file_name( output_file_name, suffix );
if (!(output_file = fopen( tmp_file, "w" )))
fatal_error( "Unable to create output file '%s'\n", tmp_file );
return tmp_file;
}
/*******************************************************************
* remove_stdcall_decoration
*