This lot mainly cleans up `comparison between signed and unsigned' gcc
[deliverable/binutils-gdb.git] / bfd / archive.c
index 10bf43c2b7f4a602d45f3297f44e8c9191961c09..19293af4573d5b15cff62a64a8387be62c0294ff 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for archive files (libraries).
-   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
    Free Software Foundation, Inc.
    Written by Cygnus Support.  Mostly Gumby Henkel-Wallace's fault.
 
@@ -131,8 +131,6 @@ DESCRIPTION
 #include "libbfd.h"
 #include "aout/ar.h"
 #include "aout/ranlib.h"
-#include <errno.h>
-#include <string.h>            /* For memchr, strrchr and friends */
 #include <ctype.h>
 
 #ifndef errno
@@ -175,7 +173,8 @@ static boolean do_slurp_bsd_armap PARAMS ((bfd *abfd));
 static boolean do_slurp_coff_armap PARAMS ((bfd *abfd));
 static const char *normalize PARAMS ((bfd *, const char *file));
 static struct areltdata *bfd_ar_hdr_from_filesystem PARAMS ((bfd *abfd,
-                                                            const char *));
+                                                            const char *,
+                                                            bfd *member));
 \f
 boolean
 _bfd_generic_mkarchive (abfd)
@@ -397,7 +396,7 @@ _bfd_generic_read_ar_hdr_mag (abfd, mag)
     }
 
   /* Extract the filename from the archive - there are two ways to
-     specify an extendend name table, either the first char of the
+     specify an extended name table, either the first char of the
      name is a space, or it's a slash.  */
   if ((hdr.ar_name[0] == '/'
        || (hdr.ar_name[0] == ' '
@@ -444,20 +443,23 @@ _bfd_generic_read_ar_hdr_mag (abfd, mag)
         spaces, so only look for ' ' if we don't find '/'. */
 
       char *e;
-      e = memchr(hdr.ar_name, '\0', ar_maxnamelen (abfd));
+      e = memchr (hdr.ar_name, '\0', ar_maxnamelen (abfd));
       if (e == NULL)
        {
-          e = memchr(hdr.ar_name, '/', ar_maxnamelen (abfd));
+          e = memchr (hdr.ar_name, '/', ar_maxnamelen (abfd));
          if (e == NULL)
-            e = memchr(hdr.ar_name, ' ', ar_maxnamelen (abfd));
+            e = memchr (hdr.ar_name, ' ', ar_maxnamelen (abfd));
        }
-      if (e == NULL)
+
+      if (e != NULL)
+       namelen = e - hdr.ar_name;
+      else
        {
-         bfd_set_error (bfd_error_malformed_archive);
-         return NULL;
+         /* If we didn't find a termination character, then the name
+            must be the entire field.  */
+         namelen = ar_maxnamelen (abfd);
        }
 
-      namelen = e - hdr.ar_name;
       allocsize += namelen + 1;
     }
 
@@ -1176,7 +1178,7 @@ normalize (abfd, file)
 #else
 static const char *
 normalize (abfd, file)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      const char *file;
 {
   const char *filename = strrchr (file, '/');
@@ -1338,21 +1340,41 @@ _bfd_construct_extended_name_table (abfd, trailing_slash, tabloc, tablen)
 \f
 /** A couple of functions for creating ar_hdrs */
 
+#ifndef HAVE_GETUID
+#define getuid() 0
+#endif
+
+#ifndef HAVE_GETGID
+#define getgid() 0
+#endif
+
 /* Takes a filename, returns an arelt_data for it, or NULL if it can't
    make one.  The filename must refer to a filename in the filesystem.
-   The filename field of the ar_hdr will NOT be initialized */
+   The filename field of the ar_hdr will NOT be initialized.  If member
+   is set, and it's an in-memory bfd, we fake it. */
 
 static struct areltdata *
-bfd_ar_hdr_from_filesystem (abfd, filename)
+bfd_ar_hdr_from_filesystem (abfd, filename, member)
      bfd *abfd;
      const char *filename;
+     bfd *member;
 {
   struct stat status;
   struct areltdata *ared;
   struct ar_hdr *hdr;
   char *temp, *temp1;
 
-  if (stat (filename, &status) != 0)
+  if (member && (member->flags & BFD_IN_MEMORY) != 0)
+    {
+      /* Assume we just "made" the member, and fake it */
+      struct bfd_in_memory *bim = (struct bfd_in_memory *) member->iostream;
+      time(&status.st_mtime);
+      status.st_uid = getuid();
+      status.st_gid = getgid();
+      status.st_mode = 0644;
+      status.st_size = bim->size;
+    }
+  else if (stat (filename, &status) != 0)
     {
       bfd_set_error (bfd_error_system_call);
       return NULL;
@@ -1404,7 +1426,7 @@ bfd_special_undocumented_glue (abfd, filename)
      bfd *abfd;
      const char *filename;
 {
-  struct areltdata *ar_elt = bfd_ar_hdr_from_filesystem (abfd, filename);
+  struct areltdata *ar_elt = bfd_ar_hdr_from_filesystem (abfd, filename, 0);
   if (ar_elt == NULL)
     return NULL;
   return (struct ar_hdr *) ar_elt->arch_header;
@@ -1586,7 +1608,7 @@ _bfd_write_archive_contents (arch)
       if (!current->arelt_data)
        {
          current->arelt_data =
-           (PTR) bfd_ar_hdr_from_filesystem (arch, current->filename);
+           (PTR) bfd_ar_hdr_from_filesystem (arch, current->filename, current);
          if (!current->arelt_data)
            return false;
 
@@ -1887,13 +1909,8 @@ bsd_write_armap (arch, elength, map, orl_count, stridx)
   bfd_ardata (arch)->armap_datepos = (SARMAG
                                      + offsetof (struct ar_hdr, ar_date[0]));
   sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp);
-#ifndef _WIN32
   sprintf (hdr.ar_uid, "%ld", (long) getuid ());
   sprintf (hdr.ar_gid, "%ld", (long) getgid ());
-#else
-  sprintf (hdr.ar_uid, "%ld", (long) 666);
-  sprintf (hdr.ar_gid, "%ld", (long) 42);
-#endif
   sprintf (hdr.ar_size, "%-10d", (int) mapsize);
   strncpy (hdr.ar_fmag, ARFMAG, 2);
   for (i = 0; i < sizeof (struct ar_hdr); i++)
This page took 0.025293 seconds and 4 git commands to generate.