Alexandre Julliard : wrc: Print better error messages for functions that set errno.

Alexandre Julliard julliard at winehq.org
Mon Feb 16 09:35:25 CST 2009


Module: wine
Branch: master
Commit: cf63bb880e9502532df55f78959b81a3b4478de8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cf63bb880e9502532df55f78959b81a3b4478de8

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Feb 16 13:08:50 2009 +0100

wrc: Print better error messages for functions that set errno.

---

 tools/wrc/readres.c  |    2 +-
 tools/wrc/utils.c    |   11 +++++++++++
 tools/wrc/utils.h    |    3 ++-
 tools/wrc/wrc.c      |    4 ++--
 tools/wrc/writeres.c |    7 +++----
 5 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/tools/wrc/readres.c b/tools/wrc/readres.c
index f7aaba8..9e964a6 100644
--- a/tools/wrc/readres.c
+++ b/tools/wrc/readres.c
@@ -354,7 +354,7 @@ resource_t *read_resfile(char *inname)
 
 	fp = fopen(inname, "rb");
 	if(!fp)
-		error("Could not open inputfile %s\n", inname);
+            fatal_perror("Could not open %s", inname);
 
 	/* Determine 16 or 32 bit .res file */
 	if(fread(&rh, 1, sizeof(rh), fp) != sizeof(rh))
diff --git a/tools/wrc/utils.c b/tools/wrc/utils.c
index eb079ee..b6688af 100644
--- a/tools/wrc/utils.c
+++ b/tools/wrc/utils.c
@@ -96,6 +96,17 @@ void internal_error(const char *file, int line, const char *s, ...)
 	exit(3);
 }
 
+void fatal_perror( const char *msg, ... )
+{
+        va_list valist;
+        va_start( valist, msg );
+	fprintf(stderr, "Error: ");
+        vfprintf( stderr, msg, valist );
+        perror( " " );
+        va_end( valist );
+        exit(2);
+}
+
 void error(const char *s, ...)
 {
 	va_list ap;
diff --git a/tools/wrc/utils.h b/tools/wrc/utils.h
index 30c6ab2..09144e7 100644
--- a/tools/wrc/utils.h
+++ b/tools/wrc/utils.h
@@ -36,7 +36,8 @@ char *xstrdup(const char *str);
 int parser_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
 int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
 void internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4), noreturn));
-void error(const char *s, ...) __attribute__((format (printf, 1, 2)));
+void fatal_perror( const char *msg, ... ) __attribute__((format (printf, 1, 2), noreturn));
+void error(const char *s, ...) __attribute__((format (printf, 1, 2), noreturn));
 void warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
 void chat(const char *s, ...) __attribute__((format (printf, 1, 2)));
 
diff --git a/tools/wrc/wrc.c b/tools/wrc/wrc.c
index 15f30a3..05bd3f8 100644
--- a/tools/wrc/wrc.c
+++ b/tools/wrc/wrc.c
@@ -462,7 +462,7 @@ int main(int argc,char *argv[])
                     FILE *output;
 
                     if (!(output = fopen( output_name, "w" )))
-                        error( "Could not open %s for writing\n", output_name );
+                        fatal_perror( "Could not open %s for writing", output_name );
                     ret = wpp_parse( input_name, output );
                     fclose( output );
                 }
@@ -487,7 +487,7 @@ int main(int argc,char *argv[])
 	chat("Starting parse\n");
 
 	if(!(parser_in = fopen(input_name, "rb")))
-		error("Could not open %s for input\n", input_name);
+            fatal_perror("Could not open %s for input", input_name);
 
 	ret = parser_parse();
 
diff --git a/tools/wrc/writeres.c b/tools/wrc/writeres.c
index e26a559..0bcad16 100644
--- a/tools/wrc/writeres.c
+++ b/tools/wrc/writeres.c
@@ -52,9 +52,7 @@ void write_resfile(char *outname, resource_t *top)
 
 	fo = fopen(outname, "wb");
 	if(!fo)
-	{
-		error("Could not open %s\n", outname);
-	}
+            fatal_perror("Could not open %s", outname);
 
 	if(win32)
 	{
@@ -102,5 +100,6 @@ void write_resfile(char *outname, resource_t *top)
 			}
 		}
 	}
-	fclose(fo);
+	if (fclose(fo))
+            fatal_perror("Error writing %s", outname);
 }




More information about the wine-cvs mailing list