~ubuntu-branches/ubuntu/natty/gdbm/natty

« back to all changes in this revision

Viewing changes to gdbm.texinfo

  • Committer: Bazaar Package Importer
  • Author(s): James Troup
  • Date: 2000-12-30 01:07:10 UTC
  • Revision ID: james.westby@ubuntu.com-20001230010710-x13c8n0wop4zneh5
Tags: upstream-1.7.3
ImportĀ upstreamĀ versionĀ 1.7.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\input texinfo  @c -*- Texinfo -*-
 
2
@comment %**start of header (This is for running Texinfo on a region.)
 
3
@setfilename gdbm.info
 
4
@settitle gdbm
 
5
@c @setchapternewpage odd
 
6
@comment %**end of header (This is for running Texinfo on a region.)
 
7
 
 
8
@iftex
 
9
@finalout
 
10
@end iftex
 
11
 
 
12
@ifinfo
 
13
This file documents the GNU dbm utility.
 
14
 
 
15
Copyright (C) 1989-1993 Free Software Foundation, Inc.
 
16
 
 
17
Permission is granted to make and distribute verbatim copies of
 
18
this manual provided the copyright notice and this permission notice
 
19
are preserved on all copies.
 
20
 
 
21
@ignore
 
22
Permission is granted to process this file through Tex and print the
 
23
results, provided the printed document carries copying permission
 
24
notice identical to this one except for the removal of this paragraph
 
25
(this paragraph not being relevant to the printed manual).
 
26
 
 
27
@end ignore
 
28
Permission is granted to copy and distribute modified versions of this
 
29
manual under the conditions for verbatim copying, provided also that
 
30
the entire resulting derived work is distributed under the terms of a
 
31
permission notice identical to this one.
 
32
 
 
33
Permission is granted to copy and distribute translations of this manual
 
34
into another language, under the above conditions for modified versions.
 
35
@end ifinfo
 
36
 
 
37
@titlepage
 
38
@null
 
39
@sp 6
 
40
@center @titlefont{GNU dbm}
 
41
@sp 2
 
42
@center A Database Manager
 
43
@sp 2
 
44
@center by Philip A. Nelson
 
45
@sp 4
 
46
@center Manual by Pierre Gaumond and Philip A. Nelson 
 
47
@center Updated by Jason Downs
 
48
@sp 1
 
49
@center Edition 1.4.1
 
50
@sp 1
 
51
@center for GNU @code{dbm}, Version 1.7.3.
 
52
@page
 
53
@null
 
54
@vskip 0pt plus 1filll
 
55
Copyright @copyright{} 1993-94 Free Software Foundation, Inc.
 
56
@sp 2
 
57
 
 
58
This is Edition 1.4.1 of the @cite{GNU @code{dbm} Manual}, for @code{gdbm}
 
59
Version 1.7.3. @*
 
60
Last updated May 19, 1994
 
61
 
 
62
Published by the Free Software Foundation @*
 
63
675 Massachusetts Avenue, @*
 
64
Cambridge, MA 02139 USA @*
 
65
 
 
66
Permission is granted to make and distribute verbatim copies of
 
67
this manual provided the copyright notice and this permission notice
 
68
are preserved on all copies.
 
69
 
 
70
Permission is granted to copy and distribute modified versions of this
 
71
manual under the conditions for verbatim copying, provided also that
 
72
the entire resulting derived work is distributed under the terms of a
 
73
permission notice identical to this one.
 
74
 
 
75
Permission is granted to copy and distribute translations of this manual
 
76
into another language, under the above conditions for modified versions,
 
77
except that this permission notice may be stated in a translation approved
 
78
by the Free Software Foundation.
 
79
@end titlepage
 
80
@page
 
81
 
 
82
@node Top, Copying, (dir), (dir)
 
83
@ifinfo
 
84
GNU @code{dbm} is a library of functions implementing a hashed database
 
85
on a disk file.  This manual documents GNU @code{dbm} Version 1.7.1
 
86
(@code{gdbm}).  The software was written by Philip A. Nelson. This
 
