libctf: add ctf_archive_count
authorNick Alcock <nick.alcock@oracle.com>
Tue, 2 Jun 2020 20:14:22 +0000 (21:14 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Wed, 22 Jul 2020 16:57:39 +0000 (17:57 +0100)
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/ChangeLog
include/ctf-api.h
libctf/ChangeLog
libctf/ctf-archive.c
libctf/libctf.ver

index 27ffb9051ed87ab10a4ea6ca8e6b1a9b4cae35c1..dd9d5e075ca2fcbb780529a493c4f9c2b92e39f2 100644 (file)
@@ -1,3 +1,7 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-api.h (ctf_archive_count): New.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-api.h (ctf_member_count): New.
index 7cdf4a562355154cf931779c24014c9c29113674..fb797a3346db33cb6b91be38933991d2acfce652 100644 (file)
@@ -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.  */
index 7df7867b4cb21f0159770d7930d73c4d72bdeaeb..0be82801845dd4dafdb1f1b3d0e71461050459bb 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-archive.c (ctf_archive_count): New.
+       * libctf.ver: New public function.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-types.c (ctf_member_count): New.
index 3c14d7d12f917850a18ff2f6366ad75abdbcab61..42e902499347efafc7a4b297d554647c17e35908 100644 (file)
@@ -617,6 +617,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
index 77b380ca99127e74c6b83031acd5e39ee6ade299..375dee8fc770a8fe03ccee40b6fc6b0adaa17f46 100644 (file)
@@ -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;