diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-03-15 17:32:42 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-03-15 17:32:42 +0200 |
commit | 02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566 (patch) | |
tree | 61071105561260e4b08a8e3faee5f8a07645fc79 | |
parent | 1f94a81a9f3a9955ca74dff07b7909595a850485 (diff) | |
download | gdbm-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.texi | 9 | ||||
-rw-r--r-- | src/gdbm.h.in | 2 | ||||
-rw-r--r-- | src/gdbmcount.c | 16 | ||||
-rw-r--r-- | src/gdbmtool.c | 12 |
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); | |||
229 | int gdbm_fdesc(dbf); | 229 | int gdbm_fdesc(dbf); |
230 | int gdbm_export (GDBM_FILE, const char *, int, int); | 230 | int gdbm_export (GDBM_FILE, const char *, int, int); |
231 | int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp); | 231 | int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp); |
232 | int gdbm_import (GDBM_FILE, const char *, int); | 232 | int gdbm_import (GDBM_FILE, const char *, int); |
233 | int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag); | 233 | int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag); |
234 | int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount); | 234 | int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount); |
235 | int gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount); | ||
235 | int gdbm_version_cmp (int const a[], int const b[]); | 236 | int gdbm_version_cmp (int const a[], int const b[]); |
236 | @end example | 237 | @end example |
237 | 238 | ||
238 | The @code{gdbm.h} include file is often in the @file{/usr/include} | 239 | The @code{gdbm.h} include file is often in the @file{/usr/include} |
239 | directory. (The actual location of @code{gdbm.h} depends on your local | 240 | directory. (The actual location of @code{gdbm.h} depends on your local |
240 | installation of @code{gdbm}.) | 241 | installation of @code{gdbm}.) |
@@ -391,12 +392,20 @@ describing the error and returns -1. | |||
391 | Counts number of records in the database @var{dbf}. On success, | 392 | Counts number of records in the database @var{dbf}. On success, |
392 | stores it in the memory location pointed to by @var{pcount} and return | 393 | stores it in the memory location pointed to by @var{pcount} and return |
393 | 0. On error, sets @code{gdbm_errno} (if relevant, also @code{errno}) | 394 | 0. On error, sets @code{gdbm_errno} (if relevant, also @code{errno}) |
394 | and returns -1. | 395 | and 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}) | ||
400 | Counts number of buckets in the database @var{dbf}. On success, | ||
401 | stores it in the memory location pointed to by @var{pcount} and return | ||
402 | 0. On error, sets @code{gdbm_errno} (if relevant, also @code{errno}) | ||
403 | and 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); | |||
130 | extern int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp); | 130 | extern int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp); |
131 | 131 | ||
132 | extern int gdbm_import (GDBM_FILE, const char *, int); | 132 | extern int gdbm_import (GDBM_FILE, const char *, int); |
133 | extern int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag); | 133 | extern int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag); |
134 | 134 | ||
135 | extern int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount); | 135 | extern int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount); |
136 | extern int gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount); | ||
137 | |||
136 | 138 | ||
137 | typedef struct gdbm_recovery_s | 139 | typedef 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 | |||
44 | int | ||
45 | gdbm_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 | ||
788 | static size_t | 788 | static size_t |
789 | bucket_count (void) | 789 | 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 | } |
803 | return count; | 797 | return count; |
804 | } | 798 | } |
805 | 799 | ||
806 | void | 800 | void |
807 | print_dir_handler (struct handler_param *param) | 801 | print_dir_handler (struct handler_param *param) |