87
document was originally written by Pierre Gaumond from texts written by
 
88
Phil.
 
89
@end ifinfo
 
90
 
 
91
 
 
92
@menu
 
93
Introduction:
 
94
 
 
95
* Copying::                    Your rights.
 
96
* Intro::                      Introduction to GNU dbm.
 
97
* List::                       List of functions.
 
98
 
 
99
Functions:
 
100
 
 
101
* Open::                       Opening the database.
 
102
* Close::                      Closing the database.
 
103
* Store::                      Inserting and replacing records in the database.
 
104
* Fetch::                      Searching records in the database.
 
105
* Delete::                     Removing records from the database.
 
106
* Sequential::                 Sequential access to records.
 
107
* Reorganization::             Database reorganization.
 
108
* Sync::                       Insure all writes to disk have competed.
 
109
* Errors::                     Convert internal error codes into English.
 
110
* Options::                    Setting internal options.
 
111
 
 
112
Other topics:
 
113
 
 
114
* Variables::                  Two useful variables.
 
115
* Compatibility::              Compatibility with UNIX dbm and ndbm.
 
116
* Conversion::                 Converting dbm files to gdbm format.
 
117
* Bugs::                       Problems and bugs.
 
118
@end menu
 
119
 
 
120
@node Copying, Intro, Top, Top
 
121
@chapter Copying Conditions.
 
122
This library is @dfn{free}; this means that everyone is free to use
 
123
it and free to redistribute it on a free basis.  GNU @code{dbm} (@code{gdbm})
 
124
is not in the public domain; it is copyrighted and there
 
125
are restrictions on its distribution, but these restrictions are
 
126
designed to permit everything that a good cooperating citizen would want
 
127
to do.  What is not allowed is to try to prevent others from further
 
128
sharing any version of @code{gdbm} that they might get from
 
129
you.@refill
 
130
 
 
131
  Specifically, we want to make sure that you have the right to give
 
132
away copies @code{gdbm}, that you receive
 
133
source code or else can get it if you want it, that you can change these
 
134
functions or use pieces of them in new free programs, and that you know
 
135
you can do these things.@refill
 
136
 
 
137
  To make sure that everyone has such rights, we have to forbid you to
 
138
deprive anyone else of these rights.  For example, if you distribute
 
139
copies @code{gdbm}, you must give the recipients all
 
140
the rights that you have.  You must make sure that they, too, receive or
 
141
can get the source code.  And you must tell them their rights.@refill
 
142
 
 
143
  Also, for our own protection, we must make certain that everyone finds
 
144
out that there is no warranty for anything in the @code{gdbm} distribution.
 
145
If these functions are modified by someone else and passed on, we want
 
146
their recipients to know that what they have is not what we distributed,
 
147
so that any problems introduced by others will not reflect on our
 
148
reputation.@refill
 
149
 
 
150
@code{gdbm} is currently distributed under the terms of the GNU General
 
151
Public License, Version 2.  (@emph{NOT} under the GNU General Library
 
152
Public License.)  A copy the GNU General Public License is included with
 
153
the distribution of @code{gdbm}.
 
154
 
 
155
@node Intro, List, Copying, Top
 
156
@chapter Introduction to GNU @code{dbm}.
 
157
 
 
158
GNU @code{dbm} (@code{gdbm})is a library of database functions that use
 
159
extendible hashing and works similar to the standard UNIX @code{dbm}
 
160
functions.  These routines are provided to a programmer needing to
 
161
create and manipulate a hashed database. (@code{gdbm} is @emph{NOT} a
 
162
complete database package for an end user.)
 
163
 
 
164
The basic use of @code{gdbm} is to store key/data pairs in a data file.
 
165
Each key must be unique and each key is paired with only one data item.
 
166
The keys can not be directly accessed in sorted order.  The basic unit
 
167
of data in @code{gdbm} is the structure:
 
168
 
 
169
@example
 
170
  typedef struct @{
 
171
             char *dptr;
 
172
             int  dsize;
 
173
          @} datum;
 
174
@end example
 
175
 
 
176
This structure allows for arbitrary sized keys and data items.
 
