aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-12-25 09:31:59 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2013-12-25 09:31:59 +0000
commit46e182da4c8a338db22199e003fc2149ee3b1b81 (patch)
treea7b382936a61ced77d284a6092d450c73e124e73
parent05fa76dfce5311161abbc64c12acbaf56f298e97 (diff)
downloadgdbm-46e182da4c8a338db22199e003fc2149ee3b1b81.tar.gz
gdbm-46e182da4c8a338db22199e003fc2149ee3b1b81.tar.bz2
Minor changes.
* src/gdbm_load.c: New options: --mmap, --cache-size and --block-size. * doc/gdbm.texinfo: Document new gdbm_load options. * doc/gdbm_load.1: Likewise. * src/gdbmdelete.c: Stylistic changes. * src/gdbmstore.c: Likewise.
-rw-r--r--ChangeLog13
-rw-r--r--doc/gdbm.texinfo29
-rw-r--r--doc/gdbm_load.118
-rw-r--r--src/gdbm_load.c47
-rw-r--r--src/gdbmdelete.c2
-rw-r--r--src/gdbmstore.c11
6 files changed, 100 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index b733844..f9b8183 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2013-12-25 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Minor changes.
+
+ * src/gdbm_load.c: New options: --mmap, --cache-size and
+ --block-size.
+
+ * doc/gdbm.texinfo: Document new gdbm_load options.
+ * doc/gdbm_load.1: Likewise.
+
+ * src/gdbmdelete.c: Stylistic changes.
+ * src/gdbmstore.c: Likewise.
+
2013-05-21 Sergey Poznyakoff <gray@gnu.org.ua>
New function gdbm_count.
diff --git a/doc/gdbm.texinfo b/doc/gdbm.texinfo
index 5c962d5..201f01c 100644
--- a/doc/gdbm.texinfo
+++ b/doc/gdbm.texinfo
@@ -1895,15 +1895,15 @@ be set in a startup script file (@pxref{startup files}).
@anchor{open parameters}
The following variables control how the database is opened:
+@deftypevr {gdbmtool variable} numeric blocksize
+Sets the block size. @xref{Open, block_size}. Unset by default.
+@end deftypevr
+
@deftypevr {gdbmtool variable} numeric cachesize
Sets the cache size. @xref{Options, GDBM_SETCACHESIZE}.
By default this variable is not set.
@end deftypevr
-@deftypevr {gdbmtool variable} numeric blocksize
-Sets the block size. @xref{Open, block_size}. Unset by default.
-@end deftypevr
-
@anchor{openvar}
@deftypevr {gdbmtool variable} string open
Open mode. The following values are allowed:
@@ -2370,7 +2370,7 @@ By default the utility creates dumps in ASCII format (@pxref{Flat
files,ASCII}). Another format can be requested using the
@option{--format} (@option{-H}) option.
-The @command{gdbm_load} utility understands the following command line
+The @command{gdbm_dump} utility understands the following command line
options:
@table @option
@@ -2405,18 +2405,31 @@ The format of the input file is detected automatically.
By default the utility attempts to restore the database under its
original name, as stored in the input file. It will fail to do so if
the input is in binary format. In that case, the name of the database
-to create can be given as the second argument.
+must be given as the second argument.
-In general, if two arguments are given, the second one is treated as
+In general, if two arguments are given the second one is treated as
the name of the database to create, overriding the file name specified
in the flat file.
The utility understands the following command line arguments:
@table @option
+
+@item -b @var{num}
+@itemx --block-size=@var{num}
+Sets block size. @xref{Open, block_size}.
+
+@item -c @var{num}
+@itemx --cache-size=@var{num}
+Sets cache size. @xref{Options, GDBM_SETCACHESIZE}.
+
+@item -M
+@itemx --mmap
+Use memory mapping.
+
@item -m @var{mode}
@item --mode=@var{mode}
-Set file mode. The argument is the desired file mode in octal.
+Sets the file mode. The argument is the desired file mode in octal.
@item -n
@itemx --no-meta
diff --git a/doc/gdbm_load.1 b/doc/gdbm_load.1
index 00aaac0..8b0e77c 100644
--- a/doc/gdbm_load.1
+++ b/doc/gdbm_load.1
@@ -1,4 +1,4 @@
-.\" This file is part of GDBM.
+.\" This file is part of GDBM. -*- nroff -*-
.\" Copyright (C) 2011, 2013 Free Software Foundation, Inc.
.\"
.\" GDBM is free software; you can redistribute it and/or modify
@@ -13,12 +13,15 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
-.TH GDBM_LOAD 1 "May 8, 2013" "GDBM" "GDBM User Reference"
+.TH GDBM_LOAD 1 "December 25, 2013" "GDBM" "GDBM User Reference"
.SH NAME
gdbm_load \- re-create a GDBM database from a dump file.
.SH SYNOPSIS
-\fBgdbm_load\fR [\fB\-nr\fR] [\fB\-m\fR \fIMODE\fR]\
+\fBgdbm_load\fR [\fB\-Mnr\fR] [\fB\-b\fR \fINUM\fR] [\fB\-c\fR \fINUM]\
+ [\fB\-m\fR \fIMODE\fR]\
[\fB\-u\fR \fINAME\fR|\fIUID\fR[:\fINAME\fR|\fIGID\fR]]
+ [\fB\-\-block\-size\fR=\fINUM\fR] [\fB\-\-cache\-size\fR=\fINUM\fR]\
+ [\fB\-\-mmap\fR=\fINUM\fR]
[\fB\-\-mode\fR=\fIMODE\fR]\
[\fB\-\-no\-meta\fR] [\fB\-\-replace\fR]
[\fB\-\-user\fR=\fINAME\fR|\fIUID\fR[:\fINAME\fR|\fIGID\fR]]\
@@ -42,6 +45,15 @@ the created database are restored from the information in the dump.
This can be overridden using the command line options (see below).
.SH OPTIONS
.TP
+\fB\-b\fR, \fB\-\-block\-size\fR=\fINUM\fR
+Sets block size.
+.TP
+\fB\-c\fR, \fB\-\-cache\-size\fR=\fINUM\fR
+Sets cache size.
+.TP
+\fB\-M\fR, \fB\-\-mmap\fR
+Use memory mapping.
+.TP
\fB\-m\fR, \fB\-\-mode\fR=\fIMODE\fR
Set database file mode (octal number).
.TP
diff --git a/src/gdbm_load.c b/src/gdbm_load.c
index 7746b1b..20942dc 100644
--- a/src/gdbm_load.c
+++ b/src/gdbm_load.c
@@ -36,6 +36,9 @@ struct gdbm_option optab[] = {
{ 'm', "mode", N_("MODE"), N_("set file mode") },
{ 'u', "user", N_("NAME|UID[:NAME|GID]"), N_("set file owner") },
{ 'n', "no-meta", NULL, N_("do not attempt to set file meta-data") },
+ { 'M', "mmap", NULL, N_("use memory mapping") },
+ { 'c', "cache-size", N_("NUM"), N_("set the cache size") },
+ { 'b', "block-size", N_("NUM"), N_("set the block size") },
{ 0 }
};
@@ -63,6 +66,27 @@ set_meta_info (GDBM_FILE dbf)
return 0;
}
+static int
+get_int (const char *arg)
+{
+ char *p;
+ long n;
+
+ errno = 0;
+ n = strtol (arg, &p, 0);
+ if (*p)
+ {
+ error (_("invalid number: %s"), arg);
+ exit (EXIT_USAGE);
+ }
+ if (errno)
+ {
+ error (_("invalid number: %s: %s"), arg, strerror (errno));
+ exit (EXIT_USAGE);
+ }
+ return n;
+}
+
int
main (int argc, char **argv)
{
@@ -72,6 +96,9 @@ main (int argc, char **argv)
FILE *fp;
unsigned long err_line, n;
char *end;
+ int oflags = GDBM_NEWDB|GDBM_NOMMAP;
+ int cache_size = 0;
+ int block_size = 0;
#ifdef HAVE_SETLOCALE
setlocale (LC_ALL, "");
@@ -87,6 +114,14 @@ main (int argc, char **argv)
{
switch (opt)
{
+ case 'b':
+ block_size = get_int (optarg);
+ break;
+
+ case 'c':
+ cache_size = get_int (optarg);
+ break;
+
case 'm':
{
errno = 0;
@@ -171,6 +206,10 @@ main (int argc, char **argv)
case 'n':
no_meta_option = 1;
break;
+
+ case 'M':
+ oflags &= ~GDBM_NOMMAP;
+ break;
default:
error (_("unknown option"));
@@ -216,12 +255,16 @@ main (int argc, char **argv)
if (dbname)
{
- dbf = gdbm_open (dbname, 0, GDBM_NEWDB, 0600, NULL);
+ dbf = gdbm_open (dbname, block_size, oflags, 0600, NULL);
if (!dbf)
{
gdbm_perror (_("gdbm_open failed"));
exit (EXIT_FATAL);
}
+
+ if (cache_size &&
+ gdbm_setopt (dbf, GDBM_SETCACHESIZE, &cache_size, sizeof (int)) == -1)
+ error (_("gdbm_setopt failed: %s"), gdbm_strerror (gdbm_errno));
}
rc = gdbm_load_from_file (&dbf, fp, replace,
@@ -248,7 +291,7 @@ main (int argc, char **argv)
rc = EXIT_FATAL;
}
}
-
+
if (dbf)
{
if (!no_meta_option && set_meta_info (dbf))
diff --git a/src/gdbmdelete.c b/src/gdbmdelete.c
index 331a286..3f888be 100644
--- a/src/gdbmdelete.c
+++ b/src/gdbmdelete.c
@@ -61,7 +61,7 @@ gdbm_delete (GDBM_FILE dbf, datum key)
/* Delete the element. */
dbf->bucket->h_table[elem_loc].hash_value = -1;
- dbf->bucket->count -= 1;
+ dbf->bucket->count--;
/* Move other elements to guarantee that they can be found. */
last_loc = elem_loc;
diff --git a/src/gdbmstore.c b/src/gdbmstore.c
index aedf375..15a2255 100644
--- a/src/gdbmstore.c
+++ b/src/gdbmstore.c
@@ -104,9 +104,7 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
/* Get the file address for the new space.
(Current bucket's free space is first place to look.) */
if (file_adr == 0)
- {
- file_adr = _gdbm_alloc (dbf, new_size);
- }
+ file_adr = _gdbm_alloc (dbf, new_size);
/* If this is a new entry in the bucket, we need to do special things. */
if (elem_loc == -1)
@@ -120,10 +118,10 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
/* Find space to insert into bucket and set elem_loc to that place. */
elem_loc = new_hash_val % dbf->header->bucket_elems;
while (dbf->bucket->h_table[elem_loc].hash_value != -1)
- { elem_loc = (elem_loc + 1) % dbf->header->bucket_elems; }
+ elem_loc = (elem_loc + 1) % dbf->header->bucket_elems;
/* We now have another element in the bucket. Add the new information.*/
- dbf->bucket->count += 1;
+ dbf->bucket->count++;
dbf->bucket->h_table[elem_loc].hash_value = new_hash_val;
memcpy (dbf->bucket->h_table[elem_loc].key_start, key.dptr,
(SMALL < key.dsize ? SMALL : key.dsize));
@@ -137,7 +135,8 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
/* Write the data to the file. */
file_pos = __lseek (dbf, file_adr, SEEK_SET);
- if (file_pos != file_adr) _gdbm_fatal (dbf, _("lseek error"));
+ if (file_pos != file_adr)
+ _gdbm_fatal (dbf, _("lseek error"));
rc = _gdbm_full_write (dbf, key.dptr, key.dsize);
if (rc)
_gdbm_fatal (dbf, gdbm_strerror (rc));

Return to:

Send suggestions and report system problems to the System administrator.