1 |
--- binutils.orig/binutils/readelf.c 2018-01-22 15:48:10.450701702 +0000 |
2 |
+++ binutils-2.30.0/binutils/readelf.c 2018-01-22 15:55:26.739588657 +0000 |
3 |
@@ -19019,75 +19019,85 @@ process_file (char * file_name) |
4 |
Filedata * filedata = NULL; |
5 |
struct stat statbuf; |
6 |
char armag[SARMAG]; |
7 |
- bfd_boolean ret = TRUE; |
8 |
+ bfd_boolean ret = FALSE; |
9 |
+ char * name; |
10 |
+ char * saved_program_name; |
11 |
+ |
12 |
+ /* Overload program_name to include file_name. Doing this means |
13 |
+ that warning/error messages will positively identify the file |
14 |
+ concerned even when multiple instances of readelf are running. */ |
15 |
+ name = xmalloc (strlen (program_name) + strlen (file_name) + 3); |
16 |
+ sprintf (name, "%s: %s", program_name, file_name); |
17 |
+ saved_program_name = program_name; |
18 |
+ program_name = name; |
19 |
|
20 |
if (stat (file_name, &statbuf) < 0) |
21 |
{ |
22 |
if (errno == ENOENT) |
23 |
- error (_("'%s': No such file\n"), file_name); |
24 |
+ error (_("No such file\n")); |
25 |
else |
26 |
- error (_("Could not locate '%s'. System error message: %s\n"), |
27 |
- file_name, strerror (errno)); |
28 |
- return FALSE; |
29 |
+ error (_("Could not locate file. System error message: %s\n"), |
30 |
+ strerror (errno)); |
31 |
+ goto done; |
32 |
} |
33 |
|
34 |
if (! S_ISREG (statbuf.st_mode)) |
35 |
{ |
36 |
- error (_("'%s' is not an ordinary file\n"), file_name); |
37 |
- return FALSE; |
38 |
+ error (_("Not an ordinary file\n")); |
39 |
+ goto done; |
40 |
} |
41 |
|
42 |
filedata = calloc (1, sizeof * filedata); |
43 |
if (filedata == NULL) |
44 |
{ |
45 |
error (_("Out of memory allocating file data structure\n")); |
46 |
- return FALSE; |
47 |
+ goto done; |
48 |
} |
49 |
|
50 |
filedata->file_name = file_name; |
51 |
filedata->handle = fopen (file_name, "rb"); |
52 |
if (filedata->handle == NULL) |
53 |
{ |
54 |
- error (_("Input file '%s' is not readable.\n"), file_name); |
55 |
- free (filedata); |
56 |
- return FALSE; |
57 |
+ error (_("Not readable\n")); |
58 |
+ goto done; |
59 |
} |
60 |
|
61 |
if (fread (armag, SARMAG, 1, filedata->handle) != 1) |
62 |
{ |
63 |
- error (_("%s: Failed to read file's magic number\n"), file_name); |
64 |
- fclose (filedata->handle); |
65 |
- free (filedata); |
66 |
- return FALSE; |
67 |
- } |
68 |
- |
69 |
- filedata->file_size = (bfd_size_type) statbuf.st_size; |
70 |
- |
71 |
- if (memcmp (armag, ARMAG, SARMAG) == 0) |
72 |
- { |
73 |
- if (! process_archive (filedata, FALSE)) |
74 |
- ret = FALSE; |
75 |
- } |
76 |
- else if (memcmp (armag, ARMAGT, SARMAG) == 0) |
77 |
- { |
78 |
- if ( ! process_archive (filedata, TRUE)) |
79 |
- ret = FALSE; |
80 |
+ error (_("Failed to read file's magic number\n")); |
81 |
} |
82 |
else |
83 |
{ |
84 |
- if (do_archive_index) |
85 |
- error (_("File %s is not an archive so its index cannot be displayed.\n"), |
86 |
- file_name); |
87 |
+ filedata->file_size = (bfd_size_type) statbuf.st_size; |
88 |
|
89 |
- rewind (filedata->handle); |
90 |
- archive_file_size = archive_file_offset = 0; |
91 |
- |
92 |
- if (! process_object (filedata)) |
93 |
- ret = FALSE; |
94 |
+ if (memcmp (armag, ARMAG, SARMAG) == 0) |
95 |
+ { |
96 |
+ if (process_archive (filedata, FALSE)) |
97 |
+ ret = TRUE; |
98 |
+ } |
99 |
+ else if (memcmp (armag, ARMAGT, SARMAG) == 0) |
100 |
+ { |
101 |
+ if (process_archive (filedata, TRUE)) |
102 |
+ ret = TRUE; |
103 |
+ } |
104 |
+ else |
105 |
+ { |
106 |
+ if (do_archive_index) |
107 |
+ error (_("Not an archive so its index cannot be displayed.\n")); |
108 |
+ |
109 |
+ rewind (filedata->handle); |
110 |
+ archive_file_size = archive_file_offset = 0; |
111 |
+ |
112 |
+ if (process_object (filedata)) |
113 |
+ ret = TRUE; |
114 |
+ } |
115 |
} |
116 |
|
117 |
fclose (filedata->handle); |
118 |
+ done: |
119 |
free (filedata); |
120 |
+ free (program_name); |
121 |
+ program_name = saved_program_name; |
122 |
|
123 |
return ret; |
124 |
} |