Don't call CORE::close in file handle DESTROY method
[p5sagit/p5-mst-13.2.git] / ext / SDBM_File / sdbm / sdbm.3
CommitLineData
463ee0b2 1.\" $Id: sdbm.3,v 1.2 90/12/13 13:00:57 oz Exp $
2.TH SDBM 3 "1 March 1990"
3.SH NAME
4sdbm, dbm_open, dbm_prep, dbm_close, dbm_fetch, dbm_store, dbm_delete, dbm_firstkey, dbm_nextkey, dbm_hash, dbm_rdonly, dbm_error, dbm_clearerr, dbm_dirfno, dbm_pagfno \- data base subroutines
5.SH SYNOPSIS
6.nf
7.ft B
8#include <sdbm.h>
9.sp
10typedef struct {
11 char *dptr;
12 int dsize;
13} datum;
14.sp
15datum nullitem = { NULL, 0 };
16.sp
17\s-1DBM\s0 *dbm_open(char *file, int flags, int mode)
18.sp
19\s-1DBM\s0 *dbm_prep(char *dirname, char *pagname, int flags, int mode)
20.sp
21void dbm_close(\s-1DBM\s0 *db)
22.sp
23datum dbm_fetch(\s-1DBM\s0 *db, key)
24.sp
25int dbm_store(\s-1DBM\s0 *db, datum key, datum val, int flags)
26.sp
27int dbm_delete(\s-1DBM\s0 *db, datum key)
28.sp
29datum dbm_firstkey(\s-1DBM\s0 *db)
30.sp
31datum dbm_nextkey(\s-1DBM\s0 *db)
32.sp
33long dbm_hash(char *string, int len)
34.sp
35int dbm_rdonly(\s-1DBM\s0 *db)
36int dbm_error(\s-1DBM\s0 *db)
37dbm_clearerr(\s-1DBM\s0 *db)
38int dbm_dirfno(\s-1DBM\s0 *db)
39int dbm_pagfno(\s-1DBM\s0 *db)
40.ft R
41.fi
42.SH DESCRIPTION
43.IX "database library" sdbm "" "\fLsdbm\fR"
44.IX dbm_open "" "\fLdbm_open\fR \(em open \fLsdbm\fR database"
45.IX dbm_prep "" "\fLdbm_prep\fR \(em prepare \fLsdbm\fR database"
46.IX dbm_close "" "\fLdbm_close\fR \(em close \fLsdbm\fR routine"
47.IX dbm_fetch "" "\fLdbm_fetch\fR \(em fetch \fLsdbm\fR database data"
48.IX dbm_store "" "\fLdbm_store\fR \(em add data to \fLsdbm\fR database"
49.IX dbm_delete "" "\fLdbm_delete\fR \(em remove data from \fLsdbm\fR database"
50.IX dbm_firstkey "" "\fLdbm_firstkey\fR \(em access \fLsdbm\fR database"
51.IX dbm_nextkey "" "\fLdbm_nextkey\fR \(em access \fLsdbm\fR database"
52.IX dbm_hash "" "\fLdbm_hash\fR \(em string hash for \fLsdbm\fR database"
53.IX dbm_rdonly "" "\fLdbm_rdonly\fR \(em return \fLsdbm\fR database read-only mode"
54.IX dbm_error "" "\fLdbm_error\fR \(em return \fLsdbm\fR database error condition"
55.IX dbm_clearerr "" "\fLdbm_clearerr\fR \(em clear \fLsdbm\fR database error condition"
56.IX dbm_dirfno "" "\fLdbm_dirfno\fR \(em return \fLsdbm\fR database bitmap file descriptor"
57.IX dbm_pagfno "" "\fLdbm_pagfno\fR \(em return \fLsdbm\fR database data file descriptor"
58.IX "database functions \(em \fLsdbm\fR" dbm_open "" \fLdbm_open\fP
59.IX "database functions \(em \fLsdbm\fR" dbm_prep "" \fLdbm_prep\fP
60.IX "database functions \(em \fLsdbm\fR" dbm_close "" \fLdbm_close\fP
61.IX "database functions \(em \fLsdbm\fR" dbm_fetch "" \fLdbm_fetch\fP
62.IX "database functions \(em \fLsdbm\fR" dbm_store "" \fLdbm_store\fP
63.IX "database functions \(em \fLsdbm\fR" dbm_delete "" \fLdbm_delete\fP
64.IX "database functions \(em \fLsdbm\fR" dbm_firstkey "" \fLdbm_firstkey\fP
65.IX "database functions \(em \fLsdbm\fR" dbm_nextkey "" \fLdbm_nextkey\fP
66.IX "database functions \(em \fLsdbm\fR" dbm_rdonly "" \fLdbm_rdonly\fP
67.IX "database functions \(em \fLsdbm\fR" dbm_error "" \fLdbm_error\fP
68.IX "database functions \(em \fLsdbm\fR" dbm_clearerr "" \fLdbm_clearerr\fP
69.IX "database functions \(em \fLsdbm\fR" dbm_dirfno "" \fLdbm_dirfno\fP
70.IX "database functions \(em \fLsdbm\fR" dbm_pagfno "" \fLdbm_pagfno\fP
71.LP
72This package allows an application to maintain a mapping of <key,value> pairs
73in disk files. This is not to be considered a real database system, but is
74still useful in many simple applications built around fast retrieval of a data
75value from a key. This implementation uses an external hashing scheme,
76called Dynamic Hashing, as described by Per-Aake Larson in BIT 18 (1978) pp.
77184-201. Retrieval of any item usually requires a single disk access.
78The application interface is compatible with the
79.IR ndbm (3)
80library.
81.LP
82An
83.B sdbm
84database is kept in two files usually given the extensions
85.B \.dir
86and
87.BR \.pag .
88The
89.B \.dir
90file contains a bitmap representing a forest of binary hash trees, the leaves
91of which indicate data pages in the
92.B \.pag
93file.
94.LP
95The application interface uses the
96.B datum
97structure to describe both
98.I keys
99and
100.IR value s.
101A
102.B datum
103specifies a byte sequence of
104.I dsize
105size pointed to by
106.IR dptr .
107If you use
108.SM ASCII
109strings as
110.IR key s
111or
112.IR value s,
113then you must decide whether or not to include the terminating
114.SM NUL
115byte which sometimes defines strings. Including it will require larger
116database files, but it will be possible to get sensible output from a
117.IR strings (1)
118command applied to the data file.
119.LP
120In order to allow a process using this package to manipulate multiple
121databases, the applications interface always requires a
122.IR handle ,
123a
124.BR "DBM *" ,
125to identify the database to be manipulated. Such a handle can be obtained
126from the only routines that do not require it, namely
127.BR dbm_open (\|)
128or
129.BR dbm_prep (\|).
130Either of these will open or create the two necessary files. The
131difference is that the latter allows explicitly naming the bitmap and data
132files whereas
133.BR dbm_open (\|)
134will take a base file name and call
135.BR dbm_prep (\|)
136with the default extensions.
137The
138.I flags
139and
140.I mode
141parameters are the same as for
142.BR open (2).
143.LP
144To free the resources occupied while a database handle is active, call
145.BR dbm_close (\|).
146.LP
147Given a handle, one can retrieve data associated with a key by using the
148.BR dbm_fetch (\|)
149routine, and associate data with a key by using the
150.BR dbm_store (\|)
151routine.
152.LP
153The values of the
154.I flags
155parameter for
156.BR dbm_store (\|)
157can be either
158.BR \s-1DBM_INSERT\s0 ,
159which will not change an existing entry with the same key, or
160.BR \s-1DBM_REPLACE\s0 ,
161which will replace an existing entry with the same key.
162Keys are unique within the database.
163.LP
164To delete a key and its associated value use the
165.BR dbm_delete (\|)
166routine.
167.LP
168To retrieve every key in the database, use a loop like:
169.sp
170.nf
171.ft B
172for (key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db))
173 ;
174.ft R
175.fi
176.LP
177The order of retrieval is unspecified.
178.LP
179If you determine that the performance of the database is inadequate or
180you notice clustering or other effects that may be due to the hashing
181algorithm used by this package, you can override it by supplying your
182own
183.BR dbm_hash (\|)
184routine. Doing so will make the database unintelligable to any other
185applications that do not use your specialized hash function.
186.sp
187.LP
188The following macros are defined in the header file:
189.IP
190.BR dbm_rdonly (\|)
191returns true if the database has been opened read\-only.
192.IP
193.BR dbm_error (\|)
194returns true if an I/O error has occurred.
195.IP
196.BR dbm_clearerr (\|)
197allows you to clear the error flag if you think you know what the error
198was and insist on ignoring it.
199.IP
200.BR dbm_dirfno (\|)
201returns the file descriptor associated with the bitmap file.
202.IP
203.BR dbm_pagfno (\|)
204returns the file descriptor associated with the data file.
205.SH SEE ALSO
206.IR open (2).
207.SH DIAGNOSTICS
208Functions that return a
209.B "DBM *"
210handle will use
211.SM NULL
212to indicate an error.
213Functions that return an
214.B int
215will use \-1 to indicate an error. The normal return value in that case is 0.
216Functions that return a
217.B datum
218will return
219.B nullitem
220to indicate an error.
221.LP
222As a special case of
223.BR dbm_store (\|),
224if it is called with the
225.B \s-1DBM_INSERT\s0
226flag and the key already exists in the database, the return value will be 1.
227.LP
228In general, if a function parameter is invalid,
229.B errno
230will be set to
231.BR \s-1EINVAL\s0 .
232If a write operation is requested on a read-only database,
233.B errno
234will be set to
235.BR \s-1ENOPERM\s0 .
236If a memory allocation (using
237.IR malloc (3))
238failed,
239.B errno
240will be set to
241.BR \s-1ENOMEM\s0 .
242For I/O operation failures
243.B errno
244will contain the value set by the relevant failed system call, either
245.IR read (2),
246.IR write (2),
247or
248.IR lseek (2).
249.SH AUTHOR
250.IP "Ozan S. Yigit" (oz@nexus.yorku.ca)
251.SH BUGS
252The sum of key and value data sizes must not exceed
253.B \s-1PAIRMAX\s0
254(1008 bytes).
255.LP
256The sum of the key and value data sizes where several keys hash to the
257same value must fit within one bitmap page.
258.LP
259The
260.B \.pag
261file will contain holes, so its apparent size is larger than its contents.
262When copied through the filesystem the holes will be filled.
263.LP
264The contents of
265.B datum
266values returned are in volatile storage. If you want to retain the values
267pointed to, you must copy them immediately before another call to this package.
268.LP
269The only safe way for multiple processes to (read and) update a database at
270the same time, is to implement a private locking scheme outside this package
271and open and close the database between lock acquisitions. It is safe for
272multiple processes to concurrently access a database read-only.
273.SH APPLICATIONS PORTABILITY
274For complete source code compatibility with the Berkeley Unix
275.IR ndbm (3)
276library, the
277.B sdbm.h
278header file should be installed in
279.BR /usr/include/ndbm.h .
280.LP
281The
282.B nullitem
283data item, and the
284.BR dbm_prep (\|),
285.BR dbm_hash (\|),
286.BR dbm_rdonly (\|),
287.BR dbm_dirfno (\|),
288and
289.BR dbm_pagfno (\|)
290functions are unique to this package.