]> Git Repo - binutils.git/blobdiff - libctf/ctf-archive.c
Automatic date update in version.in
[binutils.git] / libctf / ctf-archive.c
index 6d9c75c9013248dd6a3ff3957c8f81e87a078505..8366d7fd606df5656959cd05c91433480566fb10 100644 (file)
@@ -1,5 +1,5 @@
 /* CTF archive files.
-   Copyright (C) 2019-2021 Free Software Foundation, Inc.
+   Copyright (C) 2019-2022 Free Software Foundation, Inc.
 
    This file is part of libctf.
 
@@ -1043,70 +1043,32 @@ ctf_archive_raw_iter (const ctf_archive_t *arc,
   return -EINVAL;                       /* Not supported. */
 }
 
-/* Iterate over all CTF files in an archive.  We pass all CTF files in turn to
-   the specified callback function.  */
-static int
-ctf_archive_iter_internal (const ctf_archive_t *wrapper,
-                          const struct ctf_archive *arc,
-                          const ctf_sect_t *symsect,
-                          const ctf_sect_t *strsect,
-                          ctf_archive_member_f *func, void *data)
+/* Iterate over all CTF files in an archive: public entry point.  We pass all
+   CTF files in turn to the specified callback function.  */
+int
+ctf_archive_iter (const ctf_archive_t *arc, ctf_archive_member_f *func,
+                 void *data)
 {
-  int rc;
-  size_t i;
-  ctf_dict_t *f;
-  struct ctf_archive_modent *modent;
-  const char *nametbl;
-
-  modent = (ctf_archive_modent_t *) ((char *) arc
-                                    + sizeof (struct ctf_archive));
-  nametbl = (((const char *) arc) + le64toh (arc->ctfa_names));
+  ctf_next_t *i = NULL;
+  ctf_dict_t *fp;
+  const char *name;
+  int err;
 
-  for (i = 0; i < le64toh (arc->ctfa_ndicts); i++)
+  while ((fp = ctf_archive_next (arc, &i, &name, 0, &err)) != NULL)
     {
-      const char *name;
-
-      name = &nametbl[le64toh (modent[i].name_offset)];
-      if ((f = ctf_dict_open_internal (arc, symsect, strsect,
-                                      name,
-                                      wrapper->ctfi_symsect_little_endian,
-                                      &rc)) == NULL)
-       return rc;
+      int rc;
 
-      f->ctf_archive = (ctf_archive_t *) wrapper;
-      ctf_arc_import_parent (wrapper, f);
-      if ((rc = func (f, name, data)) != 0)
+      if ((rc = func (fp, name, data)) != 0)
        {
-         ctf_dict_close (f);
+         ctf_dict_close (fp);
+         ctf_next_destroy (i);
          return rc;
        }
-
-      ctf_dict_close (f);
+      ctf_dict_close (fp);
     }
   return 0;
 }
 
-/* Iterate over all CTF files in an archive: public entry point.  We pass all
-   CTF files in turn to the specified callback function.  */
-int
-ctf_archive_iter (const ctf_archive_t *arc, ctf_archive_member_f *func,
-                 void *data)
-{
-  const ctf_sect_t *symsect = &arc->ctfi_symsect;
-  const ctf_sect_t *strsect = &arc->ctfi_strsect;
-
-  if (symsect->cts_name == NULL)
-    symsect = NULL;
-  if (strsect->cts_name == NULL)
-    strsect = NULL;
-
-  if (arc->ctfi_is_archive)
-    return ctf_archive_iter_internal (arc, arc->ctfi_archive, symsect, strsect,
-                                     func, data);
-
-  return func (arc->ctfi_dict, _CTF_SECTION, data);
-}
-
 /* Iterate over all CTF files in an archive, returning each dict in turn as a
    ctf_dict_t, and NULL on error or end of iteration.  It is the caller's
    responsibility to close it.  Parent dicts may be skipped.
@@ -1165,6 +1127,8 @@ ctf_archive_next (const ctf_archive_t *wrapper, ctf_next_t **it, const char **na
       if (!skip_parent)
        {
          wrapper->ctfi_dict->ctf_refcnt++;
+         if (name)
+           *name = _CTF_SECTION;
          return wrapper->ctfi_dict;
        }
     }
@@ -1192,7 +1156,8 @@ ctf_archive_next (const ctf_archive_t *wrapper, ctf_next_t **it, const char **na
 
       name_ = &nametbl[le64toh (modent[i->ctn_n].name_offset)];
       i->ctn_n++;
-    } while (skip_parent && strcmp (name_, _CTF_SECTION) == 0);
+    }
+  while (skip_parent && strcmp (name_, _CTF_SECTION) == 0);
 
   if (name)
     *name = name_;
This page took 0.025871 seconds and 4 git commands to generate.