binutils/binutils-2.29-filename-in-error-messages.patch

75 lines
2.1 KiB
Diff

--- binutils.orig/binutils/readelf.c 2017-07-24 15:27:09.859116315 +0100
+++ binutils-2.29/binutils/readelf.c 2017-07-24 15:30:33.557770525 +0100
@@ -18414,39 +18414,50 @@ process_archive (char * file_name, FILE
static bfd_boolean
process_file (char * file_name)
{
+ char * name;
+ char * saved_program_name;
FILE * file;
struct stat statbuf;
char armag[SARMAG];
bfd_boolean ret = TRUE;
+ /* Overload program_name to include file_name. Doing this means
+ that warning/error messages will positively identify the file
+ concerned even when multiple instances of readelf are running. */
+ name = xmalloc (strlen (program_name) + strlen (file_name) + 3);
+ sprintf (name, "%s: %s", program_name, file_name);
+ saved_program_name = program_name;
+ program_name = name;
+
if (stat (file_name, &statbuf) < 0)
{
if (errno == ENOENT)
- error (_("'%s': No such file\n"), file_name);
+ error (_("No such file\n"));
else
- error (_("Could not locate '%s'. System error message: %s\n"),
- file_name, strerror (errno));
- return FALSE;
+ error (_("Could not locate file. System error message: %s\n"),
+ strerror (errno));
+ goto done;
}
if (! S_ISREG (statbuf.st_mode))
{
- error (_("'%s' is not an ordinary file\n"), file_name);
- return FALSE;
+ error (_("Not an ordinary file\n"));
+ goto done;
}
file = fopen (file_name, "rb");
if (file == NULL)
{
- error (_("Input file '%s' is not readable.\n"), file_name);
- return FALSE;
+ error (_("Not readable\n"));
+ goto done;
}
if (fread (armag, SARMAG, 1, file) != 1)
{
- error (_("%s: Failed to read file's magic number\n"), file_name);
+ error (_("Failed to read file's magic number\n"));
fclose (file);
- return FALSE;
+ ret = FALSE;
+ goto done;
}
current_file_size = (bfd_size_type) statbuf.st_size;
@@ -18474,7 +18484,10 @@ process_file (char * file_name)
}
fclose (file);
+ done:
current_file_size = 0;
+ free (program_name);
+ program_name = saved_program_name;
return ret;
}