From 4d55592540c7cd1e8f6e0e449402930fbf6d38fb Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 30 Mar 2010 15:34:12 +0200 Subject: [PATCH] widl: Move temp file management from wpp to widl. --- tools/widl/parser.l | 18 ++++++++++++++---- tools/widl/widl.c | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tools/widl/parser.l b/tools/widl/parser.l index 5db95609cdb..e7673d10256 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -42,6 +42,7 @@ double [0-9]+\.[0-9]+([eE][+-]?[0-9]+)* %{ #include "config.h" +#include "wine/port.h" #include #include @@ -442,10 +443,10 @@ struct imports { int do_import(char *fname) { FILE *f; - char *path; + char *path, *name; struct imports *import; int ptr = import_stack_ptr; - int ret; + int ret, fd; import = first_import; while (import && strcmp(import->name, fname)) @@ -460,7 +461,7 @@ int do_import(char *fname) /* don't search for a file name with a path in the include directories, * for compatibility with MIDL */ if (strchr( fname, '/' ) || strchr( fname, '\\' )) - path = strdup( fname ); + path = xstrdup( fname ); else if (!(path = wpp_find_include( fname, input_name ))) error_loc("Unable to open include file %s\n", fname); @@ -471,7 +472,16 @@ int do_import(char *fname) input_name = path; line_number = 1; - ret = wpp_parse_temp( path, NULL, &temp_name ); + name = xstrdup( "widl.XXXXXX" ); + if((fd = mkstemps( name, 0 )) == -1) + error("Could not generate a temp name from %s\n", name); + + temp_name = name; + if (!(f = fdopen(fd, "wt"))) + error("Could not open fd %s for writing\n", name); + + ret = wpp_parse( path, f ); + fclose( f ); if (ret) exit(1); if((f = fopen(temp_name, "r")) == NULL) diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 8c76c24e08e..8c0d0c9fb9a 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -701,7 +701,22 @@ int main(int argc,char *argv[]) if (!preprocess_only) { - ret = wpp_parse_temp( input_name, header_name, &temp_name ); + FILE *output; + int fd; + char *name = xmalloc( strlen(header_name) + 8 ); + + strcpy( name, header_name ); + strcat( name, ".XXXXXX" ); + + if ((fd = mkstemps( name, 0 )) == -1) + error("Could not generate a temp name from %s\n", name); + + temp_name = name; + if (!(output = fdopen(fd, "wt"))) + error("Could not open fd %s for writing\n", name); + + ret = wpp_parse( input_name, output ); + fclose( output ); } else {