177
 
 
178
The key/data pairs are stored in a @code{gdbm} disk file, called a
 
179
@code{gdbm} database.  An application must open a @code{gdbm} database
 
180
to be able manipulate the keys and data contained in the database.
 
181
@code{gdbm} allows an application to have multiple databases open at the
 
182
same time.  When an application opens a @code{gdbm} database, it is
 
183
designated as a @code{reader} or a @code{writer}.  A @code{gdbm}
 
184
database opened by at most one writer at a time.  However, many readers
 
185
may open the database open simultaneously.  Readers and writers can not
 
186
open the @code{gdbm} database at the same time.
 
187
 
 
188
@node List, Open, Intro, Top
 
189
@chapter List of functions.
 
190
 
 
191
The following is a quick list of the functions contained in the @code{gdbm}
 
192
library. The include file @code{gdbm.h}, that can be included by the user,
 
193
contains a definition of these functions.
 
194
 
 
195
@example
 
196
#include <gdbm.h>
 
197
 
 
198
GDBM_FILE gdbm_open(name, block_size, flags, mode, fatal_func);
 
199
void gdbm_close(dbf);
 
200
int gdbm_store(dbf, key, content, flag);
 
201
datum gdbm_fetch(dbf, key);
 
202
int gdbm_delete(dbf, key);
 
203
datum gdbm_firstkey(dbf);
 
204
datum gdbm_nextkey(dbf, key);
 
205
int gdbm_reorganize(dbf);
 
206
void gdbm_sync(dbf);
 
207
int gdbm_exists(dbf, key);
 
208
char *gdbm_strerror(errno);
 
209
int gdbm_setopt(dbf, option, value, size)
 
210
@end example
 
211
 
 
212
The @code{gdbm.h} include file is often in the @file{/usr/local/gnu/include}
 
213
directory. (The actual location of @code{gdbm.h} depends on your local
 
214
installation of @code{gdbm}.)
 
215
 
 
216
@node Open, Close, List, Top
 
217
@chapter Opening the database.
 
218
 
 
219
Initialize @code{gdbm} system. If the file has a size of zero bytes, a file
 
220
initialization procedure is performed, setting up the initial structure in the
 
221
file.
 
222
 
 
223
The procedure for opening a @code{gdbm} file is:
 
224
 
 
225
@example
 
226
GDBM_FILE dbf;
 
227
 
 
228
dbf = gdbm_open(name, block_size, flags, mode, fatal_func);
 
229
@end example
 
230
 
 
231
The parameters are:
 
232
 
 
233
@table @asis
 
234
@item char *name
 
235
The name of the file (the complete name, @code{gdbm} does not append any
 
236
characters to this name).
 
237
@item int block_size
 
238
It is used during initialization to determine the size of various constructs. It
 
239
is the size of a single transfer from disk to memory. This parameter is ignored
 
240
if the file has been previously initialized. The minimum size is 512.
 
241
If the value is less than 512, the file system blocksize is used, otherwise the
 
242
value of @code{block_size} is used.
 
243
@item int flags
 
244
If @code{flags} is set to GDBM_READER, the user wants to just read the
 
245
database and any call to @code{gdbm_store} or @code{gdbm_delete} will fail.
 
246
Many readers can access the database at the same time. If @code{flags} is
 
247
set to GDBM_WRITER, the user wants both read and write access to the database
 
248
and requires exclusive access. If @code{flags} is set to GDBM_WRCREAT, the
 
249
user wants both read and write access to the database and if the database does
 
250
not exist, create a new one. If @code{flags} is set to GDBM_NEWDB, the
 
251
user want a new database created, regardless of whether one existed, and wants
 
252
read and write access to the new database.  For all writers (GDBM_WRITER,
 
253
GDBM_WRCREAT and GDBM_NEWDB) the value GDBM_FAST can be added to the 
 
254
@code{flags} field using logical or.  This option causes @code{gdbm}
 
255
to write the database without any disk file synchronization.  This allows 
 
256
faster writes, but may produce an inconsistent database in the event of
 
