o - all arch headers are the same size (across architectures).
*/
-/* $Id$
- */
-
+/* $Id$ */
#include "sysdep.h"
#include "bfd.h"
#define arch_hdr(bfd) ((struct ar_hdr *) \
(((struct areltdata *)((bfd)->arelt_data))->arch_header))
-
\f
-
boolean
_bfd_generic_mkarchive (abfd)
bfd *abfd;
{
- abfd->tdata = bfd_zalloc(abfd, sizeof (struct artdata));
+ set_tdata (abfd, bfd_zalloc(abfd, sizeof (struct artdata)));
- if (abfd->tdata == NULL) {
+ if (bfd_ardata (abfd) == NULL) {
bfd_error = no_memory;
return false;
}
symindex
bfd_get_next_mapent (abfd, prev, entry)
bfd *abfd;
- symindex prev;
+ symindex prev;
carsym **entry;
{
if (!bfd_has_map (abfd)) {
}
if (prev == BFD_NO_MORE_SYMBOLS) prev = 0;
- else if (++prev >= (symindex)(bfd_ardata (abfd)->symdef_count))
+ else if (++prev >= bfd_ardata (abfd)->symdef_count)
return BFD_NO_MORE_SYMBOLS;
*entry = (bfd_ardata (abfd)->symdefs + prev);
bfd_set_archive_head (output_archive, new_head)
bfd *output_archive, *new_head;
{
-
+
output_archive->archive_head = new_head;
return true;
}
bfd *arch_bfd, *new_elt;
file_ptr filepos;
{
- struct ar_cache *new_cache = ((struct ar_cache *)bfd_zalloc(arch_bfd,sizeof (struct ar_cache)));
+ struct ar_cache *new_cache = (struct ar_cache *)
+ bfd_zalloc(arch_bfd, sizeof (struct ar_cache));
if (new_cache == NULL) {
bfd_error = no_memory;
bfd *arch;
char *name;
{
- extern int errno;
unsigned long index = 0;
/* Should extract string so that I can guarantee not to overflow into
n_nfd = _bfd_create_empty_archive_element_shell (archive);
if (n_nfd == NULL) {
+ bfd_release (archive, (PTR)new_areldata);
return NULL;
}
n_nfd->origin = bfd_tell (archive);
return n_nfd;
/* huh? */
+ bfd_release (archive, (PTR)n_nfd);
+ bfd_release (archive, (PTR)new_areldata);
return NULL;
}
if (!last_file)
filestart = bfd_ardata (archive)->first_file_filepos;
else {
- unsigned int size = arelt_size(last_file);
- filestart = last_file->origin +size + size %2;
-}
-
-
+ unsigned int size = arelt_size(last_file);
+ /* Pad to an even boundary... */
+ filestart = last_file->origin + size + size%2;
+ }
return get_elt_at_filepos (archive, filestart);
}
if (strncmp (armag, ARMAG, SARMAG)) return 0;
#endif
- bfd_set_ardata(abfd, (struct artdata *) bfd_zalloc(abfd,sizeof (struct artdata)));
+ /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
+ involves a cast, we can't do it as the left operand of assignment. */
+ set_tdata (abfd, bfd_zalloc(abfd,sizeof (struct artdata)));
if (bfd_ardata (abfd) == NULL) {
bfd_error = no_memory;
return 0;
}
- /* armap could be left ungc'd! FIXME -- potential storage leak */
if (!BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd))) {
bfd_release(abfd, bfd_ardata (abfd));
abfd->tdata = NULL;
struct artdata *ardata = bfd_ardata (abfd);
char *stringbase;
+ /* FIXME, if the read fails, this routine quietly returns "true"!!
+ It should probably do that if the read gives 0 bytes (empty archive),
+ but fail for any other size... */
if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) {
/* The archive has at least 16 bytes in it */
bfd_seek (abfd, -16L, SEEK_CUR);
if (raw_armap == NULL) {
bfd_error = no_memory;
byebye:
+ bfd_release (abfd, (PTR)mapdata);
return false;
}
if (bfd_read ((PTR)raw_armap, 1, mapdata->parsed_size, abfd) !=
mapdata->parsed_size) {
bfd_error = malformed_archive;
+ bfd_release (abfd, (PTR)raw_armap);
goto byebye;
}
- ardata->symdef_count = *(raw_armap) / sizeof (struct symdef);
+ ardata->symdef_count = *raw_armap / sizeof (struct symdef);
ardata->cache = 0;
rbase = raw_armap+1;
ardata->symdefs = (carsym *) rbase;
stringbase = ((char *) (ardata->symdefs + ardata->symdef_count)) + 4;
- for (;counter < (unsigned)( ardata->symdef_count); counter++) {
+ for (;counter < ardata->symdef_count; counter++) {
struct symdef *sym = ((struct symdef *) rbase) + counter;
sym->s.name = sym->s.string_offset + stringbase;
}
ardata->first_file_filepos = bfd_tell (abfd);
/* Pad to an even boundary if you have to */
ardata->first_file_filepos += (ardata-> first_file_filepos) %2;
+ /* FIXME, we should provide some way to free raw_ardata when
+ we are done using the strings from it. For now, it seems
+ to be allocated on an obstack anyway... */
bfd_has_map (abfd) = true;
}
return true;
char *stringbase;
unsigned int stringsize;
carsym *carsyms;
+ int result;
- if (bfd_read ((PTR)&nextname, 1, 1, abfd) != 1) {
- bfd_seek (abfd, -1L, SEEK_CUR);
- bfd_has_map(abfd) = false;
- return true;
- }
+ result = bfd_read ((PTR)&nextname, 1, 1, abfd);
bfd_seek (abfd, -1L, SEEK_CUR);
- if (nextname != '/') {
+ if (result != 1 || nextname != '/') {
/* Actually I think this is an error for a COFF archive */
bfd_has_map (abfd) = false;
return true;
if (raw_armap == NULL) {
bfd_error = no_memory;
byebye:
-
+ bfd_release (abfd, (PTR)mapdata);
return false;
}
mapdata->parsed_size) {
bfd_error = malformed_archive;
oops:
-
+ bfd_release (abfd, (PTR)raw_armap);
goto byebye;
}
ardata->first_file_filepos = bfd_tell (abfd);
/* Pad to an even boundary if you have to */
ardata->first_file_filepos += (ardata->first_file_filepos) %2;
-
+ bfd_release (abfd, (PTR)raw_armap);
+ bfd_release (abfd, (PTR)mapdata);
bfd_has_map (abfd) = true;
return true;
}
-
\f
/** Extended name table.
char nextname[17];
struct areltdata *namedata;
+ /* FIXME: Formatting sucks here, and in case of failure of BFD_READ,
+ we probably don't want to return true. */
if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) {
bfd_seek (abfd, -16L, SEEK_CUR);
namedata = snarf_ar_hdr (abfd);
if (namedata == NULL) return false;
-
bfd_ardata (abfd)->extended_names = bfd_zalloc(abfd,namedata->parsed_size);
if (bfd_ardata (abfd)->extended_names == NULL) {
bfd_error = no_memory;
byebye:
-
+ bfd_release (abfd, (PTR)namedata);
return false;
}
if (bfd_read ((PTR)bfd_ardata (abfd)->extended_names, 1,
namedata->parsed_size, abfd) != namedata->parsed_size) {
bfd_error = malformed_archive;
-
+ bfd_release (abfd, (PTR)(bfd_ardata (abfd)->extended_names));
bfd_ardata (abfd)->extended_names = NULL;
goto byebye;
}
bfd_ardata (abfd)->first_file_filepos +=
(bfd_ardata (abfd)->first_file_filepos) %2;
-
+ /* FIXME, we can't release namedata here because it was allocated
+ below extended_names on the obstack... */
+ /* bfd_release (abfd, namedata); */
}
return true;
}
char *pathname;
char *arhdr;
{
- /* This interacts unpleasantly with ar's quick-append option.
+ /* FIXME: This interacts unpleasantly with ar's quick-append option.
Fortunately ic960 users will never use that option. Fixing this
is very hard; fortunately I know how to do it and will do so once
intel's release is out the door. */
boolean hasobjects = false; /* if no .o's, don't bother to make a map */
unsigned int i;
-
/* Verify the viability of all entries; if any of them live in the
filesystem (as opposed to living in an archive open for input)
then construct a fresh ar_hdr for them.
\f
/* Note that the namidx for the first symbol is 0 */
-
-
boolean
compute_and_write_armap (arch, elength)
bfd *arch;