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

Alexandre Julliard julliard at winehq.org
Mon Mar 4 15:08:25 CST 2019


Module: wine
Branch: master
Commit: 67f6c6c0c92ac82db7da067fc06fe00fa05b9340
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=67f6c6c0c92ac82db7da067fc06fe00fa05b9340

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Mar  4 14:46:02 2019 +0100

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

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 tools/winebuild/build.h  |  1 +
 tools/winebuild/import.c | 27 +++++++++++----------------
 tools/winebuild/utils.c  | 20 +++++++++++++-------
 3 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h
index d65af7b..d7b46a6 100644
--- a/tools/winebuild/build.h
+++ b/tools/winebuild/build.h
@@ -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 );
diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c
index b3c7121..6ab7765 100644
--- a/tools/winebuild/import.c
+++ b/tools/winebuild/import.c
@@ -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" );
     }
 
diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c
index 09b01fa..06c3d39 100644
--- a/tools/winebuild/utils.c
+++ b/tools/winebuild/utils.c
@@ -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;
 }
@@ -762,6 +756,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 a possible @xx suffix from a function name.




More information about the wine-cvs mailing list