257
abnormal termination of the writer.
 
258
Any error detected will cause a
 
259
return value of NULL and an appropriate value will be in @code{gdbm_errno} (see
 
260
Variables). If no errors occur, a pointer to the @code{gdbm} file descriptor
 
261
will be returned.
 
262
@item int mode
 
263
File mode (see chmod(2) and open(2) if the file is created).
 
264
@item void (*fatal_func) ()
 
265
A function for @code{gdbm} to call if it detects a fatal error. The only
 
266
parameter of this function is a string. If the value of NULL is provided,
 
267
@code{gdbm} will use a default function.
 
268
@end table
 
269
 
 
270
The return value, @code{dbf}, is the pointer needed by all other functions to
 
271
access that @code{gdbm} file. If the return is the NULL pointer,
 
272
@code{gdbm_open} was not successful. The errors can be found in
 
273
@code{gdbm_errno} for @code{gdbm} errors and in @code{errno} for file system
 
274
errors (for error codes, see @code{gdbm.h}).
 
275
 
 
276
In all of the following calls, the parameter @code{dbf} refers to the pointer
 
277
returned from @code{gdbm_open}.
 
278
 
 
279
@node Close, Store, Open, Top
 
280
@chapter Closing the database.
 
281
 
 
282
It is important that every file opened is also closed. This is needed to
 
283
update the reader/writer count on the file. This is done by:
 
284
 
 
285
@example
 
286
gdbm_close(dbf);
 
287
@end example
 
288
 
 
289
The parameter is:
 
290
 
 
291
@table @asis
 
292
@item GDBM_FILE dbf
 
293
The pointer returned by @code{gdbm_open}.
 
294
@end table
 
295
 
 
296
Closes the @code{gdbm} file and frees all memory associated with the file 
 
297
@code{dbf}. 
 
298
 
 
299
@node Store, Fetch, Close, Top
 
300
@chapter Inserting and replacing records in the database.
 
301
 
 
302
The function @code{gdbm_store} inserts or replaces records in the database.
 
303
 
 
304
@example
 
305
ret = gdbm_store(dbf, key, content, flag);
 
306
@end example
 
307
 
 
308
The parameters are:
 
309
 
 
310
@table @asis
 
311
@item GDBM_FILE dbf
 
312
The pointer returned by @code{gdbm_open}.
 
313
@item datum key
 
314
The @code{key} data.
 
315
@item datum content
 
316
The data to be associated with the key.
 
317
@item int flag
 
318
Defines the action to take when the key is already in the database. The value
 
319
GDBM_REPLACE (defined in @code{gdbm.h}) asks that the old data be replaced by
 
320
the new @code{content}. The value GDBM_INSERT asks that an error be returned
 
321
and no action taken if the @code{key} already exists.
 
322
@end table
 
323
 
 
324
The values returned in @code{ret} are:
 
325
 
 
326
@table @asis
 
327
@item -1
 
328
The item was not stored in the database because the caller was not an
 
329
official writer or either @code{key} or @code{content} have a NULL dptr field.
 
330
Both @code{key} and @code{content} must have the dptr field be a non-NULL value.
 
331
Since a NULL dptr field is used by other functions to indicate an error, a NULL
 
332
field cannot be valid data.
 
333
@item +1
 
334
The item was not stored because the argument @code{flag} was GDBM_INSERT and
 
335
the @code{key} was already in the database.
 
336
@item 0
 
337
No error. @code{content} is keyed by @code{key}. The file on disk is updated
 
338
to reflect the structure of the new database before returning from this
 
339
function.
 
340
@end table
 
341
 
 
342
If you store data for a @code{key} that is already in the data base,
 
343
@code{gdbm} replaces the old data with the new data if called with
 
344
GDBM_REPLACE. You do not get two data items for the same @code{key} and you do
 
345
not get an error from @code{gdbm_store}.
 
346
 
 
347
The size in @code{gdbm} is not restricted like @code{dbm} or @code{ndbm}. Your
 
348
data can be as large as you want.
 
349
 
 
350
@node Fetch, Delete, Store,Top
 
351
@chapter Searching for records in the database.
 
352
 
 
353
Looks up a given @code{key} and returns the information associated with that
 
354
key. The pointer in the structure that is  returned is a pointer to dynamically
 
355
allocated memory block. To search for some data:
 
356
 
 
357
@example
 
358
content = gdbm_fetch(dbf, key);
 
359
@end example
 
360
 
 
361
The parameters are:
 
362
 
 
363
@table @asis
 
364
@item GDBM_FILE dbf
 
365
The pointer returned by @code{gdbm_open}.
 
366
@item datum key
 
367
The @code{key} data.
 
368
@end table
 
369
 
 
370
The datum returned in @code{content} is a pointer to the data found. If the
 
371
dptr is NULL, no data was found. If dptr is not NULL, then it points
 
372
to data allocated by malloc. @code{gdbm} does not automatically free this data.
 
373
The user must free this storage when done using it. This eliminates the
 
374
need to copy the result to save it for later use (you just save the pointer).
 
375
 
 
376
You may also search for a particular key without retrieving it, using:
 
377
 
 
378
@example
 
379
ret = gdbm_exists(dbf, key);
 
380
@end example
 
381
 
 
382
The parameters are:
 
383
 
 
384
@table @asis
 
385
@item GDBM_FILE dbf
 
386
The pointer returned by @code{gdbm_open}.
 
387
@item datum key
 
388
The @code{key} data.
 
389
@end table
 
390
 
 
391
Unlike @code{gdbm_fetch}, this routine does not allocate any memory, and
 
392
simply returns true or false, depending on whether the @code{key} exists,
 
393
or not.
 
394
 
 
395
@node Delete, Sequential, Fetch, Top
 
396
@chapter Removing records from the database.
 
397
 
 
398
To remove some data from the database:
 
399
 
 
400
@example
 
401
ret = gdbm_delete(dbf, key);
 
402
@end example
 
403
 
 
404
The parameters are:
 
405
 
 
406
@table @asis
 
407
@item GDBM_FILE dbf
 
408
The pointer returned by @code{gdbm_open}.
 
409
@item datum key
 
410
The @code{key} data.
 
411
@end table
 
412
 
 
413
The ret value is -1 if the item is not present or the requester is a reader.
 
414
The ret value is 0 if there was a successful delete.
 
415
 
 
416
@code{gdbm_delete} removes the keyed item and the @code{key} from the database
 
417
@code{dbf}. The file on disk is updated to reflect the structure of the new
 
418
database before returning from this function.
 
419
 
 
420
@node Sequential, Reorganization, Delete, Top
 
421
@chapter Sequential access to records.
 
422
 
 
423
The next two functions allow for accessing all items in the database. This
 
424
access is not @code{key} sequential, but it is guaranteed to visit every
 
425
@code{key} in the database once. The order has to do with the hash values.
 
426
@code{gdbm_firstkey} starts the visit of all keys in the database.
 
427
@code{gdbm_nextkey} finds and reads the next entry in the hash structure for
 
428
@code{dbf}.
 
429
 
 
430
@example
 
431
key = gdbm_firstkey(dbf);
 
432
 
 
433
nextkey = gdbm_nextkey(dbf, key);
 
434
@end example
 
435
 
 
436
The parameters are:
 
437
 
 
438
@table @asis
 
439
@item GDBM_FILE dbf
 
440
The pointer returned by @code{gdbm_open}.
 
441
@item datum @code{key}
 
442
@item datum nextkey
 
443
The @code{key} data.
 
444
@end table
 
445
 
 
446
The return values are both datum. If @code{key}.dptr or nextkey.dptr is NULL,
 
447
there is no first @code{key} or next @code{key}. Again notice that dptr points to
 
448
data allocated by malloc and @code{gdbm} will not free it for you.
 
449
 
 
450
These functions were intended to visit the database in read-only algorithms,
 
451
for instance, to validate the database or similar operations.
 
452
 
 
453
File @code{visiting} is based on a @code{hash table}. @code{gdbm_delete}
 
454
re-arranges the hash table to make sure that any collisions in the table do not
 
