OLD | NEW |
1 /* Low-level I/O routines for BFDs. | 1 /* Low-level I/O routines for BFDs. |
2 | 2 |
3 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | 3 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
4 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 | 4 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 |
5 Free Software Foundation, Inc. | 5 Free Software Foundation, Inc. |
6 | 6 |
7 Written by Cygnus Support. | 7 Written by Cygnus Support. |
8 | 8 |
9 This file is part of BFD, the Binary File Descriptor library. | 9 This file is part of BFD, the Binary File Descriptor library. |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 fcntl (fd, F_SETFD, old | FD_CLOEXEC); | 80 fcntl (fd, F_SETFD, old | FD_CLOEXEC); |
81 } | 81 } |
82 #endif | 82 #endif |
83 return file; | 83 return file; |
84 } | 84 } |
85 | 85 |
86 FILE * | 86 FILE * |
87 real_fopen (const char *filename, const char *modes) | 87 real_fopen (const char *filename, const char *modes) |
88 { | 88 { |
89 #ifdef VMS | 89 #ifdef VMS |
90 char vms_modes[4]; | |
91 char *vms_attr; | 90 char *vms_attr; |
92 | 91 |
93 /* On VMS, fopen allows file attributes as optionnal arguments. | 92 /* On VMS, fopen allows file attributes as optionnal arguments. |
94 We need to use them but we'd better to use the common prototype. | 93 We need to use them but we'd better to use the common prototype. |
95 In fopen-vms.h, they are separated from the mode with a comma. | 94 In fopen-vms.h, they are separated from the mode with a comma. |
96 Split here. */ | 95 Split here. */ |
97 vms_attr = strchr (modes, ','); | 96 vms_attr = strchr (modes, ','); |
98 if (vms_attr == NULL) | 97 if (vms_attr == NULL) |
99 { | 98 { |
100 /* No attributes. */ | 99 /* No attributes. */ |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 177 |
179 bfd_size_type | 178 bfd_size_type |
180 bfd_bread (void *ptr, bfd_size_type size, bfd *abfd) | 179 bfd_bread (void *ptr, bfd_size_type size, bfd *abfd) |
181 { | 180 { |
182 size_t nread; | 181 size_t nread; |
183 | 182 |
184 /* If this is an archive element, don't read past the end of | 183 /* If this is an archive element, don't read past the end of |
185 this element. */ | 184 this element. */ |
186 if (abfd->arelt_data != NULL) | 185 if (abfd->arelt_data != NULL) |
187 { | 186 { |
188 size_t maxbytes = ((struct areltdata *) abfd->arelt_data)->parsed_size; | 187 bfd_size_type maxbytes = arelt_size (abfd); |
| 188 |
189 if (abfd->where + size > maxbytes) | 189 if (abfd->where + size > maxbytes) |
190 { | 190 { |
191 if (abfd->where >= maxbytes) | 191 if (abfd->where >= maxbytes) |
192 return 0; | 192 return 0; |
193 size = maxbytes - abfd->where; | 193 size = maxbytes - abfd->where; |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 if (abfd->iovec) | 197 if (abfd->iovec) |
198 nread = abfd->iovec->bread (abfd, ptr, size); | 198 nread = abfd->iovec->bread (abfd, ptr, size); |
(...skipping 27 matching lines...) Expand all Loading... |
226 return nwrote; | 226 return nwrote; |
227 } | 227 } |
228 | 228 |
229 file_ptr | 229 file_ptr |
230 bfd_tell (bfd *abfd) | 230 bfd_tell (bfd *abfd) |
231 { | 231 { |
232 file_ptr ptr; | 232 file_ptr ptr; |
233 | 233 |
234 if (abfd->iovec) | 234 if (abfd->iovec) |
235 { | 235 { |
| 236 bfd *parent_bfd = abfd; |
236 ptr = abfd->iovec->btell (abfd); | 237 ptr = abfd->iovec->btell (abfd); |
237 | 238 |
238 if (abfd->my_archive) | 239 while (parent_bfd->my_archive != NULL) |
239 » ptr -= abfd->origin; | 240 » { |
| 241 » ptr -= parent_bfd->origin; |
| 242 » parent_bfd = parent_bfd->my_archive; |
| 243 » } |
240 } | 244 } |
241 else | 245 else |
242 ptr = 0; | 246 ptr = 0; |
243 | 247 |
244 abfd->where = ptr; | 248 abfd->where = ptr; |
245 return ptr; | 249 return ptr; |
246 } | 250 } |
247 | 251 |
248 int | 252 int |
249 bfd_flush (bfd *abfd) | 253 bfd_flush (bfd *abfd) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 well as in any other component. | 305 well as in any other component. |
302 | 306 |
303 It might be sufficient to put a spike through the cache | 307 It might be sufficient to put a spike through the cache |
304 abstraction, and look to the archive for the file position, | 308 abstraction, and look to the archive for the file position, |
305 but I think we should try for something cleaner. | 309 but I think we should try for something cleaner. |
306 | 310 |
307 In the meantime, no optimization for archives. */ | 311 In the meantime, no optimization for archives. */ |
308 } | 312 } |
309 | 313 |
310 file_position = position; | 314 file_position = position; |
311 if (direction == SEEK_SET && abfd->my_archive != NULL) | 315 if (direction == SEEK_SET) |
312 file_position += abfd->origin; | 316 { |
| 317 bfd *parent_bfd = abfd; |
| 318 |
| 319 while (parent_bfd->my_archive != NULL) |
| 320 { |
| 321 file_position += parent_bfd->origin; |
| 322 parent_bfd = parent_bfd->my_archive; |
| 323 } |
| 324 } |
313 | 325 |
314 if (abfd->iovec) | 326 if (abfd->iovec) |
315 result = abfd->iovec->bseek (abfd, file_position, direction); | 327 result = abfd->iovec->bseek (abfd, file_position, direction); |
316 else | 328 else |
317 result = -1; | 329 result = -1; |
318 | 330 |
319 if (result != 0) | 331 if (result != 0) |
320 { | 332 { |
321 int hold_errno = errno; | 333 int hold_errno = errno; |
322 | 334 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 bfd_size_type *map_len ATTRIBUTE_UNUSED) | 614 bfd_size_type *map_len ATTRIBUTE_UNUSED) |
603 { | 615 { |
604 return (void *)-1; | 616 return (void *)-1; |
605 } | 617 } |
606 | 618 |
607 const struct bfd_iovec _bfd_memory_iovec = | 619 const struct bfd_iovec _bfd_memory_iovec = |
608 { | 620 { |
609 &memory_bread, &memory_bwrite, &memory_btell, &memory_bseek, | 621 &memory_bread, &memory_bwrite, &memory_btell, &memory_bseek, |
610 &memory_bclose, &memory_bflush, &memory_bstat, &memory_bmmap | 622 &memory_bclose, &memory_bflush, &memory_bstat, &memory_bmmap |
611 }; | 623 }; |
OLD | NEW |