aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-03-15 17:32:42 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-03-15 17:32:42 +0200
commit02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566 (patch)
tree61071105561260e4b08a8e3faee5f8a07645fc79
parent1f94a81a9f3a9955ca74dff07b7909595a850485 (diff)
downloadgdbm-02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566.tar.gz
gdbm-02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566.tar.bz2
Implement the gdbm_bucket_count function.
* src/gdbmcount.c (gdbm_bucket_count): New function. * src/gdbm.h.in (gdbm_bucket_count): New proto. * doc/gdbm.texi: Document gdbm_bucket_count. * src/gdbmtool.c (bucket_count): Reimplement via gdbm_bucket_count.
-rw-r--r--doc/gdbm.texi9
-rw-r--r--src/gdbm.h.in2
-rw-r--r--src/gdbmcount.c16
-rw-r--r--src/gdbmtool.c12
4 files changed, 30 insertions, 9 deletions
diff --git a/doc/gdbm.texi b/doc/gdbm.texi
index 159a108..53c9782 100644
--- a/doc/gdbm.texi
+++ b/doc/gdbm.texi
@@ -234,2 +234,3 @@ int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag);
234int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount); 234int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount);
235int gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount);
235int gdbm_version_cmp (int const a[], int const b[]); 236int gdbm_version_cmp (int const a[], int const b[]);
@@ -396,2 +397,10 @@ and returns -1.
396 397
398@deftypefn {gdbm interface} int gdbm_bucket_count (GDBM_FILE @var{dbf}, @
399 size_t *@var{pcount})
400Counts number of buckets in the database @var{dbf}. On success,
401stores it in the memory location pointed to by @var{pcount} and return
4020. On error, sets @code{gdbm_errno} (if relevant, also @code{errno})
403and returns -1.
404@end deftypefn
405
397@node Store 406@node Store
diff --git a/src/gdbm.h.in b/src/gdbm.h.in
index 804e051..668af7c 100644
--- a/src/gdbm.h.in
+++ b/src/gdbm.h.in
@@ -135,2 +135,4 @@ extern int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag);
135extern int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount); 135extern int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount);
136extern int gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount);
137
136 138
diff --git a/src/gdbmcount.c b/src/gdbmcount.c
index 4a78bc0..c81a461 100644
--- a/src/gdbmcount.c
+++ b/src/gdbmcount.c
@@ -42 +42,17 @@ gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount)
42} 42}
43
44int
45gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount)
46{
47 int i;
48 size_t count = 0;
49
50 GDBM_ASSERT_CONSISTENCY (dbf, -1);
51
52 for (i = 0; i < GDBM_DIR_COUNT (dbf); i = _gdbm_next_bucket_dir (dbf, i))
53 {
54 ++count;
55 }
56 *pcount = count;
57 return 0;
58}
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
index f9a4924..f439207 100644
--- a/src/gdbmtool.c
+++ b/src/gdbmtool.c
@@ -790,13 +790,7 @@ bucket_count (void)
790{ 790{
791 int i;
792 off_t last = 0;
793 size_t count = 0; 791 size_t count = 0;
794 792
795 for (i = 0; i < GDBM_DIR_COUNT (gdbm_file); i++) 793 if (gdbm_bucket_count (gdbm_file, &count))
796 { 794 {
797 if (gdbm_file->dir[i] != last) 795 terror ("gdbm_bucket_count: %s", gdbm_strerror (gdbm_errno));
798 {
799 ++count;
800 last = gdbm_file->dir[i];
801 }
802 } 796 }

Return to:

Send suggestions and report system problems to the System administrator.