📄 gdbm.html
字号:
<div class="node">
<p><hr>
Node: <a name="Options">Options</a>,
Next: <a rel="next" accesskey="n" href="#Locking">Locking</a>,
Previous: <a rel="previous" accesskey="p" href="#Errors">Errors</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>
<h2 class="chapter">13 Seting options.</h2>
<p><code>Gdbm</code> supports the ability to set certain options on an already
open database.
<pre class="example"> ret = gdbm_setopt(dbf, option, value, size);
</pre>
<p>The parameters are:
<dl>
<dt>GDBM_FILE dbf
<dd>The pointer returned by <code>gdbm_open</code>.
<br><dt>int option
<dd>The option to be set.
<br><dt>int *value
<dd>A pointer to the value to which <code>option</code> will be set.
<br><dt>int size
<dd>The length of the data pointed to by <code>value</code>.
</dl>
<p>The valid options are:
<p>GDBM_CACHESIZE - Set the size of the internal bucket cache. This
option may only be set once on each GDBM_FILE descriptor, and
is set automatically to 100 upon the first access to the database.
<p>GDBM_FASTMODE - Set fast mode to either on or off. This allows
fast mode to be toggled on an already open and active database.
value (see below) should be set to either TRUE or FALSE.
<em>This option is now obsolete.</em>
<p>GDBM_SYNCMODE - Turn on or off file system synchronization operations. This
setting defaults to off; value (see below) should be set to either TRUE or
FALSE.
<p>GDBM_CENTFREE - Set central free block pool to either on or off.
The default is off, which is how previous versions of <code>Gdbm</code>
handled free blocks. If set, this option causes all subsequent free
blocks to be placed in the <em>global</em> pool, allowing (in theory)
more file space to be reused more quickly. value (see below) should
be set to either TRUE or FALSE.
<em>NOTICE: This feature is still under study.</em>
<p>GDBM_COALESCEBLKS - Set free block merging to either on or off.
The default is off, which is how previous versions of <code>Gdbm</code>
handled free blocks. If set, this option causes adjacent free blocks
to be merged. This can become a CPU expensive process with time, though,
especially if used in conjunction with GDBM_CENTFREE. value (see below)
should be set to either TRUE or FALSE.
<em>NOTICE: This feature is still under study.</em>
<p>The return value will be -1 upon failure, or 0 upon success. The global
variable <code>gdbm_errno</code> will be set upon failure.
<p>For instance, to set a database to use a cache of 10, after opening it
with <code>gdbm_open</code>, but prior to accessing it in any way, the following
code could be used:
<pre class="example"> int value = 10;
ret = gdbm_setopt(dbf, GDBM_CACHESIZE, &value, sizeof(int));
</pre>
<div class="node">
<p><hr>
Node: <a name="Locking">Locking</a>,
Next: <a rel="next" accesskey="n" href="#Variables">Variables</a>,
Previous: <a rel="previous" accesskey="p" href="#Options">Options</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>
<h2 class="chapter">14 File Locking.</h2>
<p>With locking disabled (if <code>gdbm_open</code> was called with GDBM_NOLOCK),
the user may want to perform their own file locking on the database file
in order to prevent multiple writers operating on the same file
simultaneously.
<p>In order to support this, the <code>gdbm_fdesc</code> routine is provided.
<pre class="example"> ret = gdbm_fdesc(dbf);
</pre>
<p>The single valid parameter is:
<dl>
<dt>GDBM_FILE dbf
<dd>The pointer returned by <code>gdbm_open</code>.
</dl>
<p>The return value will be the file descriptor of the database.
<div class="node">
<p><hr>
Node: <a name="Variables">Variables</a>,
Next: <a rel="next" accesskey="n" href="#Compatibility">Compatibility</a>,
Previous: <a rel="previous" accesskey="p" href="#Locking">Locking</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>
<h2 class="chapter">15 Two useful variables.</h2>
<p>The following two variables are variables that may need to be used:
<dl>
<dt>gdbm_error gdbm_errno
<dd>The variable that contains more information about <code>gdbm</code> errors
(<code>gdbm.h</code> has the definitions of the error values).
<br><dt>char * gdbm_version
<dd>The string containing the version information.
</dl>
<div class="node">
<p><hr>
Node: <a name="Compatibility">Compatibility</a>,
Next: <a rel="next" accesskey="n" href="#Conversion">Conversion</a>,
Previous: <a rel="previous" accesskey="p" href="#Variables">Variables</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>
<h2 class="chapter">16 Compatibility with standard <code>dbm</code> and <code>ndbm</code>.</h2>
<p>GNU <code>dbm</code> files are not <code>sparse</code>. You can copy them with the UNIX
<code>cp</code> command and they will not expand in the copying process.
<p>There is a compatibility mode for use with programs that already use UNIX
<code>dbm</code> and UNIX <code>ndbm</code>.
<p>GNU <code>dbm</code> has compatibility functions for <code>dbm</code>. For <code>dbm</code>
compatibility functions, you need the include file <code>dbm.h</code>.
<p>In this compatibility mode, no <code>gdbm</code> file pointer is required
by the user, and Only one file may be opened at a time. All users in
compatibility mode are assumed to be writers. If the <code>gdbm</code> file is a
read only, it will fail as a writer, but will also try to open it as a reader.
All returned pointers in datum structures point to data that <code>gdbm</code> WILL
free. They should be treated as static pointers (as standard UNIX <code>dbm</code>
does). The compatibility function names are the same as the UNIX <code>dbm</code>
function names. Their definitions follow:
<pre class="example"> int dbminit(name);
int store(key, content);
datum fetch(key);
int delete(key);
datum firstkey();
datum nextkey(key);
int dbmclose();
</pre>
<p>Standard UNIX <code>dbm</code> and GNU <code>dbm</code> do not have the same data
format in the file. You cannot access a standard UNIX <code>dbm</code> file with GNU
<code>dbm</code>! If you want to use an old database with GNU <code>dbm</code>, you must
use the <code>conv2gdbm</code> program.
<p>Also, GNU <code>dbm</code> has compatibility functions for <code>ndbm</code>. For
<code>ndbm</code> compatibility functions, you need the include file <code>ndbm.h</code>.
<p>Again, just like <code>ndbm</code>, any returned datum can be assumed to be static
storage. You do not have to free that memory, the <code>ndbm</code> compatibility
functions will do it for you.
<p>The functions are:
<pre class="example"> DBM *dbm_open(name, flags, mode);
void dbm_close(file);
datum dbm_fetch(file, key);
int dbm_store(file, key, <code>content</code>, flags);
int dbm_delete(file, key);
datum dbm_firstkey(file);
datum dbm_nextkey(file);
int dbm_error(file);
int dbm_clearerr(file);
int dbm_dirfno(file);
int dbm_pagfno(file);
int dbm_rdonly(file);
</pre>
<p>If you want to compile an old C program that used UNIX <code>dbm</code> or <code>ndbm</code>
and want to use <code>gdbm</code> files, execute the following <code>cc</code> command:
<pre class="example"> cc ... -L/usr/local/lib -lgdbm -lgdbm_compat
</pre>
<div class="node">
<p><hr>
Node: <a name="Conversion">Conversion</a>,
Next: <a rel="next" accesskey="n" href="#Bugs">Bugs</a>,
Previous: <a rel="previous" accesskey="p" href="#Compatibility">Compatibility</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>
<h2 class="chapter">17 Converting <code>dbm</code> files to <code>gdbm</code> format.</h2>
<p>The program <code>conv2gdbm</code> has been provided to help you convert from <code>dbm</code>
databases to <code>gdbm</code>. The usage is:
<pre class="example"> conv2gdbm [-q] [-b block_size] dbm_file [gdbm_file]
</pre>
<p>The options are:
<dl>
<dt>-q
<dd>Causes <code>conv2gdbm</code> to work quietly.
<br><dt>block_size
<dd>Is the same as in <code>gdbm_open</code>.
<br><dt>dbm_file
<dd>Is the name of the <code>dbm</code> file without the <code>.pag</code> or <code>.dir</code>
extensions.
<br><dt>gdbm_file
<dd>Is the complete file name. If not included, the <code>gdbm</code> file name is the
same as the <code>dbm</code> file name without any extensions. That is
<code>conv2gdbm</code> <code>dbmfile</code> converts the files <code>dbmfile.pag</code> and
<code>dbmfile.dir</code> into a <code>gdbm</code> file called <code>dbmfile</code>.
</dl>
<div class="node">
<p><hr>
Node: <a name="Bugs">Bugs</a>,
Previous: <a rel="previous" accesskey="p" href="#Conversion">Conversion</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>
<h2 class="chapter">18 Problems and bugs.</h2>
<p>If you have problems with GNU <code>dbm</code> or think you've found a bug,
please report it. Before reporting a bug, make sure you've actually
found a real bug. Carefully reread the documentation and see if it
really says you can do what you're trying to do. If it's not clear
whether you should be able to do something or not, report that too; it's
a bug in the documentation!
<p>Before reporting a bug or trying to fix it yourself, try to isolate it
to the smallest possible input file that reproduces the problem. Then
send us the input file and the exact results <code>gdbm</code> gave you. Also
say what you expected to occur; this will help us decide whether the
problem was really in the documentation.
<p>Once you've got a precise problem, send e-mail to:
<pre class="example"> Internet: <code>bug-gnu-utils@prep.ai.mit.edu</code>.
UUCP: <code>mit-eddie!prep.ai.mit.edu!bug-gnu-utils</code>.
</pre>
<p>Please include the version number of GNU <code>dbm</code> you are using. You can get
this information by printing the variable <code>gdbm_version</code> (see Variables).
<p>Non-bug suggestions are always welcome as well. If you have questions
about things that are unclear in the documentation or are just obscure
features, please report them too.
<p>You may contact the author by:
<pre class="example"> e-mail: phil@cs.wwu.edu
us-mail: Philip A. Nelson
Computer Science Department
Western Washington University
Bellingham, WA 98226
</pre>
<p>You may contact the current maintainer by:
<pre class="example"> e-mail: downsj@downsj.com
</pre>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -