aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-07-15 19:36:39 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-07-15 19:36:39 +0300
commit493772dc60886a315c749bf31fc1cbe682df5973 (patch)
tree9743f55e082e3306cf7ea3add00c152323afd065
parent44ca2b760b393e993b2a42fc489fa170910ad810 (diff)
downloadgdbm-493772dc60886a315c749bf31fc1cbe682df5973.tar.gz
gdbm-493772dc60886a315c749bf31fc1cbe682df5973.tar.bz2
New gdbm_setopt option to get the actual block size value
* src/gdbm.h.in (GDBM_GETBLOCKSIZE): New option. * src/gdbmcount.c (gdbm_count): Fix memory leak on error. * src/gdbmsetopt.c (gdbm_setopt): Rewrite. Handle GDBM_GETBLOCKSIZE. * NEWS: Document GDBM_GETBLOCKSIZE * doc/gdbm.texi: Likewise. * tests/gtload.c: New options -bsexact and -verbose. * tests/Makefile.am: Add new testcases. * tests/testsuite.at: Likewise. * tests/blocksize00.at: New testcase. * tests/blocksize01.at: Likewise. * tests/blocksize02.at: Likewise.
-rw-r--r--NEWS9
-rw-r--r--doc/gdbm.texi4
-rw-r--r--src/gdbm.h.in1
-rw-r--r--src/gdbmcount.c11
-rw-r--r--src/gdbmsetopt.c484
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/blocksize00.at36
-rw-r--r--tests/blocksize01.at32
-rw-r--r--tests/blocksize02.at28
-rw-r--r--tests/gtload.c23
-rw-r--r--tests/testsuite.at5
11 files changed, 423 insertions, 213 deletions
diff --git a/NEWS b/NEWS
index 99d4963..434e82d 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,15 @@ suppressed and gdbm_open will try to force exactly the requested block
size. If unable to do so, it will set the gdbm_errno variable to
GDBM_BLOCK_SIZE_ERROR and return NULL.
+* New gdbm_setopt option: GDBM_GETBLOCKSIZE
+
+Returns the block size in bytes. E.g.
+
+ int size;
+ if (gdbm_setopt (dbf, GDBM_GETBLOCKSIZE, &size, sizeof size))
+ abort ();
+ ...
+
* New functions
** gdbm_last_errno
diff --git a/doc/gdbm.texi b/doc/gdbm.texi
index 8096215..c823ee9 100644
--- a/doc/gdbm.texi
+++ b/doc/gdbm.texi
@@ -1102,6 +1102,10 @@ else
@}
@end example
+@kwindex GDBM_GETBLOCKSIZE
+@item GDBM_GETBLOCKSIZE
+Return the block size in bytes. The @var{value} should point to @code{int}.
+
@end table
The return value will be @samp{-1} upon failure, or @samp{0} upon
diff --git a/src/gdbm.h.in b/src/gdbm.h.in
index 07d3d1f..404d079 100644
--- a/src/gdbm.h.in
+++ b/src/gdbm.h.in
@@ -81,6 +81,7 @@ extern "C" {
# define GDBM_GETCOALESCEBLKS 13 /* Get free block coalesce status */
# define GDBM_GETMAXMAPSIZE 14 /* Get maximum mapped memory size */
# define GDBM_GETDBNAME 15 /* Return database file name */
+# define GDBM_GETBLOCKSIZE 16 /* Return block size */
typedef @GDBM_COUNT_T@ gdbm_count_t;
diff --git a/src/gdbmcount.c b/src/gdbmcount.c
index a301d0c..861a708 100644
--- a/src/gdbmcount.c
+++ b/src/gdbmcount.c
@@ -39,7 +39,8 @@ gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount)
off_t *sdir;
gdbm_count_t count = 0;
int i, last;
-
+ int result;
+
/* Return immediately if the database needs recovery */
GDBM_ASSERT_CONSISTENCY (dbf, -1);
@@ -53,17 +54,21 @@ gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount)
memcpy (sdir, dbf->dir, dbf->header->dir_size);
qsort (sdir, nbuckets, sizeof (off_t), compoff);
+ result = 0;
for (i = last = 0; i < nbuckets; i++)
{
if (i == 0 || sdir[i] != sdir[last])
{
if (_gdbm_read_bucket_at (dbf, sdir[i], &bucket, sizeof bucket))
- return -1;
+ {
+ result = -1;
+ break;
+ }
count += bucket.count;
last = i;
}
}
free (sdir);
*pcount = count;
- return 0;
+ return result;
}
diff --git a/src/gdbmsetopt.c b/src/gdbmsetopt.c
index 39b5e04..f2cf55e 100644
--- a/src/gdbmsetopt.c
+++ b/src/gdbmsetopt.c
@@ -22,8 +22,6 @@
#include "gdbmdefs.h"
-/* operate on an already open descriptor. */
-
static int
getbool (void *optval, int optlen)
{
@@ -50,225 +48,297 @@ get_size (void *optval, int optlen, size_t *ret)
return -1;
return 0;
}
+
+static int
+setopt_gdbm_setcachesize (GDBM_FILE dbf, void *optval, int optlen)
+{
+ size_t sz;
-int
-gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
+ /* Optval will point to the new size of the cache. */
+ if (dbf->bucket_cache != NULL)
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ALREADY_SET, FALSE);
+ return -1;
+ }
+
+ if (get_size (optval, optlen, &sz))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ return _gdbm_init_cache (dbf, (sz > 9) ? sz : 10);
+}
+
+static int
+setopt_gdbm_getcachesize (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (size_t))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ *(size_t*) optval = dbf->cache_size;
+ return 0;
+}
+
+/* Obsolete form of GDBM_SETSYNCMODE. */
+static int
+setopt_gdbm_fastmode (GDBM_FILE dbf, void *optval, int optlen)
+{
+ int n;
+
+ if ((n = getbool (optval, optlen)) == -1)
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ dbf->fast_write = n;
+ return 0;
+}
+
+static int
+setopt_gdbm_setsyncmode (GDBM_FILE dbf, void *optval, int optlen)
+{
+ int n;
+
+ /* Optval will point to either true or false. */
+ if ((n = getbool (optval, optlen)) == -1)
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ dbf->fast_write = !n;
+ return 0;
+}
+
+static int
+setopt_gdbm_getsyncmode (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (int))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ *(int*) optval = !dbf->fast_write;
+ return 0;
+}
+
+/* CENTFREE - set or get the stat of the central block repository */
+static int
+setopt_gdbm_setcentfree (GDBM_FILE dbf, void *optval, int optlen)
{
int n;
- size_t sz;
- /* Return immediately if the database needs recovery */
- GDBM_ASSERT_CONSISTENCY (dbf, -1);
+ /* Optval will point to either true or false. */
+ if ((n = getbool (optval, optlen)) == -1)
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ dbf->central_free = n;
+ return 0;
+}
+
+static int
+setopt_gdbm_getcentfree (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (int))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ *(int*) optval = !dbf->central_free;
+ return 0;
+}
+
+/* Coalesce state: */
+static int
+setopt_gdbm_setcoalesceblks (GDBM_FILE dbf, void *optval, int optlen)
+{
+ int n;
- switch (optflag)
+ /* Optval will point to either true or false. */
+ if ((n = getbool (optval, optlen)) == -1)
{
- /* Cache size: */
-
- case GDBM_SETCACHESIZE:
- /* Optval will point to the new size of the cache. */
- if (dbf->bucket_cache != NULL)
- {
- gdbm_set_errno (dbf, GDBM_OPT_ALREADY_SET, FALSE);
- return -1;
- }
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ dbf->coalesce_blocks = n;
+ return 0;
+}
- if (get_size (optval, optlen, &sz))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- return _gdbm_init_cache (dbf, (sz > 9) ? sz : 10);
+static int
+setopt_gdbm_getcoalesceblks (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (int))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ *(int*) optval = dbf->coalesce_blocks;
+ return 0;
+}
- case GDBM_GETCACHESIZE:
- if (!optval || optlen != sizeof (size_t))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- *(size_t*) optval = dbf->cache_size;
- break;
-
- /* Obsolete form of GDBM_SETSYNCMODE. */
- case GDBM_FASTMODE:
- if ((n = getbool (optval, optlen)) == -1)
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- dbf->fast_write = n;
- break;
-
- /* SYNC mode: */
-
- case GDBM_SETSYNCMODE:
- /* Optval will point to either true or false. */
- if ((n = getbool (optval, optlen)) == -1)
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- dbf->fast_write = !n;
- break;
+#if HAVE_MMAP
+static int
+setopt_gdbm_setmmap (GDBM_FILE dbf, void *optval, int optlen)
+{
+ int n;
+
+ if ((n = getbool (optval, optlen)) == -1)
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ __fsync (dbf);
+ if (n == dbf->memory_mapping)
+ return 0;
+ if (n)
+ {
+ if (_gdbm_mapped_init (dbf) == 0)
+ dbf->memory_mapping = TRUE;
+ else
+ return -1;
+ }
+ else
+ {
+ _gdbm_mapped_unmap (dbf);
+ dbf->memory_mapping = FALSE;
+ }
+ return 0;
+}
- case GDBM_GETSYNCMODE:
- if (!optval || optlen != sizeof (int))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- *(int*) optval = !dbf->fast_write;
- break;
-
- /* CENTFREE - set or get the stat of the central block repository */
- case GDBM_SETCENTFREE:
- /* Optval will point to either true or false. */
- if ((n = getbool (optval, optlen)) == -1)
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- dbf->central_free = n;
- break;
+static int
+setopt_gdbm_getmmap (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (int))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ *(int*) optval = dbf->memory_mapping;
+ return 0;
+}
- case GDBM_GETCENTFREE:
- if (!optval || optlen != sizeof (int))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- *(int*) optval = !dbf->central_free;
- break;
-
- /* Coalesce state: */
- case GDBM_SETCOALESCEBLKS:
- /* Optval will point to either true or false. */
- if ((n = getbool (optval, optlen)) == -1)
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- dbf->coalesce_blocks = n;
- break;
+/* Maximum size of a memory mapped region */
+static int
+setopt_gdbm_setmaxmapsize (GDBM_FILE dbf, void *optval, int optlen)
+{
+ size_t page_size = sysconf (_SC_PAGESIZE);
+ size_t sz;
- case GDBM_GETCOALESCEBLKS:
- if (!optval || optlen != sizeof (int))
- {
- gdbm_set_errno (NULL, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- *(int*) optval = dbf->coalesce_blocks;
- break;
-
- /* Mmap mode */
- case GDBM_SETMMAP:
-#if HAVE_MMAP
- if ((n = getbool (optval, optlen)) == -1)
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- __fsync (dbf);
- if (n == dbf->memory_mapping)
- return 0;
- if (n)
- {
- if (_gdbm_mapped_init (dbf) == 0)
- dbf->memory_mapping = TRUE;
- else
- return -1;
- }
- else
- {
- _gdbm_mapped_unmap (dbf);
- dbf->memory_mapping = FALSE;
- }
-#else
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
+ if (get_size (optval, optlen, &sz))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ dbf->mapped_size_max = ((sz + page_size - 1) / page_size) * page_size;
+ _gdbm_mapped_init (dbf);
+ return 0;
+}
+
+static int
+setopt_gdbm_getmaxmapsize (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (size_t))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ *(size_t*) optval = dbf->mapped_size_max;
+ return 0;
+}
+
+static int
+setopt_gdbm_getflags (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (int))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ else
+ {
+ int flags = dbf->read_write;
+ if (!dbf->fast_write)
+ flags |= GDBM_SYNC;
+ if (!dbf->file_locking)
+ flags |= GDBM_NOLOCK;
+ if (!dbf->memory_mapping)
+ flags |= GDBM_NOMMAP;
+ *(int*) optval = flags;
+ }
+ return 0;
+}
#endif
- break;
-
- case GDBM_GETMMAP:
- if (!optval || optlen != sizeof (int))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- *(int*) optval = dbf->memory_mapping;
- break;
-
- /* Maximum size of a memory mapped region */
- case GDBM_SETMAXMAPSIZE:
-#if HAVE_MMAP
- {
- size_t page_size = sysconf (_SC_PAGESIZE);
- if (get_size (optval, optlen, &sz))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- dbf->mapped_size_max = ((sz + page_size - 1) / page_size) *
- page_size;
- _gdbm_mapped_init (dbf);
- break;
+static int
+setopt_gdbm_getdbname (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (!optval || optlen != sizeof (char*))
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+ }
+ else
+ {
+ char *p = strdup (dbf->name);
+ if (!p)
+ {
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, FALSE);
+ return -1;
}
-#else
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
-#endif
-
- case GDBM_GETMAXMAPSIZE:
- if (!optval || optlen != sizeof (size_t))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- *(size_t*) optval = dbf->mapped_size_max;
- break;
-
- /* Flags */
- case GDBM_GETFLAGS:
- if (!optval || optlen != sizeof (int))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- else
- {
- int flags = dbf->read_write;
- if (!dbf->fast_write)
- flags |= GDBM_SYNC;
- if (!dbf->file_locking)
- flags |= GDBM_NOLOCK;
- if (!dbf->memory_mapping)
- flags |= GDBM_NOMMAP;
- *(int*) optval = flags;
- }
- break;
-
- case GDBM_GETDBNAME:
- if (!optval || optlen != sizeof (char*))
- {
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
- }
- else
- {
- char *p = strdup (dbf->name);
- if (!p)
- {
- gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, FALSE);
- return -1;
- }
- *(char**) optval = p;
- }
- break;
-
- default:
- gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
- return -1;
+ *(char**) optval = p;
}
-
return 0;
}
+
+static int
+setopt_gdbm_getblocksize (GDBM_FILE dbf, void *optval, int optlen)
+{
+ if (optval && optlen == sizeof (int))
+ {
+ *(int*) optval = dbf->header->block_size;
+ return 0;
+ }
+
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+}
+
+typedef int (*setopt_handler) (GDBM_FILE, void *, int);
+
+static setopt_handler setopt_handler_tab[] = {
+ [GDBM_SETCACHESIZE] = setopt_gdbm_setcachesize,
+ [GDBM_GETCACHESIZE] = setopt_gdbm_getcachesize,
+ [GDBM_FASTMODE] = setopt_gdbm_fastmode,
+ [GDBM_SETSYNCMODE] = setopt_gdbm_setsyncmode,
+ [GDBM_GETSYNCMODE] = setopt_gdbm_getsyncmode,
+ [GDBM_SETCENTFREE] = setopt_gdbm_setcentfree,
+ [GDBM_GETCENTFREE] = setopt_gdbm_getcentfree,
+ [GDBM_SETCOALESCEBLKS] = setopt_gdbm_setcoalesceblks,
+ [GDBM_GETCOALESCEBLKS] = setopt_gdbm_getcoalesceblks,
+#if HAVE_MMAP
+ [GDBM_SETMMAP] = setopt_gdbm_setmmap,
+ [GDBM_GETMMAP] = setopt_gdbm_getmmap,
+ [GDBM_SETMAXMAPSIZE] = setopt_gdbm_setmaxmapsize,
+ [GDBM_GETMAXMAPSIZE] = setopt_gdbm_getmaxmapsize,
+ [GDBM_GETFLAGS] = setopt_gdbm_getflags,
+#endif
+ [GDBM_GETDBNAME] = setopt_gdbm_getdbname,
+ [GDBM_GETBLOCKSIZE] = setopt_gdbm_getblocksize,
+};
+
+int
+gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
+{
+ /* Return immediately if the database needs recovery */
+ GDBM_ASSERT_CONSISTENCY (dbf, -1);
+
+ if (optflag >= 0
+ && optflag < sizeof (setopt_handler_tab) / sizeof (setopt_handler_tab[0]))
+ return setopt_handler_tab[optflag] (dbf, optval, optlen);
+
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, FALSE);
+ return -1;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 42335e8..f706213 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,9 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac $(srcdir)/Makefile.am
TESTSUITE_AT = \
testsuite.at\
+ blocksize00.at\
+ blocksize01.at\
+ blocksize02.at\
cloexec00.at\
cloexec01.at\
cloexec02.at\
diff --git a/tests/blocksize00.at b/tests/blocksize00.at
new file mode 100644
index 0000000..a8ceab4
--- /dev/null
+++ b/tests/blocksize00.at
@@ -0,0 +1,36 @@
+# This file is part of GDBM test suite.
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([block size adjustment])
+AT_KEYWORDS([gdbm create blocksize blocksize00])
+
+AT_CHECK([
+AT_SORT_PREREQ
+num2word 1:1000 > input
+gtload -blocksize=518 -clear -verbose test.db < input
+gtdump test.db | sort -k1n,2n > output
+cmp -s input output || diff -u input output
+
+gtload -blocksize=1025 -clear -verbose test.db < input
+gtdump test.db | sort -k1n,2n > output
+cmp -s input output || diff -u input output
+],
+[0],
+[blocksize=1024
+blocksize=2048
+])
+
+AT_CLEANUP
diff --git a/tests/blocksize01.at b/tests/blocksize01.at
new file mode 100644
index 0000000..444ae8c
--- /dev/null
+++ b/tests/blocksize01.at
@@ -0,0 +1,32 @@
+# This file is part of GDBM test suite.
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([exact blocksize])
+AT_KEYWORDS([gdbm create blocksize blocksize01])
+
+AT_CHECK([
+AT_SORT_PREREQ
+num2word 1:1000 > input
+gtload -blocksize=1024 -bsexact -clear -verbose test.db < input
+gtdump test.db | sort -k1n,2n > output
+cmp -s input output || diff -u input output
+],
+[0],
+[blocksize=1024
+])
+
+AT_CLEANUP
+
diff --git a/tests/blocksize02.at b/tests/blocksize02.at
new file mode 100644
index 0000000..7e0d7af
--- /dev/null
+++ b/tests/blocksize02.at
@@ -0,0 +1,28 @@
+# This file is part of GDBM test suite.
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([incorrect blocksize])
+AT_KEYWORDS([gdbm create blocksize blocksize02])
+
+AT_CHECK([
+gtload -blocksize=1025 -bsexact -clear -verbose test.db < /dev/null
+],
+[1],
+[],
+[gdbm_open failed: Block size error
+])
+
+AT_CLEANUP
diff --git a/tests/gtload.c b/tests/gtload.c
index 2920463..60e8504 100644
--- a/tests/gtload.c
+++ b/tests/gtload.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM test suite.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2016 Free Software Foundation, Inc.
GDBM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -39,6 +39,8 @@ main (int argc, char **argv)
int delim = '\t';
int data_z = 0;
size_t mapped_size_max = 0;
+ int blksize;
+ int verbose = 0;
while (--argc)
{
@@ -46,7 +48,7 @@ main (int argc, char **argv)
if (strcmp (arg, "-h") == 0)
{
- printf ("usage: %s [-replace] [-clear] [-blocksize=N] [-null] [-nolock] [-nommap] [-maxmap=N] [-sync] [-delim=CHR] DBFILE\n", progname);
+ printf ("usage: %s [-replace] [-clear] [-blocksize=N] [-bsexact] [-verbose] [-null] [-nolock] [-nommap] [-maxmap=N] [-sync] [-delim=CHR] DBFILE\n", progname);
exit (0);
}
else if (strcmp (arg, "-replace") == 0)
@@ -61,6 +63,10 @@ main (int argc, char **argv)
flags |= GDBM_NOMMAP;
else if (strcmp (arg, "-sync") == 0)
flags |= GDBM_SYNC;
+ else if (strcmp (arg, "-bsexact") == 0)
+ flags |= GDBM_BSEXACT;
+ else if (strcmp (arg, "-verbose") == 0)
+ verbose = 1;
else if (strncmp (arg, "-blocksize=", 11) == 0)
block_size = atoi (arg + 11);
else if (strncmp (arg, "-maxmap=", 8) == 0)
@@ -119,11 +125,22 @@ main (int argc, char **argv)
if (gdbm_setopt (dbf, GDBM_SETMAXMAPSIZE, &mapped_size_max,
sizeof (mapped_size_max)))
{
- fprintf (stderr, "gdbm_setopt failed: %s\n",
+ fprintf (stderr, "GDBM_SETMAXMAPSIZE failed: %s\n",
gdbm_strerror (gdbm_errno));
exit (1);
}
}
+
+ if (verbose)
+ {
+ if (gdbm_setopt (dbf, GDBM_GETBLOCKSIZE, &blksize, sizeof blksize))
+ {
+ fprintf (stderr, "GDBM_GETBLOCKSIZE failed: %s\n",
+ gdbm_strerror (gdbm_errno));
+ exit (1);
+ }
+ printf ("blocksize=%d\n", blksize);
+ }
while (fgets (buf, sizeof buf, stdin))
{
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 1e7373c..822d172 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -43,6 +43,11 @@ m4_include([delete00.at])
m4_include([delete01.at])
m4_include([delete02.at])
+AT_BANNER([Block size selection])
+m4_include([blocksize00.at])
+m4_include([blocksize01.at])
+m4_include([blocksize02.at])
+
AT_BANNER([Compatibility library (dbm/ndbm)])
m4_include([dbmcreate00.at])

Return to:

Send suggestions and report system problems to the System administrator.