aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
@@ -229,12 +229,13 @@ int gdbm_setopt(dbf, option, value, size);
int gdbm_fdesc(dbf);
int gdbm_export (GDBM_FILE, const char *, int, int);
int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp);
int gdbm_import (GDBM_FILE, const char *, int);
int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag);
int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount);
+int gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount);
int gdbm_version_cmp (int const a[], int const b[]);
@end example
The @code{gdbm.h} include file is often in the @file{/usr/include}
directory. (The actual location of @code{gdbm.h} depends on your local
installation of @code{gdbm}.)
@@ -391,12 +392,20 @@ describing the error and returns -1.
Counts number of records in the database @var{dbf}. On success,
stores it in the memory location pointed to by @var{pcount} and return
0. On error, sets @code{gdbm_errno} (if relevant, also @code{errno})
and returns -1.
@end deftypefn
+@deftypefn {gdbm interface} int gdbm_bucket_count (GDBM_FILE @var{dbf}, @
+ size_t *@var{pcount})
+Counts number of buckets in the database @var{dbf}. On success,
+stores it in the memory location pointed to by @var{pcount} and return
+0. On error, sets @code{gdbm_errno} (if relevant, also @code{errno})
+and returns -1.
+@end deftypefn
+
@node Store
@chapter Inserting and replacing records in the database.
@cindex storing records
@cindex records, storing
@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);
extern int gdbm_export_to_file (GDBM_FILE dbf, FILE *fp);
extern int gdbm_import (GDBM_FILE, const char *, int);
extern int gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag);
extern int gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount);
+extern int gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount);
+
typedef struct gdbm_recovery_s
{
/* Input members.
These are initialized before call to gdbm_recover. The flags argument
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)
return -1;
count += dbf->bucket->count;
}
*pcount = count;
return 0;
}
+
+int
+gdbm_bucket_count (GDBM_FILE dbf, size_t *pcount)
+{
+ int i;
+ size_t count = 0;
+
+ GDBM_ASSERT_CONSISTENCY (dbf, -1);
+
+ for (i = 0; i < GDBM_DIR_COUNT (dbf); i = _gdbm_next_bucket_dir (dbf, i))
+ {
+ ++count;
+ }
+ *pcount = count;
+ return 0;
+}
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)
return 0;
}
static size_t
bucket_count (void)
{
- int i;
- off_t last = 0;
size_t count = 0;
- for (i = 0; i < GDBM_DIR_COUNT (gdbm_file); i++)
+ if (gdbm_bucket_count (gdbm_file, &count))
{
- if (gdbm_file->dir[i] != last)
- {
- ++count;
- last = gdbm_file->dir[i];
- }
+ terror ("gdbm_bucket_count: %s", gdbm_strerror (gdbm_errno));
}
return count;
}
void
print_dir_handler (struct handler_param *param)

Return to:

Send suggestions and report system problems to the System administrator.