]>
Commit | Line | Data |
---|---|---|
52cb69e7 AM |
1 | 2005-03-07 Jakub Jelinek <jakub@redhat.com> |
2 | ||
3 | * libbfd-in.h (_bfd_ar_spacepad): New prototype. | |
4 | * libbfd.h: Rebuilt. | |
5 | * archive.c (_bfd_ar_spacepad): New function. | |
6 | (_bfd_construct_extended_name_table, _bfd_write_archive_contents, | |
7 | bsd_write_armap, _bfd_archive_bsd_update_armap_timestamp, | |
8 | coff_write_armap): Use it. | |
9 | (bfd_ar_hdr_from_filesystem): Likewise. Fix HP-UX large | |
10 | uid/gid support. | |
11 | * archive64.c (bfd_elf64_archive_write_armap): Use _bfd_ar_spacepad. | |
12 | ||
13 | --- bfd/libbfd-in.h.jj 2005-02-25 13:06:22.000000000 +0100 | |
14 | +++ bfd/libbfd-in.h 2005-03-07 11:10:58.745366987 +0100 | |
15 | @@ -176,6 +176,8 @@ bfd_boolean coff_write_armap | |
16 | ||
17 | extern void *_bfd_generic_read_ar_hdr | |
18 | (bfd *); | |
19 | +extern void _bfd_ar_spacepad | |
20 | + (char *, size_t, const char *, long); | |
21 | ||
22 | extern void *_bfd_generic_read_ar_hdr_mag | |
23 | (bfd *, const char *); | |
24 | --- bfd/libbfd.h.jj 2005-02-25 13:06:22.000000000 +0100 | |
25 | +++ bfd/libbfd.h 2005-03-07 11:11:28.099135905 +0100 | |
26 | @@ -181,6 +181,8 @@ bfd_boolean coff_write_armap | |
27 | ||
28 | extern void *_bfd_generic_read_ar_hdr | |
29 | (bfd *); | |
30 | +extern void _bfd_ar_spacepad | |
31 | + (char *, size_t, const char *, long); | |
32 | ||
33 | extern void *_bfd_generic_read_ar_hdr_mag | |
34 | (bfd *, const char *); | |
35 | --- bfd/archive.c.jj 2005-02-25 13:06:00.000000000 +0100 | |
36 | +++ bfd/archive.c 2005-03-07 11:09:22.003607377 +0100 | |
37 | @@ -121,7 +121,7 @@ DESCRIPTION | |
38 | ||
39 | Regular files with long names (or embedded spaces, for BSD variants): | |
40 | "/18 " - SVR4 style, name at offset 18 in name table. | |
41 | - "#1/23 " - Long name (or embedded paces) 23 characters long, | |
42 | + "#1/23 " - Long name (or embedded spaces) 23 characters long, | |
43 | BSD 4.4 style, full name follows header. | |
44 | Implemented for reading, not writing. | |
45 | " 18 " - Long name 18 characters long, extended pseudo-BSD. | |
46 | @@ -155,7 +155,22 @@ struct ar_cache { | |
47 | ||
48 | #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data)) | |
49 | #define arch_hdr(bfd) ((struct ar_hdr *) arch_eltdata(bfd)->arch_header) | |
50 | - | |
51 | +\f | |
52 | +void | |
53 | +_bfd_ar_spacepad (char *p, size_t n, const char *fmt, long val) | |
54 | +{ | |
55 | + static char buf[20]; | |
56 | + size_t len; | |
57 | + snprintf (buf, sizeof (buf), fmt, val); | |
58 | + len = strlen (buf); | |
59 | + if (len < n) | |
60 | + { | |
61 | + memcpy (p, buf, len); | |
62 | + memset (p + len, ' ', n - len); | |
63 | + } | |
64 | + else | |
65 | + memcpy (p, buf, n); | |
66 | +} | |
67 | \f | |
68 | bfd_boolean | |
69 | _bfd_generic_mkarchive (bfd *abfd) | |
70 | @@ -1262,17 +1277,8 @@ _bfd_construct_extended_name_table (bfd | |
71 | strptr[thislen + 1] = '\012'; | |
72 | } | |
73 | hdr->ar_name[0] = ar_padchar (current); | |
74 | - /* We know there will always be enough room (one of the few | |
75 | - cases where you may safely use sprintf). */ | |
76 | - sprintf ((hdr->ar_name) + 1, "%-d", (unsigned) (strptr - *tabloc)); | |
77 | - /* Kinda Kludgy. We should just use the returned value of | |
78 | - sprintf but not all implementations get this right. */ | |
79 | - { | |
80 | - char *temp = hdr->ar_name + 2; | |
81 | - for (; temp < hdr->ar_name + maxname; temp++) | |
82 | - if (*temp == '\0') | |
83 | - *temp = ' '; | |
84 | - } | |
85 | + _bfd_ar_spacepad (hdr->ar_name + 1, maxname - 1, "%-ld", | |
86 | + (unsigned) (strptr - *tabloc)); | |
87 | strptr += thislen + 1; | |
88 | if (trailing_slash) | |
89 | ++strptr; | |
90 | @@ -1319,7 +1325,6 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, c | |
91 | struct stat status; | |
92 | struct areltdata *ared; | |
93 | struct ar_hdr *hdr; | |
94 | - char *temp, *temp1; | |
95 | bfd_size_type amt; | |
96 | ||
97 | if (member && (member->flags & BFD_IN_MEMORY) != 0) | |
98 | @@ -1347,39 +1352,31 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, c | |
99 | /* ar headers are space padded, not null padded! */ | |
100 | memset (hdr, ' ', sizeof (struct ar_hdr)); | |
101 | ||
102 | - strncpy (hdr->ar_fmag, ARFMAG, 2); | |
103 | - | |
104 | - /* Goddamned sprintf doesn't permit MAXIMUM field lengths. */ | |
105 | - sprintf ((hdr->ar_date), "%-12ld", (long) status.st_mtime); | |
106 | + _bfd_ar_spacepad (hdr->ar_date, sizeof (hdr->ar_date), "%-12ld", | |
107 | + (long) status.st_mtime); | |
108 | #ifdef HPUX_LARGE_AR_IDS | |
109 | /* HP has a very "special" way to handle UID/GID's with numeric values | |
110 | > 99999. */ | |
111 | if (status.st_uid > 99999) | |
112 | - hpux_uid_gid_encode (hdr->ar_gid, (long) status.st_uid); | |
113 | + hpux_uid_gid_encode (hdr->ar_uid, (long) status.st_uid); | |
114 | else | |
115 | #endif | |
116 | - sprintf ((hdr->ar_uid), "%ld", (long) status.st_uid); | |
117 | + _bfd_ar_spacepad (hdr->ar_uid, sizeof (hdr->ar_uid), "%ld", | |
118 | + (long) status.st_uid); | |
119 | #ifdef HPUX_LARGE_AR_IDS | |
120 | /* HP has a very "special" way to handle UID/GID's with numeric values | |
121 | > 99999. */ | |
122 | if (status.st_gid > 99999) | |
123 | - hpux_uid_gid_encode (hdr->ar_uid, (long) status.st_gid); | |
124 | + hpux_uid_gid_encode (hdr->ar_gid, (long) status.st_gid); | |
125 | else | |
126 | #endif | |
127 | - sprintf ((hdr->ar_gid), "%ld", (long) status.st_gid); | |
128 | - sprintf ((hdr->ar_mode), "%-8o", (unsigned int) status.st_mode); | |
129 | - sprintf ((hdr->ar_size), "%-10ld", (long) status.st_size); | |
130 | - /* Correct for a lossage in sprintf whereby it null-terminates. I cannot | |
131 | - understand how these C losers could design such a ramshackle bunch of | |
132 | - IO operations. */ | |
133 | - temp = (char *) hdr; | |
134 | - temp1 = temp + sizeof (struct ar_hdr) - 2; | |
135 | - for (; temp < temp1; temp++) | |
136 | - { | |
137 | - if (*temp == '\0') | |
138 | - *temp = ' '; | |
139 | - } | |
140 | - strncpy (hdr->ar_fmag, ARFMAG, 2); | |
141 | + _bfd_ar_spacepad (hdr->ar_gid, sizeof (hdr->ar_gid), "%ld", | |
142 | + (long) status.st_gid); | |
143 | + _bfd_ar_spacepad (hdr->ar_mode, sizeof (hdr->ar_mode), "%-8lo", | |
144 | + (unsigned int) status.st_mode); | |
145 | + _bfd_ar_spacepad (hdr->ar_size, sizeof (hdr->ar_size), "%-10ld", | |
146 | + (long) status.st_size); | |
147 | + memcpy (hdr->ar_fmag, ARFMAG, 2); | |
148 | ared->parsed_size = status.st_size; | |
149 | ared->arch_header = (char *) hdr; | |
150 | ||
151 | @@ -1600,7 +1597,6 @@ _bfd_write_archive_contents (bfd *arch) | |
152 | /* If no .o's, don't bother to make a map. */ | |
153 | bfd_boolean hasobjects = FALSE; | |
154 | bfd_size_type wrote; | |
155 | - unsigned int i; | |
156 | int tries; | |
157 | ||
158 | /* Verify the viability of all entries; if any of them live in the | |
159 | @@ -1657,15 +1653,12 @@ _bfd_write_archive_contents (bfd *arch) | |
160 | { | |
161 | struct ar_hdr hdr; | |
162 | ||
163 | - memset (&hdr, 0, sizeof (struct ar_hdr)); | |
164 | - strcpy (hdr.ar_name, ename); | |
165 | + memset (&hdr, ' ', sizeof (struct ar_hdr)); | |
166 | + memcpy (hdr.ar_name, ename, strlen (ename)); | |
167 | /* Round size up to even number in archive header. */ | |
168 | - sprintf (&(hdr.ar_size[0]), "%-10d", | |
169 | - (int) ((elength + 1) & ~(bfd_size_type) 1)); | |
170 | - strncpy (hdr.ar_fmag, ARFMAG, 2); | |
171 | - for (i = 0; i < sizeof (struct ar_hdr); i++) | |
172 | - if (((char *) (&hdr))[i] == '\0') | |
173 | - (((char *) (&hdr))[i]) = ' '; | |
174 | + _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", | |
175 | + (int) ((elength + 1) & ~(bfd_size_type) 1)); | |
176 | + memcpy (hdr.ar_fmag, ARFMAG, 2); | |
177 | if ((bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch) | |
178 | != sizeof (struct ar_hdr)) | |
179 | || bfd_bwrite (etable, elength, arch) != elength) | |
180 | @@ -1899,25 +1892,22 @@ bsd_write_armap (bfd *arch, | |
181 | unsigned int count; | |
182 | struct ar_hdr hdr; | |
183 | struct stat statbuf; | |
184 | - unsigned int i; | |
185 | ||
186 | firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG; | |
187 | ||
188 | stat (arch->filename, &statbuf); | |
189 | - memset (&hdr, 0, sizeof (struct ar_hdr)); | |
190 | - sprintf (hdr.ar_name, RANLIBMAG); | |
191 | + memset (&hdr, ' ', sizeof (struct ar_hdr)); | |
192 | + memcpy (hdr.ar_name, RANLIBMAG, strlen (RANLIBMAG)); | |
193 | /* Remember the timestamp, to keep it holy. But fudge it a little. */ | |
194 | bfd_ardata (arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET; | |
195 | bfd_ardata (arch)->armap_datepos = (SARMAG | |
196 | + offsetof (struct ar_hdr, ar_date[0])); | |
197 | - sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp); | |
198 | - sprintf (hdr.ar_uid, "%ld", (long) getuid ()); | |
199 | - sprintf (hdr.ar_gid, "%ld", (long) getgid ()); | |
200 | - sprintf (hdr.ar_size, "%-10d", (int) mapsize); | |
201 | - strncpy (hdr.ar_fmag, ARFMAG, 2); | |
202 | - for (i = 0; i < sizeof (struct ar_hdr); i++) | |
203 | - if (((char *) (&hdr))[i] == '\0') | |
204 | - (((char *) (&hdr))[i]) = ' '; | |
205 | + _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", | |
206 | + bfd_ardata (arch)->armap_timestamp); | |
207 | + _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", (long) getuid ()); | |
208 | + _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", (long) getgid ()); | |
209 | + _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", (int) mapsize); | |
210 | + memcpy (hdr.ar_fmag, ARFMAG, 2); | |
211 | if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch) | |
212 | != sizeof (struct ar_hdr)) | |
213 | return FALSE; | |
214 | @@ -1982,7 +1972,6 @@ _bfd_archive_bsd_update_armap_timestamp | |
215 | { | |
216 | struct stat archstat; | |
217 | struct ar_hdr hdr; | |
218 | - unsigned int i; | |
219 | ||
220 | /* Flush writes, get last-write timestamp from file, and compare it | |
221 | to the timestamp IN the file. */ | |
222 | @@ -2002,11 +1991,9 @@ _bfd_archive_bsd_update_armap_timestamp | |
223 | bfd_ardata (arch)->armap_timestamp = archstat.st_mtime + ARMAP_TIME_OFFSET; | |
224 | ||
225 | /* Prepare an ASCII version suitable for writing. */ | |
226 | - memset (hdr.ar_date, 0, sizeof (hdr.ar_date)); | |
227 | - sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp); | |
228 | - for (i = 0; i < sizeof (hdr.ar_date); i++) | |
229 | - if (hdr.ar_date[i] == '\0') | |
230 | - (hdr.ar_date)[i] = ' '; | |
231 | + memset (hdr.ar_date, ' ', sizeof (hdr.ar_date)); | |
232 | + _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", | |
233 | + bfd_ardata (arch)->armap_timestamp); | |
234 | ||
235 | /* Write it into the file. */ | |
236 | bfd_ardata (arch)->armap_datepos = (SARMAG | |
237 | @@ -2054,7 +2041,6 @@ coff_write_armap (bfd *arch, | |
238 | bfd *current = arch->archive_head; | |
239 | unsigned int count; | |
240 | struct ar_hdr hdr; | |
241 | - unsigned int i; | |
242 | int padit = mapsize & 1; | |
243 | ||
244 | if (padit) | |
245 | @@ -2066,19 +2052,17 @@ coff_write_armap (bfd *arch, | |
246 | + sizeof (struct ar_hdr) | |
247 | + SARMAG); | |
248 | ||
249 | - memset (&hdr, 0, sizeof (struct ar_hdr)); | |
250 | + memset (&hdr, ' ', sizeof (struct ar_hdr)); | |
251 | hdr.ar_name[0] = '/'; | |
252 | - sprintf (hdr.ar_size, "%-10d", (int) mapsize); | |
253 | - sprintf (hdr.ar_date, "%ld", (long) time (NULL)); | |
254 | + _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", | |
255 | + (int) mapsize); | |
256 | + _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", | |
257 | + (long) time (NULL)); | |
258 | /* This, at least, is what Intel coff sets the values to. */ | |
259 | - sprintf ((hdr.ar_uid), "%d", 0); | |
260 | - sprintf ((hdr.ar_gid), "%d", 0); | |
261 | - sprintf ((hdr.ar_mode), "%-7o", (unsigned) 0); | |
262 | - strncpy (hdr.ar_fmag, ARFMAG, 2); | |
263 | - | |
264 | - for (i = 0; i < sizeof (struct ar_hdr); i++) | |
265 | - if (((char *) (&hdr))[i] == '\0') | |
266 | - (((char *) (&hdr))[i]) = ' '; | |
267 | + _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", 0); | |
268 | + _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", 0); | |
269 | + _bfd_ar_spacepad (hdr.ar_mode, sizeof (hdr.ar_mode), "%-7lo", 0); | |
270 | + memcpy (hdr.ar_fmag, ARFMAG, 2); | |
271 | ||
272 | /* Write the ar header for this item and the number of symbols. */ | |
273 | if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch) | |
274 | --- bfd/archive64.c.jj 2003-07-02 17:01:47.000000000 +0200 | |
275 | +++ bfd/archive64.c 2005-03-07 11:11:36.334668270 +0100 | |
276 | @@ -156,7 +156,6 @@ bfd_elf64_archive_write_armap (bfd *arch | |
277 | bfd *current = arch->archive_head; | |
278 | unsigned int count; | |
279 | struct ar_hdr hdr; | |
280 | - unsigned int i; | |
281 | int padding; | |
282 | bfd_byte buf[8]; | |
283 | ||
284 | @@ -169,19 +168,17 @@ bfd_elf64_archive_write_armap (bfd *arch | |
285 | + sizeof (struct ar_hdr) | |
286 | + SARMAG); | |
287 | ||
288 | - memset (&hdr, 0, sizeof (struct ar_hdr)); | |
289 | - strcpy (hdr.ar_name, "/SYM64/"); | |
290 | - sprintf (hdr.ar_size, "%-10d", (int) mapsize); | |
291 | - sprintf (hdr.ar_date, "%ld", (long) time (NULL)); | |
292 | + memset (&hdr, ' ', sizeof (struct ar_hdr)); | |
293 | + memcpy (hdr.ar_name, "/SYM64/", strlen ("/SYM64/")); | |
294 | + _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", | |
295 | + (int) mapsize); | |
296 | + _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", | |
297 | + (long) time (NULL)); | |
298 | /* This, at least, is what Intel coff sets the values to.: */ | |
299 | - sprintf ((hdr.ar_uid), "%d", 0); | |
300 | - sprintf ((hdr.ar_gid), "%d", 0); | |
301 | - sprintf ((hdr.ar_mode), "%-7o", (unsigned) 0); | |
302 | - strncpy (hdr.ar_fmag, ARFMAG, 2); | |
303 | - | |
304 | - for (i = 0; i < sizeof (struct ar_hdr); i++) | |
305 | - if (((char *) (&hdr))[i] == '\0') | |
306 | - (((char *) (&hdr))[i]) = ' '; | |
307 | + _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", 0); | |
308 | + _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", 0); | |
309 | + _bfd_ar_spacepad (hdr.ar_mode, sizeof (hdr.ar_mode), "%-7lo", 0); | |
310 | + memcpy (hdr.ar_fmag, ARFMAG, 2); | |
311 | ||
312 | /* Write the ar header for this item and the number of symbols */ | |
313 |