home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / bfd / archive.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  52KB  |  1,799 lines

  1. /* BFD back-end for archive files (libraries).
  2.    Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.  Mostly Gumby Henkel-Wallace's fault.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /*
  22. @setfilename archive-info
  23. SECTION
  24.     Archives
  25.  
  26. DESCRIPTION
  27.     An archive (or library) is just another BFD.  It has a symbol
  28.     table, although there's not much a user program will do with it.
  29.  
  30.     The big difference between an archive BFD and an ordinary BFD
  31.     is that the archive doesn't have sections.  Instead it has a
  32.     chain of BFDs that are considered its contents.  These BFDs can
  33.     be manipulated like any other.  The BFDs contained in an
  34.     archive opened for reading will all be opened for reading.  You
  35.     may put either input or output BFDs into an archive opened for
  36.     output; they will be handled correctly when the archive is closed.
  37.  
  38.     Use <<bfd_openr_next_archived_file>> to step through
  39.     the contents of an archive opened for input.  You don't
  40.     have to read the entire archive if you don't want
  41.     to!  Read it until you find what you want.
  42.  
  43.     Archive contents of output BFDs are chained through the
  44.     <<next>> pointer in a BFD.  The first one is findable through
  45.     the <<archive_head>> slot of the archive.  Set it with
  46.     <<bfd_set_archive_head>> (q.v.).  A given BFD may be in only one
  47.     open output archive at a time.
  48.  
  49.     As expected, the BFD archive code is more general than the
  50.     archive code of any given environment.  BFD archives may
  51.     contain files of different formats (e.g., a.out and coff) and
  52.     even different architectures.  You may even place archives
  53.     recursively into archives!
  54.  
  55.     This can cause unexpected confusion, since some archive
  56.     formats are more expressive than others.  For instance, Intel
  57.     COFF archives can preserve long filenames; SunOS a.out archives
  58.     cannot.  If you move a file from the first to the second
  59.     format and back again, the filename may be truncated.
  60.     Likewise, different a.out environments have different
  61.     conventions as to how they truncate filenames, whether they
  62.     preserve directory names in filenames, etc.  When
  63.     interoperating with native tools, be sure your files are
  64.     homogeneous.
  65.  
  66.     Beware: most of these formats do not react well to the
  67.     presence of spaces in filenames.  We do the best we can, but
  68.     can't always handle this case due to restrictions in the format of
  69.     archives.  Many Unix utilities are braindead in regards to
  70.     spaces and such in filenames anyway, so this shouldn't be much
  71.     of a restriction.
  72.  
  73.     Archives are supported in BFD in <<archive.c>>.
  74.  
  75. */
  76.  
  77. /* Assumes:
  78.    o - all archive elements start on an even boundary, newline padded;
  79.    o - all arch headers are char *;
  80.    o - all arch headers are the same size (across architectures).
  81. */
  82.  
  83. /* Some formats provide a way to cram a long filename into the short
  84.    (16 chars) space provided by a BSD archive.  The trick is: make a
  85.    special "file" in the front of the archive, sort of like the SYMDEF
  86.    entry.  If the filename is too long to fit, put it in the extended
  87.    name table, and use its index as the filename.  To prevent
  88.    confusion prepend the index with a space.  This means you can't
  89.    have filenames that start with a space, but then again, many Unix
  90.    utilities can't handle that anyway.
  91.  
  92.    This scheme unfortunately requires that you stand on your head in
  93.    order to write an archive since you need to put a magic file at the
  94.    front, and need to touch every entry to do so.  C'est la vie.
  95.  
  96.    We support two variants of this idea:
  97.    The SVR4 format (extended name table is named "//"),
  98.    and an extended pseudo-BSD variant (extended name table is named
  99.    "ARFILENAMES/").  The origin of the latter format is uncertain.
  100.  
  101.    BSD 4.4 uses a third scheme:  It writes a long filename
  102.    directly after the header.  This allows 'ar q' to work.
  103.    We currently can read BSD 4.4 archives, but not write them.
  104. */
  105.  
  106. /* Summary of archive member names:
  107.  
  108.  Symbol table (must be first):
  109.  "__.SYMDEF       " - Symbol table, Berkeley style, produced by ranlib.
  110.  "/               " - Symbol table, system 5 style.
  111.  
  112.  Long name table (must be before regular file members):
  113.  "//              " - Long name table, System 5 R4 style.
  114.  "ARFILENAMES/    " - Long name table, non-standard extended BSD (not BSD 4.4).
  115.  
  116.  Regular file members with short names:
  117.  "filename.o/     " - Regular file, System 5 style (embedded spaces ok).
  118.  "filename.o      " - Regular file, Berkeley style (no embedded spaces).
  119.  
  120.  Regular files with long names (or embedded spaces, for BSD variants):
  121.  "/18             " - SVR4 style, name at offset 18 in name table.
  122.  "#1/23           " - Long name (or embedded paces) 23 characters long,
  123.               BSD 4.4 style, full name follows header.
  124.               Implemented for reading, not writing.
  125.  " 18             " - Long name 18 characters long, extended pseudo-BSD.
  126.  */
  127.  
  128. #include "bfd.h"
  129. #include "sysdep.h"
  130. #include "libbfd.h"
  131. #include "aout/ar.h"
  132. #include "aout/ranlib.h"
  133. #include <errno.h>
  134. #include <string.h>        /* For memchr, strrchr and friends */
  135. #include <ctype.h>
  136.  
  137. #ifndef errno
  138. extern int errno;
  139. #endif
  140.  
  141. #ifdef GNU960
  142. #define BFD_GNU960_ARMAG(abfd)    (BFD_COFF_FILE_P((abfd)) ? ARMAG : ARMAGB)
  143. #endif
  144.  
  145. /* Can't define this in hosts/foo.h, because (e.g. in gprof) the hosts file
  146.    is included, then obstack.h, which thinks if offsetof is defined, it
  147.    doesn't need to include stddef.h.  */
  148. /* Define offsetof for those systems which lack it */
  149.  
  150. #if !defined (offsetof)
  151. #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
  152. #endif
  153.  
  154. /* We keep a cache of archive filepointers to archive elements to
  155.    speed up searching the archive by filepos.  We only add an entry to
  156.    the cache when we actually read one.  We also don't sort the cache;
  157.    it's generally short enough to search linearly.
  158.    Note that the pointers here point to the front of the ar_hdr, not
  159.    to the front of the contents!
  160. */
  161. struct ar_cache {
  162.   file_ptr ptr;
  163.   bfd* arelt;
  164.   struct ar_cache *next;
  165. };
  166.  
  167. #define ar_padchar(abfd) ((abfd)->xvec->ar_pad_char)
  168. #define ar_maxnamelen(abfd) ((abfd)->xvec->ar_max_namelen)
  169.  
  170. #define arch_eltdata(bfd) ((struct areltdata *)((bfd)->arelt_data))
  171. #define arch_hdr(bfd) ((struct ar_hdr *)arch_eltdata(bfd)->arch_header)
  172.  
  173. static char *get_extended_arelt_filename PARAMS ((bfd *arch,
  174.                           const char *name));
  175. static boolean do_slurp_bsd_armap PARAMS ((bfd *abfd));
  176. static boolean do_slurp_coff_armap PARAMS ((bfd *abfd));
  177. static const char *normalize PARAMS ((const char *file));
  178. static boolean bfd_construct_extended_name_table PARAMS ((bfd *abfd,
  179.                               char **tabloc,
  180.                               unsigned int *));
  181. static struct areltdata *bfd_ar_hdr_from_filesystem PARAMS ((bfd *abfd,
  182.                                  const char *));
  183. static boolean compute_and_write_armap PARAMS ((bfd *arch,
  184.                         unsigned int elength));
  185. static boolean bsd_update_armap_timestamp PARAMS ((bfd *arch));
  186.  
  187. boolean
  188. _bfd_generic_mkarchive (abfd)
  189.      bfd *abfd;
  190. {
  191.   abfd->tdata.aout_ar_data = ((struct artdata *)
  192.                   bfd_zalloc (abfd, sizeof (struct artdata)));
  193.  
  194.   if (bfd_ardata (abfd) == NULL)
  195.     {
  196.       bfd_error = no_memory;
  197.       return false;
  198.     }
  199.  
  200.   bfd_ardata (abfd)->cache = NULL;
  201.   bfd_ardata (abfd)->archive_head = NULL;
  202.   bfd_ardata (abfd)->symdefs = NULL;
  203.   bfd_ardata (abfd)->extended_names = NULL;
  204.   bfd_ardata (abfd)->tdata = NULL;
  205.  
  206.   return true;
  207. }
  208.  
  209. /*
  210. FUNCTION
  211.     bfd_get_next_mapent
  212.  
  213. SYNOPSIS
  214.     symindex bfd_get_next_mapent(bfd *abfd, symindex previous, carsym **sym);
  215.  
  216. DESCRIPTION
  217.     Step through archive @var{abfd}'s symbol table (if it
  218.     has one).  Successively update @var{sym} with the next symbol's
  219.     information, returning that symbol's (internal) index into the
  220.     symbol table.
  221.  
  222.     Supply <<BFD_NO_MORE_SYMBOLS>> as the @var{previous} entry to get
  223.     the first one; returns <<BFD_NO_MORE_SYMBOLS>> when you've already
  224.     got the last one.
  225.  
  226.     A <<carsym>> is a canonical archive symbol.  The only
  227.     user-visible element is its name, a null-terminated string.
  228. */
  229.  
  230. symindex
  231. bfd_get_next_mapent (abfd, prev, entry)
  232.      bfd *abfd;
  233.      symindex prev;
  234.      carsym **entry;
  235. {
  236.   if (!bfd_has_map (abfd)) {
  237.     bfd_error = invalid_operation;
  238.     return BFD_NO_MORE_SYMBOLS;
  239.   }
  240.   
  241.   if (prev == BFD_NO_MORE_SYMBOLS) prev = 0;
  242.   else if (++prev >= bfd_ardata (abfd)->symdef_count)
  243.     return BFD_NO_MORE_SYMBOLS;
  244.  
  245.   *entry = (bfd_ardata (abfd)->symdefs + prev);
  246.   return prev;
  247. }
  248.  
  249. /* To be called by backends only */
  250.  
  251. bfd *
  252. _bfd_create_empty_archive_element_shell (obfd)
  253.      bfd *obfd;
  254. {
  255.   bfd *nbfd;
  256.  
  257.   nbfd = new_bfd_contained_in(obfd);
  258.   if (nbfd == NULL)
  259.     {
  260.       bfd_error = no_memory;
  261.       return NULL;
  262.     }
  263.   return nbfd;
  264. }
  265.  
  266. /*
  267. FUNCTION
  268.     bfd_set_archive_head
  269.  
  270. SYNOPSIS
  271.     boolean bfd_set_archive_head(bfd *output, bfd *new_head);
  272.  
  273. DESCRIPTION
  274.     Set the head of the chain of
  275.     BFDs contained in the archive @var{output} to @var{new_head}. 
  276. */
  277.  
  278. boolean
  279. bfd_set_archive_head (output_archive, new_head)
  280.      bfd *output_archive;
  281.      bfd *new_head;
  282. {
  283.  
  284.   output_archive->archive_head = new_head;
  285.   return true;
  286. }
  287.  
  288. bfd *
  289. look_for_bfd_in_cache (arch_bfd, filepos)
  290.      bfd *arch_bfd;
  291.      file_ptr filepos;
  292. {
  293.   struct ar_cache *current;
  294.  
  295.   for (current = bfd_ardata (arch_bfd)->cache; current != NULL;
  296.        current = current->next)
  297.     if (current->ptr == filepos) return current->arelt;
  298.  
  299.   return NULL;
  300. }
  301.  
  302. /* Kind of stupid to call cons for each one, but we don't do too many */
  303. boolean
  304. _bfd_add_bfd_to_archive_cache (arch_bfd, filepos, new_elt)
  305.      bfd *arch_bfd, *new_elt;
  306.      file_ptr filepos;
  307. {
  308.   struct ar_cache *new_cache = (struct ar_cache *)
  309.                 bfd_zalloc(arch_bfd, sizeof (struct ar_cache));
  310.  
  311.   if (new_cache == NULL) {
  312.     bfd_error = no_memory;
  313.     return false;
  314.   }
  315.  
  316.   new_cache->ptr = filepos;
  317.   new_cache->arelt = new_elt;
  318.   new_cache->next = (struct ar_cache *)NULL;
  319.   if (bfd_ardata (arch_bfd)->cache == NULL)
  320.     bfd_ardata (arch_bfd)->cache = new_cache;
  321.   else {
  322.     struct ar_cache *current = bfd_ardata (arch_bfd)->cache;
  323.  
  324.     while (current->next != NULL)
  325.       current = current->next;
  326.     current->next = new_cache;
  327.   }
  328.     
  329.   return true;
  330. }
  331.  
  332. /* The name begins with space.  Hence the rest of the name is an index into
  333.    the string table. */
  334.  
  335. static char *
  336. get_extended_arelt_filename (arch, name)
  337.      bfd *arch;
  338.      const char *name;
  339. {
  340.   unsigned long index = 0;
  341.  
  342.   /* Should extract string so that I can guarantee not to overflow into
  343.      the next region, but I'm too lazy. */
  344.   errno = 0;
  345.   /* Skip first char, which is '/' in SVR4 or ' ' in some other variants. */
  346.   index = strtol (name+1, NULL, 10);
  347.   if (errno != 0) {
  348.       bfd_error = malformed_archive;
  349.       return NULL;
  350.     }
  351.  
  352.   return bfd_ardata (arch)->extended_names + index;
  353. }  
  354.  
  355. /* This functions reads an arch header and returns an areltdata pointer, or
  356.    NULL on error.
  357.  
  358.    Presumes the file pointer is already in the right place (ie pointing
  359.    to the ar_hdr in the file).   Moves the file pointer; on success it
  360.    should be pointing to the front of the file contents; on failure it
  361.    could have been moved arbitrarily.
  362. */
  363.  
  364. struct areltdata *
  365. _bfd_snarf_ar_hdr (abfd)
  366.      bfd *abfd;
  367. {
  368. #ifndef errno
  369.   extern int errno;
  370. #endif
  371.  
  372.     struct ar_hdr hdr;
  373.     char *hdrp = (char *) &hdr;
  374.     unsigned int parsed_size;
  375.     struct areltdata *ared;
  376.     char *filename = NULL;
  377.     unsigned int namelen = 0;
  378.     unsigned int allocsize = sizeof (struct areltdata) + sizeof (struct ar_hdr);
  379.     char *allocptr = 0;
  380.  
  381.     if (bfd_read ((PTR)hdrp, 1, sizeof (struct ar_hdr), abfd)
  382.     != sizeof (struct ar_hdr)) {
  383.     bfd_error = no_more_archived_files;
  384.     return NULL;
  385.     }
  386.     if (strncmp ((hdr.ar_fmag), ARFMAG, 2)) {
  387.     bfd_error = malformed_archive;
  388.     return NULL;
  389.     }
  390.  
  391.     errno = 0;
  392.     parsed_size = strtol (hdr.ar_size, NULL, 10);
  393.     if (errno != 0) {
  394.     bfd_error = malformed_archive;
  395.     return NULL;
  396.     }
  397.  
  398.     /* extract the filename from the archive - there are two ways to
  399.        specify an extendend name table, either the first char of the
  400.        name is a space, or it's a slash.  */
  401.     if ((hdr.ar_name[0] == '/'
  402.      || (hdr.ar_name[0] == ' '
  403.          && memchr (hdr.ar_name, '/', ar_maxnamelen(abfd)) == NULL))
  404.     && bfd_ardata (abfd)->extended_names != NULL) {
  405.     filename = get_extended_arelt_filename (abfd, hdr.ar_name);
  406.     if (filename == NULL) {
  407.         bfd_error = malformed_archive;
  408.         return NULL;
  409.     }
  410.     }
  411.     /* BSD4.4-style long filename.
  412.        Only implemented for reading, so far! */
  413.     else if (hdr.ar_name[0] == '#' && hdr.ar_name[1] == '1'
  414.          && hdr.ar_name[2] == '/' && isdigit(hdr.ar_name[3]))
  415.       {
  416.     /* BSD-4.4 extended name */
  417.     namelen = atoi (&hdr.ar_name[3]);
  418.     allocsize += namelen + 1;
  419.     parsed_size -= namelen;
  420.  
  421.     allocptr = bfd_zalloc(abfd, allocsize);
  422.     if (allocptr == NULL) {
  423.       bfd_error = no_memory;
  424.       return NULL;
  425.     }
  426.     filename = allocptr
  427.       + (sizeof (struct areltdata) + sizeof (struct ar_hdr));
  428.     if (bfd_read (filename, 1, namelen, abfd) != namelen) {
  429.       bfd_error = no_more_archived_files;
  430.       return NULL;
  431.     }
  432.     filename[namelen] = '\0';
  433.       }
  434.     else 
  435.     {
  436.         /* We judge the end of the name by looking for '/' or ' '.
  437.            Note:  The SYSV format (terminated by '/') allows embedded
  438.            spaces, so only look for ' ' if we don't find '/'. */
  439.  
  440.         namelen = 0;
  441.         while (hdr.ar_name[namelen] != '\0' &&
  442.            hdr.ar_name[namelen] != '/') {
  443.         namelen++;
  444.         if (namelen == (unsigned)ar_maxnamelen(abfd)) {
  445.             namelen = 0;
  446.             while (hdr.ar_name[namelen] != ' '
  447.                && namelen < (unsigned)ar_maxnamelen(abfd)) {
  448.             namelen++;
  449.             }
  450.             break;
  451.         }
  452.         }
  453.  
  454.         allocsize += namelen + 1;
  455.     }
  456.  
  457.     if (!allocptr) {
  458.       allocptr = bfd_zalloc(abfd, allocsize);
  459.       if (allocptr == NULL) {
  460.     bfd_error = no_memory;
  461.     return NULL;
  462.       }
  463.     }
  464.  
  465.     ared = (struct areltdata *) allocptr;
  466.  
  467.     ared->arch_header = allocptr + sizeof (struct areltdata);
  468.     memcpy ((char *) ared->arch_header, (char *) &hdr, sizeof (struct ar_hdr));
  469.     ared->parsed_size = parsed_size;
  470.  
  471.     if (filename != NULL) ared->filename = filename;
  472.     else {
  473.     ared->filename = allocptr + (sizeof (struct areltdata) +
  474.                      sizeof (struct ar_hdr));
  475.     if (namelen)
  476.         memcpy (ared->filename, hdr.ar_name, namelen);
  477.     ared->filename[namelen] = '\0';
  478.     }
  479.   
  480.     return ared;
  481. }
  482.  
  483. /* This is an internal function; it's mainly used when indexing
  484.    through the archive symbol table, but also used to get the next
  485.    element, since it handles the bookkeeping so nicely for us.
  486. */
  487.  
  488. bfd *
  489. _bfd_get_elt_at_filepos (archive, filepos)
  490.      bfd *archive;
  491.      file_ptr filepos;
  492. {
  493.   struct areltdata *new_areldata;
  494.   bfd *n_nfd;
  495.  
  496.   n_nfd = look_for_bfd_in_cache (archive, filepos);
  497.   if (n_nfd)
  498.     return n_nfd;
  499.  
  500.   if (0 > bfd_seek (archive, filepos, SEEK_SET))
  501.     {
  502.       bfd_error = system_call_error;
  503.       return NULL;
  504.     }
  505.  
  506.   if ((new_areldata = _bfd_snarf_ar_hdr (archive)) == NULL)
  507.     return NULL;
  508.   
  509.   n_nfd = _bfd_create_empty_archive_element_shell (archive);
  510.   if (n_nfd == NULL)
  511.     {
  512.       bfd_release (archive, (PTR)new_areldata);
  513.       return NULL;
  514.     }
  515.  
  516.   n_nfd->origin = bfd_tell (archive);
  517.   n_nfd->arelt_data = (PTR) new_areldata;
  518.   n_nfd->filename = new_areldata->filename;
  519.  
  520.   if (_bfd_add_bfd_to_archive_cache (archive, filepos, n_nfd))
  521.     return n_nfd;
  522.  
  523.   /* huh? */
  524.   bfd_release (archive, (PTR)n_nfd);
  525.   bfd_release (archive, (PTR)new_areldata);
  526.   return NULL;
  527. }
  528.  
  529. /*
  530. FUNCTION
  531.     bfd_get_elt_at_index
  532.  
  533. SYNOPSIS
  534.     bfd *bfd_get_elt_at_index(bfd *archive, int index);
  535.  
  536. DESCRIPTION
  537.     Return the BFD which is referenced by the symbol in @var{archive}
  538.     indexed by @var{index}.  @var{index} should have been returned by
  539.     <<bfd_get_next_mapent>> (q.v.).
  540.  
  541. */
  542. bfd *
  543. bfd_get_elt_at_index (abfd, index)
  544.      bfd *abfd;
  545.      int index;
  546. {
  547.   bfd *result =
  548.     _bfd_get_elt_at_filepos
  549.       (abfd, (bfd_ardata (abfd)->symdefs + index)->file_offset);
  550.   return result;
  551. }
  552.  
  553. /*
  554. FUNCTION
  555.     bfd_openr_next_archived_file
  556.  
  557. SYNOPSIS
  558.     bfd *bfd_openr_next_archived_file(bfd *archive, bfd *previous);
  559.  
  560. DESCRIPTION
  561.     Provided a BFD, @var{archive}, containing an archive and NULL, open
  562.     an input BFD on the first contained element and returns that.
  563.     Subsequent calls should pass
  564.     the archive and the previous return value to return a created
  565.     BFD to the next contained element. NULL is returned when there
  566.     are no more.
  567.  
  568. */
  569.  
  570. bfd *
  571. bfd_openr_next_archived_file (archive, last_file)
  572.      bfd *archive;
  573.      bfd *last_file;
  574. {
  575.   if ((bfd_get_format (archive) != bfd_archive) ||
  576.       (archive->direction == write_direction))
  577.     {
  578.       bfd_error = invalid_operation;
  579.       return NULL;
  580.     }
  581.  
  582.   return BFD_SEND (archive,
  583.            openr_next_archived_file,
  584.            (archive,
  585.             last_file));
  586. }
  587.  
  588. bfd *
  589. bfd_generic_openr_next_archived_file (archive, last_file)
  590.      bfd *archive;
  591.      bfd *last_file;
  592. {
  593.   file_ptr filestart;
  594.  
  595.   if (!last_file)
  596.     filestart = bfd_ardata (archive)->first_file_filepos;
  597.   else {
  598.     unsigned int size = arelt_size(last_file);
  599.     /* Pad to an even boundary... 
  600.        Note that last_file->origin can be odd in the case of
  601.        BSD-4.4-style element with a long odd size. */
  602.     filestart = last_file->origin + size;
  603.     filestart += filestart % 2;
  604.   }
  605.  
  606.   return _bfd_get_elt_at_filepos (archive, filestart);
  607. }
  608.  
  609.  
  610. bfd_target *
  611. bfd_generic_archive_p (abfd)
  612.      bfd *abfd;
  613. {
  614.   char armag[SARMAG+1];
  615.  
  616.   if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG)
  617.     {
  618.       bfd_error = wrong_format;
  619.       return NULL;
  620.     }
  621.  
  622. #ifdef GNU960
  623.   if (strncmp (armag, BFD_GNU960_ARMAG(abfd), SARMAG) != 0)
  624.     return 0;
  625. #else
  626.   if (strncmp (armag, ARMAG, SARMAG) != 0 &&
  627.       strncmp (armag, ARMAGB, SARMAG) != 0)
  628.     return 0;
  629. #endif
  630.  
  631.   /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
  632.      involves a cast, we can't do it as the left operand of assignment. */
  633.   abfd->tdata.aout_ar_data = ((struct artdata *)
  634.                   bfd_zalloc (abfd, sizeof (struct artdata)));
  635.  
  636.   if (bfd_ardata (abfd) == NULL)
  637.     {
  638.       bfd_error = no_memory;
  639.       return NULL;
  640.     }
  641.  
  642.   bfd_ardata (abfd)->first_file_filepos = SARMAG;
  643.   bfd_ardata (abfd)->cache = NULL;
  644.   bfd_ardata (abfd)->archive_head = NULL;
  645.   bfd_ardata (abfd)->symdefs = NULL;
  646.   bfd_ardata (abfd)->extended_names = NULL;
  647.   bfd_ardata (abfd)->tdata = NULL;
  648.   
  649.   if (! BFD_SEND (abfd, _bfd_slurp_armap, (abfd)))
  650.     {
  651.       bfd_release(abfd, bfd_ardata (abfd));
  652.       abfd->tdata.aout_ar_data = NULL;
  653.       return NULL;
  654.     }
  655.  
  656.   if (! BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd)))
  657.     {
  658.       bfd_release(abfd, bfd_ardata (abfd));
  659.       abfd->tdata.aout_ar_data = NULL;
  660.       return NULL;
  661.     }
  662.   
  663.   return abfd->xvec;
  664. }
  665.  
  666. /* Returns false on error, true otherwise */
  667. static boolean
  668. do_slurp_bsd_armap (abfd)
  669.      bfd *abfd;
  670. {
  671.   struct areltdata *mapdata;
  672.   unsigned int counter = 0;
  673.   int *raw_armap, *rbase;
  674.   struct artdata *ardata = bfd_ardata (abfd);
  675.   char *stringbase;
  676.   unsigned int parsed_size;
  677.  
  678.   mapdata = _bfd_snarf_ar_hdr (abfd);
  679.   if (mapdata == NULL)
  680.     return false;
  681.   parsed_size = mapdata->parsed_size;
  682.   bfd_release (abfd, (PTR)mapdata); /* Don't need it any more. */
  683.     
  684.   raw_armap = (int *) bfd_zalloc(abfd, parsed_size);
  685.   if (raw_armap == NULL) {
  686.       bfd_error = no_memory;
  687.       return false;
  688.   }
  689.     
  690.   if (bfd_read ((PTR)raw_armap, 1, parsed_size, abfd) != parsed_size) {
  691.       bfd_error = malformed_archive;
  692.     byebye:
  693.       bfd_release (abfd, (PTR)raw_armap);
  694.       return false;
  695.   }
  696.     
  697.   ardata->symdef_count = (bfd_h_get_32 (abfd, (bfd_byte *) raw_armap)
  698.               / sizeof (struct symdef));
  699.     
  700.   if (ardata->symdef_count * sizeof (struct symdef)
  701.       > parsed_size - sizeof (*raw_armap)) {
  702.       /* Probably we're using the wrong byte ordering.  */
  703.       bfd_error = wrong_format;
  704.       goto byebye;
  705.   }
  706.   
  707.   ardata->cache = 0;
  708.   rbase = raw_armap+1;
  709.   ardata->symdefs = (carsym *) rbase;
  710.   stringbase = ((char *) (ardata->symdefs + ardata->symdef_count)) + 4;
  711.   
  712.   for (;counter < ardata->symdef_count; counter++) {
  713.       struct symdef *sym = ((struct symdef *) rbase) + counter;
  714.       sym->s.name = (bfd_h_get_32 (abfd, (bfd_byte *) (&sym->s.string_offset))
  715.              + stringbase);
  716.       sym->file_offset = bfd_h_get_32 (abfd,
  717.                        (bfd_byte *) (&(sym->file_offset)));
  718.   }
  719.   
  720.   ardata->first_file_filepos = bfd_tell (abfd);
  721.   /* Pad to an even boundary if you have to */
  722.   ardata->first_file_filepos += (ardata-> first_file_filepos) %2;
  723.   /* FIXME, we should provide some way to free raw_ardata when
  724.      we are done using the strings from it.  For now, it seems
  725.      to be allocated on an obstack anyway... */
  726.   bfd_has_map (abfd) = true;
  727.   return true;
  728. }
  729.  
  730. /* Returns false on error, true otherwise */
  731. static boolean
  732. do_slurp_coff_armap (abfd)
  733.      bfd *abfd;
  734. {
  735.   struct areltdata *mapdata;
  736.   int *raw_armap, *rawptr;
  737.   struct artdata *ardata = bfd_ardata (abfd);
  738.   char *stringbase;
  739.   unsigned int stringsize;
  740.   unsigned int parsed_size;
  741.   carsym *carsyms;
  742.   unsigned int nsymz; /* Number of symbols in armap. */
  743.   bfd_vma (*swap) PARAMS ((const bfd_byte*));
  744.   char int_buf[sizeof(long)];
  745.   unsigned int carsym_size, ptrsize, i;
  746.   
  747.   mapdata = _bfd_snarf_ar_hdr (abfd);
  748.   if (mapdata == NULL)
  749.     return false;
  750.   parsed_size = mapdata->parsed_size;
  751.   bfd_release (abfd, (PTR)mapdata); /* Don't need it any more. */
  752.  
  753.   if (bfd_read ((PTR)int_buf, 1, 4, abfd) != 4) {
  754.     bfd_error = malformed_archive;
  755.     return false;
  756.   }
  757.   /* It seems that all numeric information in a coff archive is always
  758.      in big endian format, nomatter the host or target. */
  759.   swap = bfd_getb32;
  760.   nsymz = bfd_getb32((PTR)int_buf);
  761.   stringsize = parsed_size - (4 * nsymz) - 4;
  762.  
  763. #if 1
  764.   /* ... except that some archive formats are broken, and it may be our
  765.      fault - the i960 little endian coff sometimes has big and sometimes
  766.      little, because our tools changed.  Here's a horrible hack to clean
  767.      up the crap.  */
  768.   
  769.   if (stringsize > 0xfffff) {
  770.       /* This looks dangerous, let's do it the other way around */
  771.       nsymz = bfd_getl32((PTR)int_buf);
  772.       stringsize = parsed_size - (4 * nsymz) - 4;
  773.       swap = bfd_getl32;
  774.   }
  775. #endif
  776.  
  777.   /* The coff armap must be read sequentially.  So we construct a bsd-style
  778.      one in core all at once, for simplicity. */  
  779.   
  780.   carsym_size = (nsymz * sizeof (carsym));
  781.   ptrsize = (4 * nsymz);
  782.  
  783.   ardata->symdefs = (carsym *) bfd_zalloc(abfd, carsym_size + stringsize + 1);
  784.   if (ardata->symdefs == NULL) {
  785.       bfd_error = no_memory;
  786.       return false;
  787.   }
  788.   carsyms = ardata->symdefs;
  789.   stringbase = ((char *) ardata->symdefs) + carsym_size;
  790.  
  791.   /* Allocate and read in the raw offsets. */
  792.   raw_armap = (int *) bfd_alloc(abfd, ptrsize);
  793.   if (raw_armap == NULL) {
  794.       bfd_error = no_memory;
  795.       goto release_symdefs;
  796.   }
  797.   if (bfd_read ((PTR)raw_armap, 1, ptrsize, abfd) != ptrsize
  798.       || bfd_read ((PTR)stringbase, 1, stringsize, abfd) != stringsize) {
  799.     bfd_error = malformed_archive;
  800.     goto release_raw_armap;
  801.   }
  802.  
  803.   /* OK, build the carsyms */
  804.   for (i = 0; i < nsymz; i++) {
  805.       rawptr = raw_armap + i;
  806.       carsyms->file_offset = swap((PTR)rawptr);
  807.       carsyms->name = stringbase;
  808.       stringbase += strlen (stringbase) + 1;
  809.       carsyms++;
  810.   }
  811.   *stringbase = 0;
  812.  
  813.   ardata->symdef_count = nsymz;
  814.   ardata->first_file_filepos = bfd_tell (abfd);
  815.   /* Pad to an even boundary if you have to */
  816.   ardata->first_file_filepos += (ardata->first_file_filepos) %2;
  817.  
  818.   bfd_has_map (abfd) = true;
  819.   bfd_release (abfd, (PTR)raw_armap);
  820.   return true;
  821.  
  822.  release_raw_armap:
  823.   bfd_release (abfd, (PTR)raw_armap);
  824.  release_symdefs:
  825.   bfd_release (abfd, (PTR)(ardata)->symdefs);
  826.   return false;
  827. }
  828.  
  829. /* This routine can handle either coff-style or bsd-style armaps.
  830.    Returns false on error, true otherwise */
  831.  
  832. boolean
  833. bfd_slurp_armap (abfd)
  834.      bfd *abfd;
  835. {
  836.   char nextname[17];
  837.   int i = bfd_read ((PTR)nextname, 1, 16, abfd);
  838.   
  839.   if (i == 0)
  840.       return true;
  841.   if (i != 16)
  842.       return false;
  843.  
  844.   bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
  845.  
  846.   if (!strncmp (nextname, "__.SYMDEF       ", 16))
  847.     return do_slurp_bsd_armap (abfd);
  848.   else if (!strncmp (nextname, "/               ", 16))
  849.     return do_slurp_coff_armap (abfd);
  850.  
  851.   bfd_has_map (abfd) = false;
  852.   return true;
  853. }
  854.  
  855. /* Returns false on error, true otherwise */
  856. /* flavor 2 of a bsd armap, similar to bfd_slurp_bsd_armap except the
  857.    header is in a slightly different order and the map name is '/'. 
  858.    This flavour is used by hp300hpux. */
  859. boolean
  860. bfd_slurp_bsd_armap_f2 (abfd)  
  861.      bfd *abfd;
  862. {
  863.   struct areltdata *mapdata;
  864.   char nextname[17];
  865.   unsigned int counter = 0;
  866.   int *raw_armap, *rbase;
  867.   struct artdata *ardata = bfd_ardata (abfd);
  868.   char *stringbase;
  869.   unsigned int stringsize;
  870.   int i = bfd_read ((PTR)nextname, 1, 16, abfd);
  871.  
  872.   if (i == 0)
  873.     return true;
  874.   if (i != 16)
  875.     return false;
  876.  
  877.   /* The archive has at least 16 bytes in it */
  878.   bfd_seek (abfd, -16L, SEEK_CUR);
  879.  
  880.   if (!strncmp (nextname, "__.SYMDEF       ", 16))
  881.     return do_slurp_bsd_armap (abfd);
  882.  
  883.   if (strncmp (nextname, "/               ", 16))
  884.     {
  885.       bfd_has_map (abfd) = false;
  886.       return true;
  887.     }
  888.  
  889.   mapdata = _bfd_snarf_ar_hdr (abfd);
  890.   if (mapdata == NULL)
  891.     return false;
  892.  
  893.   raw_armap = (int *) bfd_zalloc(abfd,mapdata->parsed_size);
  894.   if (raw_armap == NULL)
  895.     {
  896.       bfd_error = no_memory;
  897.     byebye:
  898.       bfd_release (abfd, (PTR)mapdata);
  899.       return false;
  900.     }
  901.  
  902.   if (bfd_read ((PTR)raw_armap, 1, mapdata->parsed_size, abfd) !=
  903.       mapdata->parsed_size)
  904.     {
  905.       bfd_error = malformed_archive;
  906.     byebyebye:
  907.       bfd_release (abfd, (PTR)raw_armap);
  908.       goto byebye;
  909.     }
  910.  
  911.   ardata->symdef_count = bfd_h_get_16(abfd, (PTR)raw_armap);
  912.  
  913.   if (ardata->symdef_count * sizeof (struct symdef)
  914.       > mapdata->parsed_size - sizeof (*raw_armap))
  915.     {
  916.       /* Probably we're using the wrong byte ordering.  */
  917.       bfd_error = wrong_format;
  918.       goto byebyebye;
  919.     }
  920.  
  921.   ardata->cache = 0;
  922.  
  923.   stringsize = bfd_h_get_32(abfd, (PTR)(((char*)raw_armap)+2));
  924.   /* skip sym count and string sz */
  925.   rbase = (int*)(((char*)raw_armap) + 6);
  926.   stringbase = (char *) rbase;
  927.   ardata->symdefs = (carsym *)(((char*) rbase) + stringsize);
  928.  
  929.   for (;counter < ardata->symdef_count; counter++)
  930.     {
  931.       struct symdef *sym = ((struct symdef *) ardata->symdefs) + counter;
  932.       sym->s.name = bfd_h_get_32(abfd, (PTR)(&(sym->s.string_offset))) + stringbase;
  933.       sym->file_offset = bfd_h_get_32(abfd, (PTR)( &(sym->file_offset)));
  934.     }
  935.  
  936.   ardata->first_file_filepos = bfd_tell (abfd);
  937.   /* Pad to an even boundary if you have to */
  938.   ardata->first_file_filepos += (ardata-> first_file_filepos) %2;
  939.   /* FIXME, we should provide some way to free raw_ardata when
  940.      we are done using the strings from it.  For now, it seems
  941.      to be allocated on an obstack anyway... */
  942.   bfd_has_map (abfd) = true;
  943.   return true;
  944. }
  945.  
  946. /** Extended name table.
  947.  
  948.   Normally archives support only 14-character filenames.
  949.  
  950.   Intel has extended the format: longer names are stored in a special
  951.   element (the first in the archive, or second if there is an armap);
  952.   the name in the ar_hdr is replaced by <space><index into filename
  953.   element>.  Index is the P.R. of an int (decimal).  Data General have
  954.   extended the format by using the prefix // for the special element */
  955.  
  956. /* Returns false on error, true otherwise */
  957. boolean
  958. _bfd_slurp_extended_name_table (abfd)
  959.      bfd *abfd;
  960. {
  961.   char nextname[17];
  962.   struct areltdata *namedata;
  963.  
  964.   /* FIXME:  Formatting sucks here, and in case of failure of BFD_READ,
  965.      we probably don't want to return true.  */
  966.   if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) {
  967.  
  968.     bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
  969.  
  970.     if (strncmp (nextname, "ARFILENAMES/    ", 16) != 0 &&
  971.     strncmp (nextname, "//              ", 16) != 0) 
  972.     {
  973.       bfd_ardata (abfd)->extended_names = NULL;
  974.       return true;
  975.     }
  976.  
  977.     namedata = _bfd_snarf_ar_hdr (abfd);
  978.     if (namedata == NULL)
  979.       return false;
  980.   
  981.     bfd_ardata (abfd)->extended_names = bfd_zalloc(abfd,namedata->parsed_size);
  982.     if (bfd_ardata (abfd)->extended_names == NULL) {
  983.       bfd_error = no_memory;
  984.     byebye:
  985.       bfd_release (abfd, (PTR)namedata);
  986.       return false;
  987.     }
  988.  
  989.     if (bfd_read ((PTR)bfd_ardata (abfd)->extended_names, 1,
  990.           namedata->parsed_size, abfd) != namedata->parsed_size) {
  991.       bfd_error = malformed_archive;
  992.       bfd_release (abfd, (PTR)(bfd_ardata (abfd)->extended_names));
  993.       bfd_ardata (abfd)->extended_names = NULL;
  994.       goto byebye;
  995.     }
  996.  
  997.     /* Since the archive is supposed to be printable if it contains
  998.        text, the entries in the list are newline-padded, not null
  999.        padded. In SVR4-style archives, the names also have a
  1000.        trailing '/'.  We'll fix both problems here..  */
  1001.       {
  1002.     char *temp = bfd_ardata (abfd)->extended_names;
  1003.     char *limit = temp + namedata->parsed_size;
  1004.     for (; temp < limit; ++temp)
  1005.       if (*temp == '\n')
  1006.         temp[temp[-1] == '/' ? -1 : 0] = '\0';
  1007.       }
  1008.   
  1009.     /* Pad to an even boundary if you have to */
  1010.     bfd_ardata (abfd)->first_file_filepos = bfd_tell (abfd);
  1011.     bfd_ardata (abfd)->first_file_filepos +=
  1012.       (bfd_ardata (abfd)->first_file_filepos) %2;
  1013.  
  1014.     /* FIXME, we can't release namedata here because it was allocated
  1015.        below extended_names on the obstack... */
  1016.     /* bfd_release (abfd, namedata); */
  1017.   }
  1018.   return true;
  1019. }
  1020.  
  1021. #ifdef VMS
  1022.  
  1023. /* Return a copy of the stuff in the filename between any :]> and a
  1024.    semicolon */
  1025. static const char *
  1026. normalize (file)
  1027.      const char *file;
  1028. {
  1029.   CONST char *first;
  1030.   CONST char *last;
  1031.   char *copy;
  1032.  
  1033.   first = file + strlen(file)-1;
  1034.   last = first+1;
  1035.  
  1036.   while (first != file) 
  1037.   {
  1038.     if (*first == ';') 
  1039.      last = first;
  1040.     if (*first == ':' || *first == ']' ||*first == '>') 
  1041.     { 
  1042.       first++;
  1043.       break;
  1044.     }
  1045.     first --;
  1046.   }
  1047.   
  1048.  
  1049.   copy = bfd_xmalloc(last - first + 1);
  1050.   memcpy(copy, first, last-first);
  1051.   copy[last-first] = 0;
  1052.  
  1053.   return copy;
  1054. }
  1055.  
  1056. #else
  1057. static const char *
  1058. normalize (file)
  1059.      const char *file;
  1060. {
  1061.   CONST char *    filename = strrchr(file, '/');
  1062.  
  1063.   if (filename != (char *)NULL) {
  1064.       filename ++;
  1065.     }
  1066.   else {
  1067.       filename = file;
  1068.     }
  1069.   return filename;
  1070. }
  1071. #endif
  1072. /* Follows archive_head and produces an extended name table if necessary.
  1073.    Returns (in tabloc) a pointer to an extended name table, and in tablen
  1074.    the length of the table.  If it makes an entry it clobbers the filename
  1075.    so that the element may be written without further massage.
  1076.    Returns true if it ran successfully, false if something went wrong.
  1077.    A successful return may still involve a zero-length tablen!
  1078.    */
  1079. static boolean
  1080. bfd_construct_extended_name_table (abfd, tabloc, tablen)
  1081.      bfd *abfd;
  1082.      char **tabloc;
  1083.      unsigned int *tablen;
  1084. {
  1085.   unsigned int maxname = abfd->xvec->ar_max_namelen;
  1086.   unsigned int total_namelen = 0;
  1087.   bfd *current;
  1088.   char *strptr;
  1089.  
  1090.   *tablen = 0;
  1091.   
  1092.   /* Figure out how long the table should be */
  1093.   for (current = abfd->archive_head; current != NULL; current = current->next){
  1094.     unsigned int thislen = strlen (normalize(current->filename));
  1095.     if (thislen > maxname) total_namelen += thislen + 1; /* leave room for \n */
  1096.   }
  1097.  
  1098.   if (total_namelen == 0) return true;
  1099.  
  1100.   *tabloc = bfd_zalloc (abfd,total_namelen);
  1101.   if (*tabloc == NULL) {
  1102.     bfd_error = no_memory;
  1103.     return false;
  1104.   }
  1105.  
  1106.   *tablen = total_namelen;
  1107.   strptr = *tabloc;
  1108.  
  1109.   for (current = abfd->archive_head; current != NULL; current =
  1110.        current->next) {
  1111.     CONST char *normal =normalize( current->filename);
  1112.     unsigned int thislen = strlen (normal);
  1113.     if (thislen > maxname) {
  1114.       /* Works for now; may need to be re-engineered if we encounter an oddball
  1115.      archive format and want to generalise this hack. */
  1116.       struct ar_hdr *hdr = arch_hdr(current);
  1117.       strcpy (strptr, normal);
  1118.       strptr[thislen] = '\n';
  1119.       hdr->ar_name[0] = ' ';
  1120.       /* We know there will always be enough room (one of the few cases
  1121.      where you may safely use sprintf). */
  1122.       sprintf ((hdr->ar_name) + 1, "%-d", (unsigned) (strptr - *tabloc));
  1123.       /* Kinda Kludgy.   We should just use the returned value of sprintf
  1124.      but not all implementations get this right */
  1125.     {
  1126.       char *temp = hdr->ar_name +2; 
  1127.       for (; temp < hdr->ar_name + maxname; temp++)
  1128.         if (*temp == '\0') *temp = ' ';
  1129.     }
  1130.       strptr += thislen + 1;
  1131.     }
  1132.   }
  1133.  
  1134.   return true;
  1135. }
  1136.  
  1137. /** A couple of functions for creating ar_hdrs */
  1138.  
  1139. /* Takes a filename, returns an arelt_data for it, or NULL if it can't make one.
  1140.    The filename must refer to a filename in the filesystem.
  1141.    The filename field of the ar_hdr will NOT be initialized
  1142. */
  1143.  
  1144. static struct areltdata *
  1145. bfd_ar_hdr_from_filesystem (abfd,filename)
  1146.      bfd* abfd;
  1147.      const char *filename;
  1148. {
  1149.   struct stat status;
  1150.   struct areltdata *ared;
  1151.   struct ar_hdr *hdr;
  1152.   char *temp, *temp1;
  1153.  
  1154.   if (stat (filename, &status) != 0) {
  1155.     bfd_error = system_call_error;
  1156.     return NULL;
  1157.   }
  1158.  
  1159.   ared = (struct areltdata *) bfd_zalloc(abfd, sizeof (struct ar_hdr) +
  1160.                       sizeof (struct areltdata));
  1161.   if (ared == NULL) {
  1162.     bfd_error = no_memory;
  1163.     return NULL;
  1164.   }
  1165.   hdr = (struct ar_hdr *) (((char *) ared) + sizeof (struct areltdata));
  1166.  
  1167.   /* ar headers are space padded, not null padded! */
  1168.   memset (hdr, ' ', sizeof (struct ar_hdr));
  1169.  
  1170.   strncpy (hdr->ar_fmag, ARFMAG, 2);
  1171.   
  1172.   /* Goddamned sprintf doesn't permit MAXIMUM field lengths */
  1173.   sprintf ((hdr->ar_date), "%-12ld", status.st_mtime);
  1174.   sprintf ((hdr->ar_uid), "%d", status.st_uid);
  1175.   sprintf ((hdr->ar_gid), "%d", status.st_gid);
  1176.   sprintf ((hdr->ar_mode), "%-8o", (unsigned) status.st_mode);
  1177.   sprintf ((hdr->ar_size), "%-10ld", status.st_size);
  1178.   /* Correct for a lossage in sprintf whereby it null-terminates.  I cannot
  1179.      understand how these C losers could design such a ramshackle bunch of
  1180.      IO operations */
  1181.   temp = (char *) hdr;
  1182.   temp1 = temp + sizeof (struct ar_hdr) - 2;
  1183.   for (; temp < temp1; temp++) {
  1184.     if (*temp == '\0') *temp = ' ';
  1185.   }
  1186.   strncpy (hdr->ar_fmag, ARFMAG, 2);
  1187.   ared->parsed_size = status.st_size;
  1188.   ared->arch_header = (char *) hdr;
  1189.  
  1190.   return ared;
  1191. }
  1192.  
  1193. /* This is magic required by the "ar" program.  Since it's
  1194.     undocumented, it's undocumented.   You may think that it would
  1195.     take a strong stomach to write this, and it does, but it takes
  1196.     even a stronger stomach to try to code around such a thing!
  1197. */
  1198.  
  1199. struct ar_hdr *
  1200. bfd_special_undocumented_glue (abfd, filename)
  1201.      bfd *abfd;
  1202.      char *filename;
  1203. {
  1204.   struct areltdata *ar_elt = bfd_ar_hdr_from_filesystem (abfd, filename);
  1205.   if (ar_elt == NULL)
  1206.       return NULL;
  1207.   return (struct ar_hdr *) ar_elt->arch_header;
  1208. }
  1209.  
  1210.  
  1211. /* Analogous to stat call */
  1212. int
  1213. bfd_generic_stat_arch_elt (abfd, buf)
  1214.      bfd *abfd;
  1215.      struct stat *buf;
  1216. {
  1217.   struct ar_hdr *hdr;
  1218.   char *aloser;
  1219.   
  1220.   if (abfd->arelt_data == NULL) {
  1221.     bfd_error = invalid_operation;
  1222.     return -1;
  1223.   }
  1224.     
  1225.   hdr = arch_hdr (abfd);
  1226.  
  1227. #define foo(arelt, stelt, size)  \
  1228.   buf->stelt = strtol (hdr->arelt, &aloser, size); \
  1229.   if (aloser == hdr->arelt) return -1;
  1230.   
  1231.   foo (ar_date, st_mtime, 10);
  1232.   foo (ar_uid, st_uid, 10);
  1233.   foo (ar_gid, st_gid, 10);
  1234.   foo (ar_mode, st_mode, 8);
  1235.  
  1236.   buf->st_size = arch_eltdata (abfd)->parsed_size;
  1237.  
  1238.   return 0;
  1239. }
  1240.  
  1241. void
  1242. bfd_dont_truncate_arname (abfd, pathname, arhdr)
  1243.      bfd *abfd;
  1244.      CONST char *pathname;
  1245.      char *arhdr;
  1246. {
  1247.   /* FIXME: This interacts unpleasantly with ar's quick-append option.
  1248.      Fortunately ic960 users will never use that option.  Fixing this
  1249.      is very hard; fortunately I know how to do it and will do so once
  1250.      intel's release is out the door. */
  1251.    
  1252.   struct ar_hdr *hdr = (struct ar_hdr *) arhdr;
  1253.   int length;
  1254.   CONST char *filename = normalize(pathname);
  1255.   int maxlen = ar_maxnamelen (abfd);
  1256.  
  1257.   length = strlen (filename);
  1258.  
  1259.   if (length <= maxlen)
  1260.     memcpy (hdr->ar_name, filename, length);
  1261.  
  1262.   if (length < maxlen) (hdr->ar_name)[length] = ar_padchar (abfd);
  1263.   return;
  1264.  
  1265. }
  1266.  
  1267. void
  1268. bfd_bsd_truncate_arname (abfd, pathname, arhdr)
  1269.      bfd *abfd;
  1270.      CONST char *pathname;
  1271.      char *arhdr;
  1272. {
  1273.   struct ar_hdr *hdr = (struct ar_hdr *) arhdr;
  1274.   int length;
  1275.   CONST char *filename = strrchr (pathname, '/');
  1276.   int maxlen = ar_maxnamelen (abfd);
  1277.  
  1278.  
  1279.   if (filename == NULL)
  1280.     filename = pathname;
  1281.   else
  1282.     ++filename;
  1283.  
  1284.   length = strlen (filename);
  1285.  
  1286.   if (length <= maxlen)
  1287.     memcpy (hdr->ar_name, filename, length);
  1288.   else {
  1289.     /* pathname: meet procrustes */
  1290.     memcpy (hdr->ar_name, filename, maxlen);
  1291.     length = maxlen;
  1292.   }
  1293.  
  1294.   if (length < maxlen)
  1295.     (hdr->ar_name)[length] = ar_padchar (abfd);
  1296. }
  1297.  
  1298. /* Store name into ar header.  Truncates the name to fit.
  1299.    1> strip pathname to be just the basename.
  1300.    2> if it's short enuf to fit, stuff it in.
  1301.    3> If it doesn't end with .o, truncate it to fit
  1302.    4> truncate it before the .o, append .o, stuff THAT in.
  1303. */
  1304.  
  1305. /* This is what gnu ar does.  It's better but incompatible with the bsd ar. */
  1306. void
  1307. bfd_gnu_truncate_arname (abfd, pathname, arhdr)
  1308.      bfd *abfd;
  1309.      CONST char *pathname;
  1310.      char *arhdr;
  1311. {
  1312.   struct ar_hdr *hdr = (struct ar_hdr *) arhdr;
  1313.   int length;
  1314.   CONST char *filename = strrchr (pathname, '/');
  1315.   int maxlen = ar_maxnamelen (abfd);
  1316.     
  1317.   if (filename == NULL)
  1318.     filename = pathname;
  1319.   else
  1320.     ++filename;
  1321.  
  1322.   length = strlen (filename);
  1323.  
  1324.   if (length <= maxlen)
  1325.     memcpy (hdr->ar_name, filename, length);
  1326.   else {            /* pathname: meet procrustes */
  1327.     memcpy (hdr->ar_name, filename, maxlen);
  1328.     if ((filename[length - 2] == '.') && (filename[length - 1] == 'o')) {
  1329.       hdr->ar_name[maxlen - 2] = '.';
  1330.       hdr->ar_name[maxlen - 1] = 'o';
  1331.     }
  1332.     length = maxlen;
  1333.   }
  1334.  
  1335.   if (length < 16)
  1336.     (hdr->ar_name)[length] = ar_padchar (abfd);
  1337. }
  1338.  
  1339.  
  1340. /* The BFD is open for write and has its format set to bfd_archive */
  1341. boolean
  1342. _bfd_write_archive_contents (arch)
  1343.      bfd *arch;
  1344. {
  1345.   bfd *current;
  1346.   char *etable = NULL;
  1347.   unsigned int elength = 0;
  1348.   boolean makemap = bfd_has_map (arch);
  1349.   boolean hasobjects = false;    /* if no .o's, don't bother to make a map */
  1350.   unsigned int i;
  1351.   int tries;
  1352.  
  1353.   /* Verify the viability of all entries; if any of them live in the
  1354.      filesystem (as opposed to living in an archive open for input)
  1355.      then construct a fresh ar_hdr for them.
  1356.      */
  1357.   for (current = arch->archive_head; current; current = current->next) {
  1358.     if (bfd_write_p (current)) {
  1359.       bfd_error = invalid_operation;
  1360.       return false;
  1361.     }
  1362.     if (!current->arelt_data) {
  1363.       current->arelt_data =
  1364.       (PTR) bfd_ar_hdr_from_filesystem (arch, current->filename);
  1365.       if (!current->arelt_data) return false;
  1366.  
  1367.       /* Put in the file name */
  1368.     
  1369.     BFD_SEND (arch, _bfd_truncate_arname,(arch, 
  1370.                       current->filename,
  1371.                      (char *) arch_hdr(current)));
  1372.  
  1373.       
  1374.     }
  1375.  
  1376.     if (makemap) {        /* don't bother if we won't make a map! */
  1377.       if ((bfd_check_format (current, bfd_object))
  1378. #if 0                /* FIXME -- these are not set correctly */
  1379.       && ((bfd_get_file_flags (current) & HAS_SYMS))
  1380. #endif
  1381.       )
  1382.     hasobjects = true;
  1383.     }
  1384.   }
  1385.  
  1386.   if (!bfd_construct_extended_name_table (arch, &etable, &elength))
  1387.     return false;
  1388.  
  1389.   bfd_seek (arch, (file_ptr) 0, SEEK_SET);
  1390. #ifdef GNU960
  1391.   bfd_write (BFD_GNU960_ARMAG(arch), 1, SARMAG, arch);
  1392. #else
  1393.   bfd_write (ARMAG, 1, SARMAG, arch);
  1394. #endif
  1395.  
  1396.   if (makemap && hasobjects) {
  1397.  
  1398.     if (compute_and_write_armap (arch, elength) != true) {
  1399.       return false;
  1400.     }
  1401.   }
  1402.  
  1403.   if (elength != 0) {
  1404.     struct ar_hdr hdr;
  1405.  
  1406.     memset ((char *)(&hdr), 0, sizeof (struct ar_hdr));
  1407.     sprintf (&(hdr.ar_name[0]), "ARFILENAMES/");
  1408.     sprintf (&(hdr.ar_size[0]), "%-10d", (int) elength);
  1409.     hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
  1410.     for (i = 0; i < sizeof (struct ar_hdr); i++)
  1411.       if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
  1412.     bfd_write ((char *)&hdr, 1, sizeof (struct ar_hdr), arch);
  1413.     bfd_write (etable, 1, elength, arch);
  1414.     if ((elength % 2) == 1) bfd_write ("\n", 1, 1, arch);
  1415.  
  1416.   }
  1417.  
  1418.   for (current = arch->archive_head; current; current = current->next) {
  1419.     char buffer[DEFAULT_BUFFERSIZE];
  1420.     unsigned int remaining = arelt_size (current);
  1421.     struct ar_hdr *hdr = arch_hdr(current);
  1422.     /* write ar header */
  1423.  
  1424.     if (bfd_write ((char *)hdr, 1, sizeof(*hdr), arch) != sizeof(*hdr)) {
  1425.     syserr:
  1426.     bfd_error = system_call_error;
  1427.     return false;
  1428.       }
  1429.     if (bfd_seek (current, (file_ptr) 0, SEEK_SET) != 0) goto syserr;
  1430.     while (remaining) 
  1431.     {
  1432.       unsigned int amt = DEFAULT_BUFFERSIZE;
  1433.       if (amt > remaining) {
  1434.         amt = remaining;
  1435.       }
  1436.       errno = 0;
  1437.       if (bfd_read (buffer, amt, 1, current) != amt) {
  1438.           if (errno) goto syserr;
  1439.           /* Looks like a truncated archive. */
  1440.           bfd_error = malformed_archive;
  1441.           return false;
  1442.       }
  1443.       if (bfd_write (buffer, amt, 1, arch)   != amt) goto syserr;
  1444.       remaining -= amt;
  1445.     }
  1446.     if ((arelt_size (current) % 2) == 1) bfd_write ("\n", 1, 1, arch);
  1447.   }
  1448.  
  1449.   /* Verify the timestamp in the archive file.  If it would
  1450.      not be accepted by the linker, rewrite it until it would be.
  1451.      If anything odd happens, break out and just return. 
  1452.      (The Berkeley linker checks the timestamp and refuses to read the
  1453.      table-of-contents if it is >60 seconds less than the file's
  1454.      modified-time.  That painful hack requires this painful hack.  */
  1455.  
  1456.   tries = 1;
  1457.   do {
  1458.     /* FIXME!  This kludge is to avoid adding a member to the xvec,
  1459.        while generating a small patch for Adobe.  FIXME!  The
  1460.        update_armap_timestamp function call should be in the xvec,
  1461.        thus:
  1462.  
  1463.         if (bfd_update_armap_timestamp (arch) == true) break;
  1464.                      ^
  1465.  
  1466.        Instead, we check whether in a BSD archive, and call directly. */
  1467.  
  1468.     if (arch->xvec->write_armap != bsd_write_armap)
  1469.     break;
  1470.     if (bsd_update_armap_timestamp(arch) == true)  /* FIXME!!!  Vector it */
  1471.     break;
  1472.     if (tries > 0)
  1473.     fprintf (stderr,
  1474.        "Warning: writing archive was slow: rewriting timestamp\n");
  1475.   } while (++tries < 6 );
  1476.  
  1477.   return true;
  1478. }
  1479.  
  1480. /* Note that the namidx for the first symbol is 0 */
  1481.  
  1482. static boolean
  1483. compute_and_write_armap (arch, elength)
  1484.      bfd *arch;
  1485.      unsigned int elength;
  1486. {
  1487.     bfd *current;
  1488.     file_ptr elt_no = 0;
  1489.     struct orl *map;
  1490.     int orl_max = 15000;    /* fine initial default */
  1491.     int orl_count = 0;
  1492.     int stridx = 0;        /* string index */
  1493.  
  1494.     /* Dunno if this is the best place for this info... */
  1495.     if (elength != 0) elength += sizeof (struct ar_hdr);
  1496.     elength += elength %2 ;
  1497.  
  1498.     map = (struct orl *) bfd_zalloc (arch,orl_max * sizeof (struct orl));
  1499.     if (map == NULL) {
  1500.         bfd_error = no_memory;
  1501.         return false;
  1502.     }
  1503.  
  1504.     /* Drop all the files called __.SYMDEF, we're going to make our
  1505.        own */
  1506.     while (arch->archive_head   &&
  1507.        strcmp(arch->archive_head->filename,"__.SYMDEF") == 0) 
  1508.     {
  1509.     arch->archive_head = arch->archive_head->next;
  1510.     }
  1511.     /* Map over each element */
  1512.     for (current = arch->archive_head;
  1513.      current != (bfd *)NULL;
  1514.      current = current->next, elt_no++) 
  1515.     {
  1516.     if ((bfd_check_format (current, bfd_object) == true)
  1517.         && ((bfd_get_file_flags (current) & HAS_SYMS))) {
  1518.         asymbol **syms;
  1519.         unsigned int storage;
  1520.         unsigned int symcount;
  1521.         unsigned int src_count;
  1522.  
  1523.         storage = get_symtab_upper_bound (current);
  1524.         if (storage != 0) {
  1525.  
  1526.             syms = (asymbol **) bfd_zalloc (arch,storage);
  1527.             if (syms == NULL) {
  1528.                 bfd_error = no_memory; /* FIXME -- memory leak */
  1529.                 return false;
  1530.                 }
  1531.             symcount = bfd_canonicalize_symtab (current, syms);
  1532.  
  1533.  
  1534.             /* Now map over all the symbols, picking out the ones we want */
  1535.             for (src_count = 0; src_count <symcount; src_count++) {
  1536.                 flagword flags =
  1537.                  (syms[src_count])->flags;
  1538.                 asection  *sec =
  1539.                  syms[src_count]->section;
  1540.                 
  1541.                 if ((flags & BSF_GLOBAL ||
  1542.                      flags & BSF_WEAK ||
  1543.                      flags & BSF_INDIRECT ||
  1544.                      bfd_is_com_section (sec))
  1545.                     && (sec != &bfd_und_section)) {
  1546.  
  1547.                     /* This symbol will go into the archive header */
  1548.                     if (orl_count == orl_max) 
  1549.                     {
  1550.                         orl_max *= 2;
  1551.                         map = (struct orl *) bfd_realloc (arch, (char *) map,
  1552.                                           orl_max * sizeof (struct orl));
  1553.                     }
  1554.  
  1555.                     (map[orl_count]).name = (char **) &((syms[src_count])->name);
  1556.                     (map[orl_count]).pos = (file_ptr) current;
  1557.                     (map[orl_count]).namidx = stridx;
  1558.  
  1559.                     stridx += strlen ((syms[src_count])->name) + 1;
  1560.                     ++orl_count;
  1561.                     }
  1562.                 }
  1563.             }
  1564.         }
  1565.     }
  1566.     /* OK, now we have collected all the data, let's write them out */
  1567.     if (!BFD_SEND (arch, write_armap,
  1568.            (arch, elength, map, orl_count, stridx))) {
  1569.  
  1570.         return false;
  1571.     }
  1572.  
  1573.  
  1574.     return true;
  1575. }
  1576.  
  1577. boolean
  1578. bsd_write_armap (arch, elength, map, orl_count, stridx)
  1579.      bfd *arch;
  1580.      unsigned int elength;
  1581.      struct orl *map;
  1582.      unsigned int orl_count;
  1583.      int stridx;
  1584. {
  1585.   int padit = stridx & 1;
  1586.   unsigned int ranlibsize = orl_count * sizeof (struct ranlib);
  1587.   unsigned int stringsize = stridx + padit;
  1588.   /* Include 8 bytes to store ranlibsize and stringsize in output. */
  1589.   unsigned int mapsize = ranlibsize + stringsize + 8;
  1590.   file_ptr firstreal;
  1591.   bfd *current = arch->archive_head;
  1592.   bfd *last_elt = current;    /* last element arch seen */
  1593.   int temp;
  1594.   int count;
  1595.   struct ar_hdr hdr;
  1596.   struct stat statbuf;
  1597.   unsigned int i;
  1598.  
  1599.   firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG;
  1600.  
  1601.   stat (arch->filename, &statbuf);
  1602.   memset ((char *)(&hdr), 0, sizeof (struct ar_hdr));
  1603.   sprintf (hdr.ar_name, RANLIBMAG);
  1604.   /* Remember the timestamp, to keep it holy.  But fudge it a little.  */
  1605.   bfd_ardata(arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET;
  1606.   bfd_ardata(arch)->armap_datepos = SARMAG + 
  1607.                       offsetof(struct ar_hdr, ar_date[0]);
  1608.   sprintf (hdr.ar_date, "%ld", bfd_ardata(arch)->armap_timestamp);  
  1609.   sprintf (hdr.ar_uid, "%d", getuid());
  1610.   sprintf (hdr.ar_gid, "%d", getgid());
  1611.   sprintf (hdr.ar_size, "%-10d", (int) mapsize);
  1612.   hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
  1613.   for (i = 0; i < sizeof (struct ar_hdr); i++)
  1614.    if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
  1615.   bfd_write ((char *)&hdr, 1, sizeof (struct ar_hdr), arch);
  1616.   bfd_h_put_32(arch, (bfd_vma) ranlibsize, (PTR)&temp);
  1617.   bfd_write (&temp, 1, sizeof (temp), arch);
  1618.   
  1619.   for (count = 0; count < orl_count; count++) {
  1620.     struct symdef outs;
  1621.     struct symdef *outp = &outs;
  1622.     
  1623.     if (((bfd *)(map[count]).pos) != last_elt) {
  1624.       do {
  1625.     firstreal += arelt_size (current) + sizeof (struct ar_hdr);
  1626.     firstreal += firstreal % 2;
  1627.     current = current->next;
  1628.       } while (current != (bfd *)(map[count]).pos);
  1629.     }                /* if new archive element */
  1630.  
  1631.     last_elt = current;
  1632.     bfd_h_put_32(arch, ((map[count]).namidx),(PTR) &outs.s.string_offset);
  1633.     bfd_h_put_32(arch, firstreal,(PTR) &outs.file_offset);
  1634.     bfd_write ((char *)outp, 1, sizeof (outs), arch);
  1635.   }
  1636.  
  1637.   /* now write the strings themselves */
  1638.   bfd_h_put_32(arch, stringsize, (PTR)&temp);
  1639.   bfd_write ((PTR)&temp, 1, sizeof (temp), arch);
  1640.   for (count = 0; count < orl_count; count++)
  1641.    bfd_write (*((map[count]).name), 1, strlen (*((map[count]).name))+1, arch);
  1642.  
  1643.   /* The spec sez this should be a newline.  But in order to be
  1644.      bug-compatible for sun's ar we use a null. */
  1645.   if (padit)
  1646.    bfd_write("",1,1,arch);
  1647.  
  1648.   return true;
  1649. }
  1650.  
  1651.  
  1652. /* At the end of archive file handling, update the timestamp in the
  1653.    file, so the linker will accept it.  
  1654.  
  1655.    Return true if the timestamp was OK, or an unusual problem happened.
  1656.    Return false if we updated the timestamp.  */
  1657.  
  1658. static boolean
  1659. bsd_update_armap_timestamp (arch)
  1660.      bfd *arch;
  1661. {
  1662.   struct stat archstat;
  1663.   struct ar_hdr hdr;
  1664.   int i;
  1665.  
  1666.   /* Flush writes, get last-write timestamp from file, and compare it
  1667.      to the timestamp IN the file.  */
  1668.   bfd_flush (arch);
  1669.   if (bfd_stat (arch, &archstat) == -1) {
  1670.     perror ("Reading archive file mod timestamp");
  1671.     return true;        /* Can't read mod time for some reason */
  1672.   }
  1673.   if (archstat.st_mtime <= bfd_ardata(arch)->armap_timestamp)
  1674.     return true;        /* OK by the linker's rules */
  1675.  
  1676.   /* Update the timestamp.  */
  1677.   bfd_ardata(arch)->armap_timestamp = archstat.st_mtime + ARMAP_TIME_OFFSET;
  1678.  
  1679.   /* Prepare an ASCII version suitable for writing.  */
  1680.   memset (hdr.ar_date, 0, sizeof (hdr.ar_date));
  1681.   sprintf (hdr.ar_date, "%ld", bfd_ardata(arch)->armap_timestamp);  
  1682.   for (i = 0; i < sizeof (hdr.ar_date); i++)
  1683.    if (hdr.ar_date[i] == '\0')
  1684.      (hdr.ar_date)[i] = ' ';
  1685.  
  1686.   /* Write it into the file.  */
  1687.   bfd_seek (arch, bfd_ardata(arch)->armap_datepos, SEEK_SET);
  1688.   if (bfd_write (hdr.ar_date, sizeof(hdr.ar_date), 1, arch) 
  1689.       != sizeof(hdr.ar_date)) {
  1690.     perror ("Writing updated armap timestamp");
  1691.     return true;        /* Some error while writing */
  1692.   }
  1693.  
  1694.   return false;            /* We updated the timestamp successfully.  */
  1695. }
  1696.  
  1697.  
  1698. /* A coff armap looks like :
  1699.  lARMAG
  1700.  struct ar_hdr with name = '/' 
  1701.  number of symbols
  1702.  offset of file for symbol 0
  1703.  offset of file for symbol 1
  1704.  
  1705.  offset of file for symbol n-1
  1706.  symbol name 0
  1707.  symbol name 1    
  1708.  
  1709.  symbol name n-1
  1710.  
  1711. */
  1712.  
  1713. boolean
  1714. coff_write_armap (arch, elength, map, symbol_count, stridx)
  1715.      bfd *arch;
  1716.      unsigned int elength;
  1717.      struct orl *map;
  1718.      unsigned int symbol_count;
  1719.      int stridx;
  1720. {
  1721.     /* The size of the ranlib is the number of exported symbols in the
  1722.        archive * the number of bytes in a int, + an int for the count */
  1723.  
  1724.     unsigned int ranlibsize = (symbol_count * 4) + 4;
  1725.     unsigned int stringsize = stridx;
  1726.     unsigned int mapsize = stringsize + ranlibsize;
  1727.     file_ptr archive_member_file_ptr;
  1728.     bfd *current = arch->archive_head;
  1729.     int count;
  1730.     struct ar_hdr hdr;
  1731.     unsigned int i;
  1732.     int padit = mapsize & 1;
  1733.   
  1734.     if (padit) mapsize ++;
  1735.  
  1736.     /* work out where the first object file will go in the archive */
  1737.     archive_member_file_ptr =   mapsize + elength + sizeof (struct ar_hdr) + SARMAG;
  1738.  
  1739.     memset ((char *)(&hdr), 0, sizeof (struct ar_hdr));
  1740.     hdr.ar_name[0] = '/';
  1741.     sprintf (hdr.ar_size, "%-10d", (int) mapsize);
  1742.     sprintf (hdr.ar_date, "%ld", (long)time (NULL));
  1743.     /* This, at least, is what Intel coff sets the values to.: */
  1744.     sprintf ((hdr.ar_uid), "%d", 0);
  1745.     sprintf ((hdr.ar_gid), "%d", 0);
  1746.     sprintf ((hdr.ar_mode), "%-7o",(unsigned ) 0);
  1747.     hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
  1748.  
  1749.     for (i = 0; i < sizeof (struct ar_hdr); i++)
  1750.      if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
  1751.  
  1752.     /* Write the ar header for this item and the number of symbols */
  1753.  
  1754.   
  1755.     bfd_write ((PTR)&hdr, 1, sizeof (struct ar_hdr), arch);
  1756.  
  1757.     bfd_write_bigendian_4byte_int(arch, symbol_count);
  1758.  
  1759.     /* Two passes, first write the file offsets for each symbol -
  1760.        remembering that each offset is on a two byte boundary.  */
  1761.  
  1762.     /* Write out the file offset for the file associated with each
  1763.        symbol, and remember to keep the offsets padded out.  */
  1764.  
  1765.     current = arch->archive_head;
  1766.     count = 0;
  1767.     while (current != (bfd *)NULL && count < symbol_count) {
  1768.     /* For each symbol which is used defined in this object, write out
  1769.        the object file's address in the archive */
  1770.     
  1771.     while (((bfd *)(map[count]).pos) == current) {
  1772.         bfd_write_bigendian_4byte_int(arch, archive_member_file_ptr);
  1773.         count++;
  1774.     }
  1775.     /* Add size of this archive entry */
  1776.     archive_member_file_ptr += arelt_size (current) + sizeof (struct
  1777.                                   ar_hdr);
  1778.     /* remember aboout the even alignment */
  1779.     archive_member_file_ptr += archive_member_file_ptr % 2;
  1780.     current = current->next;
  1781.     }  
  1782.  
  1783.  
  1784.  
  1785.     /* now write the strings themselves */
  1786.     for (count = 0; count < symbol_count; count++) {
  1787.     bfd_write ((PTR)*((map[count]).name),
  1788.            1,
  1789.            strlen (*((map[count]).name))+1, arch);
  1790.  
  1791.     }
  1792.     /* The spec sez this should be a newline.  But in order to be
  1793.        bug-compatible for arc960 we use a null. */
  1794.     if (padit)
  1795.      bfd_write("",1,1,arch);
  1796.  
  1797.     return true;
  1798. }
  1799.