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
@@ -229,12 +229,13 @@ int gdbm_setopt(dbf, option, value, size);
229int gdbm_fdesc(dbf); 229int gdbm_fdesc(dbf);
230int gdbm_export (GDBM_FILE, const char *, int, int); 230int gdbm_export (GDBM_FILE, const char *, int, int);
231int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp); 231int 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
238The @code{gdbm.h} include file is often in the @file{/usr/include} 239The @code{gdbm.h} include file is often in the @file{/usr/include}
239directory. (The actual location of @code{gdbm.h} depends on your local 240directory. (The actual location of @code{gdbm.h} depends on your local
240installation of @code{gdbm}.) 241installation of @code{gdbm}.)
@@ -391,12 +392,20 @@ describing the error and returns -1.
391Counts number of records in the database @var{dbf}. On success, 392Counts number of records in the database @var{dbf}. On success,
392stores it in the memory location pointed to by @var{pcount} and return 393stores it in the memory location pointed to by @var{pcount} and return
3930. On error, sets @code{gdbm_errno} (if relevant, also @code{errno}) 3940. On error, sets @code{gdbm_errno} (if relevant, also @code{errno})
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
400@cindex records, storing 409@cindex records, storing
401 410
402@deftypefn {gdbm interface} int gdbm_store (GDBM_FILE @var{dbf}, datum @var{key}, @ 411@deftypefn {gdbm interface} int gdbm_store (GDBM_FILE @var{dbf}, datum @var{key}, @
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
@@ -130,12 +130,14 @@ extern int gdbm_export (GDBM_FILE, const char *, int, int);
130extern int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp); 130extern int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp);
131 131
132extern int gdbm_import (GDBM_FILE, const char *, int); 132extern 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{
139 /* Input members. 141 /* Input members.
140 These are initialized before call to gdbm_recover. The flags argument 142 These are initialized before call to gdbm_recover. The flags argument
141 specifies which of them are initialized. */ 143 specifies which of them are initialized. */
diff --git a/src/gdbmcount.c b/src/gdbmcount.c
index 4a78bc0..c81a461 100644
--- a/src/gdbmcount.c
+++ b/src/gdbmcount.c
@@ -37,6 +37,22 @@ gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount)
37 return -1; 37 return -1;
38 count += dbf->bucket->count; 38 count += dbf->bucket->count;
39 } 39 }
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
@@ -785,23 +785,17 @@ print_dir_begin (struct handler_param *param GDBM_ARG_UNUSED, size_t *exp_count)
785 return 0; 785 return 0;
786} 786}
787 787
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}
805 799
806void 800void
807print_dir_handler (struct handler_param *param) 801print_dir_handler (struct handler_param *param)

Return to:

Send suggestions and report system problems to the System administrator.