Commit cf63bb88 authored by Alexandre Julliard's avatar Alexandre Julliard

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

parent 4d135d9a
......@@ -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))
......
......@@ -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;
......
......@@ -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)));
......
......@@ -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();
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment