2001-02-11 17:24:25 +00:00
|
|
|
.\" Copyright (c) 1999 Tim Singletary
|
|
|
|
.\" No copyright is claimed.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
|
|
|
.\" Note: The date here should be updated whenever a non-trivial
|
|
|
|
.\" change is made to the manual page.
|
|
|
|
.Dd July 7, 1999
|
2001-02-12 15:16:24 +00:00
|
|
|
.Dt DBM 3
|
|
|
|
.Os
|
2001-02-11 17:24:25 +00:00
|
|
|
.Sh NAME
|
2001-02-12 15:16:24 +00:00
|
|
|
.Nm dbm_clearerr ,
|
|
|
|
.Nm dbm_close ,
|
|
|
|
.Nm dbm_delete ,
|
|
|
|
.Nm dbm_dirfno ,
|
|
|
|
.Nm dbm_error ,
|
|
|
|
.Nm dbm_fetch ,
|
|
|
|
.Nm dbm_firstkey ,
|
|
|
|
.Nm dbm_nextkey ,
|
|
|
|
.Nm dbm_open ,
|
2001-02-11 17:24:25 +00:00
|
|
|
.Nm dbm_store
|
|
|
|
.Nd database access functions
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In fcntl.h
|
|
|
|
.In ndbm.h
|
2001-02-11 17:24:25 +00:00
|
|
|
.Ft DBM *
|
|
|
|
.Fn dbm_open "const char *base" "int flags" "int mode"
|
|
|
|
.Ft void
|
|
|
|
.Fn dbm_close "DBM *db"
|
|
|
|
.Ft int
|
|
|
|
.Fn dbm_store "DBM *db" "datum key" "datum data" "int flags"
|
|
|
|
.Ft datum
|
|
|
|
.Fn dbm_fetch "DBM *db" "datum key"
|
|
|
|
.Ft int
|
|
|
|
.Fn dbm_delete "DBM *db" "datum key"
|
|
|
|
.Ft datum
|
|
|
|
.Fn dbm_firstkey "DBM *db"
|
|
|
|
.Ft datum
|
|
|
|
.Fn dbm_nextkey "DBM *db"
|
|
|
|
.Ft int
|
|
|
|
.Fn dbm_error "DBM *db"
|
|
|
|
.Ft int
|
|
|
|
.Fn dbm_clearerr "DBM *db"
|
|
|
|
.Ft int
|
|
|
|
.Fn dbm_dirfno "DBM *db"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
Database access functions.
|
2001-02-12 15:16:24 +00:00
|
|
|
These functions are implemented using
|
|
|
|
.Xr dbopen 3
|
|
|
|
with a
|
|
|
|
.Xr hash 3
|
2001-02-11 17:24:25 +00:00
|
|
|
database.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pp
|
|
|
|
.Vt datum
|
2001-02-11 17:24:25 +00:00
|
|
|
is declared in
|
2001-02-12 15:16:24 +00:00
|
|
|
.Aq Pa ndbm.h :
|
2001-02-11 17:24:25 +00:00
|
|
|
.Bd -literal
|
|
|
|
typedef struct {
|
2001-02-12 15:16:24 +00:00
|
|
|
char *dptr;
|
|
|
|
int dsize;
|
2001-02-11 17:24:25 +00:00
|
|
|
} datum;
|
|
|
|
.Ed
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_open base flags mode
|
|
|
|
opens or creates a database.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fa base
|
|
|
|
is the basename of the file containing
|
2001-02-11 17:24:25 +00:00
|
|
|
the database; the actual database has a
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pa .db
|
|
|
|
suffix.
|
|
|
|
I.e., if
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fa base
|
|
|
|
is
|
2001-02-12 15:16:24 +00:00
|
|
|
.Qq Li /home/me/mystuff
|
2001-02-11 17:24:25 +00:00
|
|
|
then the actual database is in the file
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pa /home/me/mystuff.db .
|
|
|
|
.Fa flags
|
|
|
|
and
|
|
|
|
.Fa mode
|
|
|
|
are passed to
|
|
|
|
.Xr open 2 .
|
2001-08-16 11:09:00 +00:00
|
|
|
.Pq Dv O_RDWR | O_CREAT
|
2001-02-11 17:24:25 +00:00
|
|
|
is a typical value for
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fa flags ;
|
2001-02-11 17:24:25 +00:00
|
|
|
.Li 0660
|
|
|
|
is a typical value for
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fa mode .
|
|
|
|
.Dv O_WRONLY
|
2001-02-11 17:24:25 +00:00
|
|
|
is not allowed in
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fa flags .
|
2001-02-11 17:24:25 +00:00
|
|
|
The pointer returned by
|
|
|
|
.Fn dbm_open
|
|
|
|
identifies the database and is the
|
|
|
|
.Fa db
|
|
|
|
argument to the other functions.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fn dbm_open
|
|
|
|
returns
|
|
|
|
.Dv NULL
|
|
|
|
and sets
|
2001-02-11 17:24:25 +00:00
|
|
|
.Va errno
|
2001-02-12 15:16:24 +00:00
|
|
|
if there were any errors.
|
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_close db
|
|
|
|
closes the database.
|
|
|
|
.Fn dbm_close
|
|
|
|
normally returns zero.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_store db key data flags
|
2001-02-12 15:16:24 +00:00
|
|
|
inserts or replaces an entry in the database.
|
|
|
|
.Fa flags
|
|
|
|
is either
|
|
|
|
.Dv DBM_INSERT
|
|
|
|
or
|
|
|
|
.Dv DBM_REPLACE .
|
|
|
|
If
|
|
|
|
.Fa flags
|
2001-02-11 17:24:25 +00:00
|
|
|
is
|
2001-02-12 15:16:24 +00:00
|
|
|
.Dv DBM_INSERT
|
2001-02-11 17:24:25 +00:00
|
|
|
and the database already contains an entry for
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fa key ,
|
|
|
|
that entry is not replaced.
|
|
|
|
Otherwise the entry is replaced or inserted.
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_store
|
2001-06-24 01:34:38 +00:00
|
|
|
normally returns zero but returns 1 if the entry could not be
|
2001-02-12 15:16:24 +00:00
|
|
|
inserted (because
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fa flags
|
|
|
|
is
|
2001-02-12 15:16:24 +00:00
|
|
|
.Dv DBM_INSERT ,
|
2001-02-11 17:24:25 +00:00
|
|
|
and an entry with
|
|
|
|
.Fa key
|
|
|
|
already exists) or returns -1 and sets
|
|
|
|
.Va errno
|
|
|
|
if there were any errors.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_fetch db key
|
2001-02-12 15:16:24 +00:00
|
|
|
returns
|
|
|
|
.Dv NULL
|
2001-02-11 17:24:25 +00:00
|
|
|
or the
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fa data
|
|
|
|
corresponding to
|
|
|
|
.Fa key .
|
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_delete db key
|
|
|
|
deletes the entry for
|
2001-02-12 15:16:24 +00:00
|
|
|
.Fa key .
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_delete
|
|
|
|
normally returns zero but returns 1 if there was no entry with
|
|
|
|
.Fa key
|
2001-02-12 15:16:24 +00:00
|
|
|
in the database or returns -1 and sets
|
|
|
|
.Va errno
|
2001-02-11 17:24:25 +00:00
|
|
|
if there were any errors.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_firstkey db
|
|
|
|
returns the first key in the database.
|
|
|
|
.Fn dbm_nextkey db
|
2001-02-12 15:16:24 +00:00
|
|
|
returns subsequent keys.
|
|
|
|
.Fn db_firstkey
|
|
|
|
must be called before
|
|
|
|
.Fn dbm_nextkey .
|
2001-02-11 17:24:25 +00:00
|
|
|
The order in which keys are returned is unspecified and may appear
|
|
|
|
random.
|
|
|
|
.Fn dbm_nextkey
|
2001-02-12 15:16:24 +00:00
|
|
|
returns
|
|
|
|
.Dv NULL
|
2001-02-11 17:24:25 +00:00
|
|
|
after all keys have been returned.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_error db
|
2001-02-12 15:16:24 +00:00
|
|
|
returns the
|
2001-02-11 17:24:25 +00:00
|
|
|
.Va errno
|
|
|
|
value of the most recent error.
|
|
|
|
.Fn dbm_clearerr db
|
|
|
|
resets this value to 0 and returns 0.
|
2001-02-12 15:16:24 +00:00
|
|
|
.Pp
|
2001-02-11 17:24:25 +00:00
|
|
|
.Fn dbm_dirfno db
|
|
|
|
returns the file descriptor to the database.
|
|
|
|
.Sh SEE ALSO
|
2001-02-12 15:16:24 +00:00
|
|
|
.Xr open 2 ,
|
|
|
|
.Xr dbopen 3 ,
|
|
|
|
.Xr hash 3
|
2001-02-11 17:24:25 +00:00
|
|
|
.Sh STANDARDS
|
2001-02-12 15:16:24 +00:00
|
|
|
These functions (except
|
|
|
|
.Fn dbm_dirfno )
|
|
|
|
are included in the
|
|
|
|
.St -susv2 .
|