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

View File

@ -734,16 +734,10 @@ void open_output_file(void)
if (output_file_name) if (output_file_name)
{ {
if (strendswith( output_file_name, ".o" )) if (strendswith( output_file_name, ".o" ))
{ output_file_source_name = open_temp_output_file( ".s" );
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 );
}
else else
{
if (!(output_file = fopen( output_file_name, "w" ))) if (!(output_file = fopen( output_file_name, "w" )))
fatal_error( "Unable to create output file '%s'\n", output_file_name ); fatal_error( "Unable to create output file '%s'\n", output_file_name );
}
} }
else output_file = stdout; 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 * remove_stdcall_decoration
* *