opncls.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 685 行 · 第 1/2 页

C
685
字号
     CONST char *target;{  bfd *nbfd;  const bfd_target *target_vec;  bfd_set_error (bfd_error_system_call);  /* nbfd has to point to head of malloc'ed block so that bfd_close may     reclaim it correctly. */  nbfd = _bfd_new_bfd ();  if (nbfd == NULL)    return NULL;  target_vec = bfd_find_target (target, nbfd);  if (target_vec == NULL)    {      objalloc_free ((struct objalloc *) nbfd->memory);      free (nbfd);      return NULL;    }  nbfd->filename = filename;  nbfd->direction = write_direction;  if (bfd_open_file (nbfd) == NULL)    {      bfd_set_error (bfd_error_system_call);	/* File not writeable, etc */      objalloc_free ((struct objalloc *) nbfd->memory);      free (nbfd);      return NULL;  }  return nbfd;}/*FUNCTION	bfd_closeSYNOPSIS	boolean bfd_close(bfd *abfd);DESCRIPTION	Close a BFD. If the BFD was open for writing,	then pending operations are completed and the file written out	and closed. If the created file is executable, then	<<chmod>> is called to mark it as such.	All memory attached to the BFD is released.	The file descriptor associated with the BFD is closed (even	if it was passed in to BFD by <<bfd_fdopenr>>).RETURNS	<<true>> is returned if all is ok, otherwise <<false>>.*/booleanbfd_close (abfd)     bfd *abfd;{  boolean ret;  if (!bfd_read_p (abfd))    {      if (! BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd)))	return false;    }  if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))    return false;  ret = bfd_cache_close (abfd);  /* If the file was open for writing and is now executable,     make it so */  if (ret      && abfd->direction == write_direction      && abfd->flags & EXEC_P)    {      struct stat buf;      if (stat (abfd->filename, &buf) == 0)	{ 	  int mask = umask (0);	  umask (mask);	  chmod (abfd->filename,		 (0777		  & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));	}    }  objalloc_free ((struct objalloc *) abfd->memory);  free (abfd);  return ret;}/*FUNCTION	bfd_close_all_doneSYNOPSIS	boolean bfd_close_all_done(bfd *);DESCRIPTION	Close a BFD.  Differs from <<bfd_close>>	since it does not complete any pending operations.  This	routine would be used if the application had just used BFD for	swapping and didn't want to use any of the writing code.	If the created file is executable, then <<chmod>> is called	to mark it as such.	All memory attached to the BFD is released.RETURNS	<<true>> is returned if all is ok, otherwise <<false>>.*/booleanbfd_close_all_done (abfd)     bfd *abfd;{  boolean ret;  ret = bfd_cache_close (abfd);  /* If the file was open for writing and is now executable,     make it so */  if (ret      && abfd->direction == write_direction      && abfd->flags & EXEC_P)    {      struct stat buf;      if (stat (abfd->filename, &buf) == 0)	{	  int mask = umask (0);	  umask (mask);	  chmod (abfd->filename,		 (0777		  & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));	}    }  objalloc_free ((struct objalloc *) abfd->memory);  free (abfd);  return ret;}/*FUNCTION	bfd_createSYNOPSIS	bfd *bfd_create(CONST char *filename, bfd *templ);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>>.*/bfd *bfd_create (filename, templ)     CONST char *filename;     bfd *templ;{  bfd *nbfd;  nbfd = _bfd_new_bfd ();  if (nbfd == NULL)    return NULL;  nbfd->filename = filename;  if (templ)    nbfd->xvec = templ->xvec;  nbfd->direction = no_direction;  bfd_set_format (nbfd, bfd_object);  return nbfd;}/*FUNCTION	bfd_make_writableSYNOPSIS	boolean bfd_make_writable(bfd *abfd);DESCRIPTION	Takes a BFD as created by <<bfd_create>> and converts it	into one like as returned by <<bfd_openw>>.  It does this	by converting the BFD to BFD_IN_MEMORY.  It's assumed that	you will call <<bfd_make_readable>> on this bfd later.RETURNS	<<true>> is returned if all is ok, otherwise <<false>>.*/booleanbfd_make_writable(abfd)     bfd *abfd;{  struct bfd_in_memory *bim;  if (abfd->direction != no_direction)    {      bfd_set_error (bfd_error_invalid_operation);      return false;    }  bim = (struct bfd_in_memory *) bfd_malloc (sizeof (struct bfd_in_memory));  abfd->iostream = (PTR) bim;  /* bfd_write will grow these as needed */  bim->size = 0;  bim->buffer = 0;  abfd->flags |= BFD_IN_MEMORY;  abfd->direction = write_direction;  abfd->where = 0;  return true;}/*FUNCTION	bfd_make_readableSYNOPSIS	boolean bfd_make_readable(bfd *abfd);DESCRIPTION	Takes a BFD as created by <<bfd_create>> and	<<bfd_make_writable>> and converts it into one like as	returned by <<bfd_openr>>.  It does this by writing the	contents out to the memory buffer, then reversing the	direction.RETURNS	<<true>> is returned if all is ok, otherwise <<false>>.  */booleanbfd_make_readable(abfd)     bfd *abfd;{  if (abfd->direction != write_direction || !(abfd->flags & BFD_IN_MEMORY))    {      bfd_set_error (bfd_error_invalid_operation);      return false;    }  if (! BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd)))    return false;  if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))    return false;  abfd->arch_info = &bfd_default_arch_struct;  abfd->where = 0;  abfd->sections = (asection *) NULL;  abfd->format = bfd_unknown;  abfd->my_archive = (bfd *) NULL;  abfd->origin = 0;				  abfd->opened_once = false;  abfd->output_has_begun = false;  abfd->section_count = 0;  abfd->usrdata = (PTR) NULL;  abfd->cacheable = false;  abfd->flags = BFD_IN_MEMORY;  abfd->mtime_set = false;  abfd->target_defaulted = true;  abfd->direction = read_direction;  abfd->sections = 0;  abfd->symcount = 0;  abfd->outsymbols = 0;  abfd->tdata.any = 0;  bfd_check_format(abfd, bfd_object);  return true;}/*INTERNAL_FUNCTION	bfd_allocSYNOPSIS	PTR bfd_alloc (bfd *abfd, size_t wanted);DESCRIPTION	Allocate a block of @var{wanted} bytes of memory attached to	<<abfd>> and return a pointer to it.*/PTRbfd_alloc (abfd, size)     bfd *abfd;     size_t size;{  PTR ret;  ret = objalloc_alloc (abfd->memory, (unsigned long) size);  if (ret == NULL)    bfd_set_error (bfd_error_no_memory);  return ret;}PTRbfd_zalloc (abfd, size)     bfd *abfd;     size_t size;{  PTR res;  res = bfd_alloc (abfd, size);  if (res)    memset (res, 0, size);  return res;}/* Free a block allocated for a BFD.  */voidbfd_release (abfd, block)     bfd *abfd;     PTR block;{  objalloc_free_block ((struct objalloc *) abfd->memory, block);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?