[18/59] libctf: add ctf_archive_count

Message ID 20200630233146.338613-19-nick.alcock@oracle.com
State New
Headers show
Series
  • Deduplicating CTF linker
Related show

Commit Message

H.J. Lu via Binutils June 30, 2020, 11:31 p.m.
Another count that was otherwise unavailable without doing expensive
operations.

include/
	* ctf-api.h (ctf_archive_count): New.

libctf/
	* ctf-archive.c (ctf_archive_count): New.
	* libctf.ver: New public function.
---
 include/ctf-api.h    |  1 +
 libctf/ctf-archive.c | 10 ++++++++++
 libctf/libctf.ver    |  1 +
 3 files changed, 12 insertions(+)

-- 
2.27.0.247.g3dff7de930

Patch

diff --git a/include/ctf-api.h b/include/ctf-api.h
index 7cdf4a56235..fb797a3346d 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -276,6 +276,7 @@  extern ctf_file_t *ctf_arc_open_by_name_sections (const ctf_archive_t *,
 						  const ctf_sect_t *,
 						  const ctf_sect_t *,
 						  const char *, int *);
+extern size_t ctf_archive_count (const ctf_archive_t *);
 
 /* The next functions return or close real CTF files, or write out CTF archives,
    not opaque containers around either.  */
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index 303c94d97a4..1cfe40f6e3a 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -624,6 +624,16 @@  ctf_arc_open_by_offset (const struct ctf_archive *arc,
   return fp;
 }
 
+/* Return the number of members in an archive.  */
+size_t
+ctf_archive_count (const ctf_archive_t *wrapper)
+{
+  if (!wrapper->ctfi_is_archive)
+    return 1;
+
+  return wrapper->ctfi_archive->ctfa_nfiles;
+}
+
 /* Raw iteration over all CTF files in an archive.  We pass the raw data for all
    CTF files in turn to the specified callback function.  */
 static int
diff --git a/libctf/libctf.ver b/libctf/libctf.ver
index 77b380ca991..375dee8fc77 100644
--- a/libctf/libctf.ver
+++ b/libctf/libctf.ver
@@ -135,6 +135,7 @@  LIBCTF_1.0 {
 	ctf_arc_close;
 	ctf_arc_open_by_name;
 	ctf_arc_open_by_name_sections;
+	ctf_archive_count;
 	ctf_archive_iter;
 	ctf_archive_raw_iter;
 	ctf_get_arc;