/* opncls.c -- open and close a BFD.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
- 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
Written by Cygnus Support.
#define S_IXOTH 0001 /* Execute by others. */
#endif
-/* Counter used to initialize the bfd identifier. */
+/* Counters used to initialize the bfd identifier. */
-static unsigned int _bfd_id_counter = 0;
+static unsigned int bfd_id_counter = 0;
+static unsigned int bfd_reserved_id_counter = 0;
+
+/*
+CODE_FRAGMENT
+.{* Set to N to open the next N BFDs using an alternate id space. *}
+.extern unsigned int bfd_use_reserved_id;
+*/
+unsigned int bfd_use_reserved_id = 0;
/* fdopen is a loser -- we should use stdio exclusively. Unfortunately
if we do that we can't use fcntl. */
if (nbfd == NULL)
return NULL;
- nbfd->id = _bfd_id_counter++;
+ if (bfd_use_reserved_id)
+ {
+ nbfd->id = --bfd_reserved_id_counter;
+ --bfd_use_reserved_id;
+ }
+ else
+ nbfd->id = bfd_id_counter++;
nbfd->memory = objalloc_create ();
if (nbfd->memory == NULL)
bfd *
bfd_openr_iovec (const char *filename, const char *target,
- void *(*_open) (struct bfd *, void *),
+ void *(*open_p) (struct bfd *, void *),
void *open_closure,
- file_ptr (*_pread) (struct bfd *, void *, void *, file_ptr,
- file_ptr),
- int (*_close) (struct bfd *, void *),
- int (*_stat) (struct bfd *, void *, struct stat *))
+ file_ptr (*pread_p) (struct bfd *, void *, void *,
+ file_ptr, file_ptr),
+ int (*close_p) (struct bfd *, void *),
+ int (*stat_p) (struct bfd *, void *, struct stat *))
{
bfd *nbfd;
const bfd_target *target_vec;
nbfd->filename = filename;
nbfd->direction = read_direction;
- /* `open (...)' would get expanded by an the open(2) syscall macro. */
- stream = (*_open) (nbfd, open_closure);
+ /* `open_p (...)' would get expanded by an the open(2) syscall macro. */
+ stream = (*open_p) (nbfd, open_closure);
if (stream == NULL)
{
_bfd_delete_bfd (nbfd);
vec = (struct opncls *) bfd_zalloc (nbfd, sizeof (struct opncls));
vec->stream = stream;
- vec->pread = _pread;
- vec->close = _close;
- vec->stat = _stat;
+ vec->pread = pread_p;
+ vec->close = close_p;
+ vec->stat = stat_p;
nbfd->iovec = &opncls_iovec;
nbfd->iostream = vec;
if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
return FALSE;
- if ((abfd->flags & BFD_IN_MEMORY) != 0)
- {
- /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
- vector.
- Until that's done, at least don't leak memory. */
- struct bfd_in_memory *bim = (struct bfd_in_memory *) abfd->iostream;
-
- if (bim->buffer != NULL)
- free (bim->buffer);
- free (bim);
- ret = TRUE;
- }
- else
- ret = abfd->iovec->bclose (abfd);
+ ret = abfd->iovec->bclose (abfd);
if (ret)
_maybe_make_executable (abfd);
DESCRIPTION
Create a new BFD in the manner of <<bfd_openw>>, but without
opening a file. The new BFD takes the target from the target
- used by @var{template}. The format is always set to <<bfd_object>>.
+ used by @var{templ}. The format is always set to <<bfd_object>>.
*/
bfd *
bim->buffer = 0;
abfd->flags |= BFD_IN_MEMORY;
+ abfd->iovec = &_bfd_memory_iovec;
+ abfd->origin = 0;
abfd->direction = write_direction;
abfd->where = 0;
if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
return FALSE;
-
abfd->arch_info = &bfd_default_arch_struct;
abfd->where = 0;
}
/*
-INTERNAL_FUNCTION
+FUNCTION
bfd_alloc
SYNOPSIS
}
/*
-INTERNAL_FUNCTION
+FUNCTION
bfd_zalloc
SYNOPSIS