455
leave some item @code{un-findable}. The original key order is NOT guaranteed to
 
456
remain unchanged in ALL instances. It is possible that some key will not be
 
457
visited if a loop like the following is executed:
 
458
 
 
459
@example
 
460
@group
 
461
   key = gdbm_firstkey ( dbf );
 
462
   while ( key.dptr ) @{
 
463
      nextkey = gdbm_nextkey ( dbf, key );
 
464
      if ( some condition ) @{
 
465
         gdbm_delete ( dbf, key );
 
466
         free ( key.dptr );
 
467
      @}
 
468
      key = nextkey;
 
469
   @}
 
470
@end group
 
471
@end example
 
472
 
 
473
@node Reorganization, Sync, Sequential, Top
 
474
@chapter Database reorganization.
 
475
 
 
476
The following function should be used very seldom.
 
477
 
 
478
@example
 
479
ret = gdbm_reorganize(dbf);
 
480
@end example
 
481
 
 
482
The parameter is:
 
483
 
 
484
@table @asis
 
485
@item GDBM_FILE dbf
 
486
The pointer returned by @code{gdbm_open}.
 
487
@end table
 
488
 
 
489
If you have had a lot of deletions and would like to shrink the space
 
490
used by the @code{gdbm} file, this function will reorganize the database.
 
491
@code{gdbm} will not shorten the length of a @code{gdbm} file (deleted file space will be
 
492
reused) except by using this reorganization.
 
493
 
 
494
This reorganization requires creating a new file and inserting all the elements
 
495
in the old file @code{dbf} into the new file. The new file is then renamed to
 
496
the same name as the old file and @code{dbf} is updated to contain all the
 
497
correct information about the new file. If an error is detected, the return
 
498
value is negative. The value zero is returned after a successful
 
499
reorganization.
 
500
 
 
501
@node Sync, Errors, Reorganization, Top
 
502
@chapter Database Synchronization
 
503
 
 
504
If your database was opened with the GDBM_FAST flag, @code{gdbm} does not
 
505
wait for writes to the disk to complete before continuing.  This allows
 
506
faster writing of databases at the risk of having a corrupted database if
 
507
the application terminates in an abnormal fashion.  The following function
 
508
allows the programmer to make sure the disk version of the 
 
509
database has been completely updated with all changes to the current time.
 
510
 
 
511
@example
 
512
gdbm_sync(dbf);
 
513
@end example
 
514
 
 
515
The parameter is:
 
516
 
 
517
@table @asis
 
518
@item GDBM_FILE dbf
 
519
The pointer returned by @code{gdbm_open}.
 
520
@end table
 
521
 
 
522
This would usually be called after a complete set of changes have been
 
523
made to the database and before some long waiting time.
 
524
@code{gdbm_close} automatically calls the equivalent of @code{gdbm_sync}
 
525
so no call is needed if the database is to be closed immediately after
 
526
the set of changes have been made.
 
527
 
 
528
@node Errors, Options, Sync, Top
 
529
@chapter Error strings.
 
530
 
 
531
To convert a @code{gdbm} error code into English text, use this routine:
 
532
 
 
533
@example
 
534
ret = gdbm_strerror(errno)
 
535
@end example
 
536
 
 
537
The parameter is:
 
538
 
 
539
@table @asis
 
540
@item gdbm_error errno
 
541
The @code{gdbm} error code, usually @code{gdbm_errno}.
 
542
@end table
 
543
 
 
544
The appropiate phrase for reading by humans is returned.
 
545
 
 
546
@node Options, Variables, Errors, top
 
547
@chapter Seting options.
 
548
 
 
549
@code{Gdbm} now supports the ability to set certain options on an already
 
550
open database.
 
551
 
 
552
@example
 
553
ret = gdbm_setopt(dbf, option, value, size)
 
554
@end example
 
555
 
 
556
The parameters are:
 
557
 
 
558
@table @asis
 
559
@item GDBM_FILE dbf
 
560
The pointer returned by @code{gdbm_open}.
 
561
@item int option
 
562
The option to be set.
 
