+static char *sym_tab;
+static int sym_tab_size;
+
+char *
+get_member_name (char *name, size_t *p_size, int allocate, FILE * libfp)
+{
+ *p_size = 0;
+
+ if (0 == memcmp (name, "#1/", 3))
+ {
+ char *p;
+ size_t len = strtoul (&name [3], &p, 10);
+ if (p > &name [3])
+ {
+ /* BSD appends real file name to the file header */
+ if (p_size != NULL)
+ *p_size = len;
+
+ if (allocate)
+ {
+ char *n = (char *) malloc (len);
+ if (fread (n, 1, len, libfp) != len)
+ {
+ /* not an ar archive or broken ar archive */
+ return NULL;
+ }
+ else
+ return n;
+ }
+ else
+ {
+ /* just advance the file pointer */
+ fseek (libfp, len, SEEK_CUR);
+ return NULL;
+ }
+ }
+ else
+ {
+ /* not an ar archive or broken ar archive */
+ return NULL;
+ }
+ }
+ else if (allocate)
+ {
+ if (name[0] == '/')
+ {
+ if (NULL != sym_tab)
+ {
+ char *p;
+
+ int name_offset = strtol (++name, &p, 0);
+ if (p != name && name_offset < sym_tab_size)
+ {
+ int len = p - name + 1;
+ while (len < AR_NAME_LEN && name[len++] == ' ')
+ ;
+ if (len == AR_NAME_LEN)
+ {
+ char *n;
+
+ /* long name: get it from the symbol table */
+ name = &sym_tab[name_offset];
+ for (p = name; *p != '/' && *p != '\n'; ++p)
+ assert (p < &sym_tab[sym_tab_size]);
+
+ if (p[0] != '/' || p[1] != '\n')
+ while (*++p != '\n')
+ assert (p < &sym_tab[sym_tab_size]);
+
+ n = (char *) malloc (p - name + 1);
+ memcpy (n, name, p - name);
+ n[p - name] = '\0';
+ return n;
+ }
+ }
+ }
+ }
+ else
+ {
+ char *p = strrchr (name, '/');
+
+ if (NULL != p)
+ {
+ int len = p - name;
+ while (name[++len] == ' ')
+ ;
+ if (len == AR_NAME_LEN)
+ {
+ char *n = (char *) malloc (p - name + 1);
+ memcpy (n, name, p - name);
+ n[p - name] = '\0';
+ return n;
+ }
+ }
+ else
+ {
+ /* BSD formed member name:
+ trim trailing spaces */
+ char *n;
+
+ p = name + AR_NAME_LEN;
+ while (*--p == ' ' && p >= name)
+ ;
+ ++p;
+ n = (char *) malloc (p - name + 1);
+ memcpy (n, name, p - name);
+ n[p - name] = '\0';
+ return n;
+ }
+ }
+
+ /* bad formed member name:
+ just return it */
+
+ return strdup (name);
+ }
+ else
+ return NULL;
+}
+
+size_t
+ar_get_header (struct ar_hdr *hdr, FILE * libfp, char **p_obj_name)