summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2020-03-15 15:32:42 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2020-03-15 15:32:42 (GMT)
commit02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566 (patch) (unidiff)
tree61071105561260e4b08a8e3faee5f8a07645fc79
parent1f94a81a9f3a9955ca74dff07b7909595a850485 (diff)
downloadgdbm-02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566.tar.gz
gdbm-02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566.tar.bz2
Implement the gdbm_bucket_count function.newcache
* 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.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--doc/gdbm.texi9
-rw-r--r--src/gdbm.h.in2
-rw-r--r--src/gdbmcount.c16
-rw-r--r--src/gdbmtool.c10
4 files changed, 29 insertions, 8 deletions
diff --git a/doc/gdbm.texi b/doc/gdbm.texi
index 159a108..53c9782 100644
--- a/doc/gdbm.texi
+++ b/doc/gdbm.texi
@@ -232,6 +232,7 @@ int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp);
232int gdbm_import (GDBM_FILE, const char *, int); 232int gdbm_import (GDBM_FILE, const char *, int);
233int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag); 233int 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[]);
236@end example 237@end example
237 238
@@ -394,6 +395,14 @@ stores it in the memory location pointed to by @var{pcount} and return
394and returns -1. 395and returns -1.
395@end deftypefn 396@end deftypefn
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
398@chapter Inserting and replacing records in the database. 407@chapter Inserting and replacing records in the database.
399@cindex storing records 408@cindex storing records
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
@@ -133,6 +133,8 @@ extern int gdbm_import (GDBM_FILE, const char *, int);
133extern int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag); 133extern int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag);
134 134
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
137typedef struct gdbm_recovery_s 139typedef struct gdbm_recovery_s
138{ 140{
diff --git a/src/gdbmcount.c b/src/gdbmcount.c
index 4a78bc0..c81a461 100644
--- a/src/gdbmcount.c
+++ b/src/gdbmcount.c
@@ -40,3 +40,19 @@ gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount)
40 *pcount = count; 40 *pcount = count;
41 return 0; 41 return 0;
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
@@ -788,17 +788,11 @@ print_dir_begin (struct handler_param *param GDBM_ARG_UNUSED, size_t *exp_count)
788static size_t 788static size_t
789bucket_count (void) 789bucket_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 }
803 return count; 797 return count;
804} 798}

Return to:

Send suggestions and report system problems to the System administrator.