563
@item int *value
 
564
A pointer to the value to which @code{option} will be set.
 
565
@item int size
 
566
The length of the data pointed to by @code{value}.
 
567
@end table
 
568
 
 
569
The valid options are currently:
 
570
 
 
571
  GDBM_CACHESIZE - Set the size of the internal bucket cache.  This
 
572
  option may only be set once on each GDBM_FILE descriptor, and
 
573
  is set automatically to 100 upon the first access to the database.
 
574
 
 
575
  GDBM_FASTMODE - Set fast mode to either on or off.  This allows
 
576
  fast mode to be toggled on an already open and active database.
 
577
  value (see below) should be set to either TRUE or FALSE.
 
578
 
 
579
The return value will be -1 upon failure, or 0 upon success.  The global
 
580
variable @code{gdbm_errno} will be set upon failure.
 
581
 
 
582
For instance, to set a database to use a cache of 10, after opening it
 
583
with @code{gdbm_open}, but prior to accessing it in any way, the following
 
584
code could be used:
 
585
 
 
586
@example
 
587
int value = 10;
 
588
ret = gdbm_setopt(dbf, GDBM_CACHESIZE, &value, sizeof(int));
 
589
@end example
 
590
 
 
591
@node Variables, Compatibility, Options, Top
 
592
@chapter Two useful variables.
 
593
 
 
594
The following two variables are variables that may need to be used:
 
595
 
 
596
@table @asis
 
597
@item gdbm_error gdbm_errno
 
598
The variable that contains more information about @code{gdbm} errors
 
599
(@code{gdbm.h} has the definitions of the error values).
 
600
@item const char * gdbm_version
 
601
The string containing the version information.
 
602
@end table
 
603
 
 
604
@node Compatibility, Conversion, Variables, Top
 
605
@chapter Compatibility with standard @code{dbm} and @code{ndbm}.
 
606
 
 
607
GNU @code{dbm} files are not @code{sparse}. You can copy them with the UNIX
 
608
@code{cp} command and they will not expand in the copying process.
 
609
 
 
610
There is a compatibility mode for use with programs that already use UNIX
 
611
@code{dbm} and UNIX @code{ndbm}.
 
612
 
 
613
GNU @code{dbm} has compatibility functions for @code{dbm}. For @code{dbm}
 
614
compatibility functions, you need the include file @code{dbm.h}.
 
615
 
 
616
In this compatibility mode, no @code{gdbm} file pointer is required
 
617
by the user, and Only one file may be opened at a time. All users in
 
618
compatibility mode are assumed to be writers. If the @code{gdbm} file is a
 
619
read only, it will fail as a writer, but will also try to open it as a reader.
 
620
All returned pointers in datum structures point to data that @code{gdbm} WILL
 
621
free. They should be treated as static pointers (as standard UNIX @code{dbm}
 
622
does). The compatibility function names are the same as the UNIX @code{dbm}
 
623
function names. Their definitions follow:
 
624
 
 
625
@example
 
626
int dbminit(name);
 
627
int store(key, content);
 
628
datum fetch(key);
 
629
int delete(key);
 
630
datum firstkey();
 
631
datum nextkey(key);
 
632
int dbmclose();
 
633
@end example
 
634
 
 
635
Standard UNIX @code{dbm} and GNU @code{dbm} do not have the same data
 
636
format in the file. You cannot access a standard UNIX @code{dbm} file with GNU
 
637
@code{dbm}!  If you want to use an old database with GNU @code{dbm}, you must
 
638
use the @code{conv2gdbm} program.
 
639
 
 
640
Also, GNU @code{dbm} has compatibility functions for @code{ndbm}. For
 
641
@code{ndbm} compatibility functions, you need the include file @code{ndbm.h}.
 
642
 
 
643
Again, just like @code{ndbm}, any returned datum can be assumed to be static
 
644
storage. You do not have to free that memory, the @code{ndbm} compatibility
 
645
functions will do it for you.
 
646
 
 
647
The functions are:
 
648
 
 
649
@example
 
650
DBM *dbm_open(name, flags, mode);
 
651
void dbm_close(file);
 
652
datum dbm_fetch(file, key);
 
653
int dbm_store(file, key, @code{content}, flags);
 
654
int dbm_delete(file, key);
 
655
datum dbm_firstkey(file);
 
656
datum dbm_nextkey(file);
 
657
int dbm_error(file);
 
658
int dbm_clearerr(file);
 
659
int dbm_dirfno(file);
 
660
int dbm_pagfno(file);
 
661
int dbm_rdonly(file);
 
662
@end example
 
663
 
 
664
If you want to compile an old C program that used UNIX @code{dbm} or @code{ndbm}
 
665
and want to use @code{gdbm} files, execute the following @code{cc} command:
 
666
 
 
667
@example
 
668
cc ... -L /usr/local/lib -lgdbm
 
669
@end example
 
670
 
 
671
@node Conversion, Bugs, Compatibility, Top
 
672
@chapter Converting @code{dbm} files to @code{gdbm} format.
 
673
 
 
674
The program @code{conv2gdbm} has been provided to help you convert from @code{dbm}
 
675
databases to @code{gdbm}. The usage is:
 
676
 
 
677
@example
 
678
conv2gdbm [-q] [-b block_size] dbm_file [gdbm_file]
 
679
@end example
 
680
 
 
681
The options are:
 
682
 
 
683
@table @asis
 
684
@item -q
 
685
Causes @code{conv2gdbm} to work quietly.
 
686
@item block_size
 
687
Is the same as in @code{gdbm_open}.
 
688
@item dbm_file
 
689
Is the name of the @code{dbm} file without the @code{.pag} or @code{.dir}
 
690
extensions.
 
691
@item gdbm_file
 
692
Is the complete file name. If not included, the @code{gdbm} file name is the
 
693
same as the @code{dbm} file name without any extensions. That is
 
694
@code{conv2gdbm} @code{dbmfile} converts the files @code{dbmfile.pag} and
 
695
@code{dbmfile.dir} into a @code{gdbm} file called @code{dbmfile}.
 
696
@end table
 
697
 
 
698
 
 
699
@node Bugs, , Conversion, Top
 
700
@chapter Problems and bugs.
 
701
 
 
702
If you have problems with GNU @code{dbm} or think you've found a bug,
 
703
please report it. Before reporting a bug, make sure you've actually
 
704
found a real bug. Carefully reread the documentation and see if it
 
705
really says you can do what you're trying to do. If it's not clear
 
706
whether you should be able to do something or not, report that too; it's
 
707
a bug in the documentation!
 
708
 
 
709
Before reporting a bug or trying to fix it yourself, try to isolate it
 
710
to the smallest possible input file that reproduces the problem. Then
 
711
send us the input file and the exact results @code{gdbm} gave you. Also
 
712
say what you expected to occur; this will help us decide whether the
 
713
problem was really in the documentation.
 
714
 
 
715
Once you've got a precise problem, send e-mail to:
 
716
 
 
717
@example
 
718
Internet: @file{bug-gnu-utils@@prep.ai.mit.edu}.
 
719
UUCP: @file{mit-eddie!prep.ai.mit.edu!bug-gnu-utils}.
 
720
@end example
 
721
 
 
722
Please include the version number of GNU @code{dbm} you are using. You can get
 
723
this information by printing the variable @code{gdbm_version} (see Variables).
 
724
 
 
725
Non-bug suggestions are always welcome as well. If you have questions
 
726
about things that are unclear in the documentation or are just obscure
 
727
features, please report them too.
 
728
 
 
729
You may contact the author by:
 
730
@example
 
731
    e-mail:  phil@@cs.wwu.edu
 
732
   us-mail:  Philip A. Nelson
 
733
             Computer Science Department
 
734
             Western Washington University
 
735
             Bellingham, WA 98226
 
736
@end example
 
737
 
 
738
You may contact the current maintainer by:
 
739
@example
 
740
    e-mail:  downsj@@CSOS.ORST.EDU
 
741
@end example
 
742
 
 
743
@bye
 
744
 
 
745
 
 
746