2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)ndbm.c 8.4 (Berkeley) 7/21/94
33 * $DragonFly: src/lib/libc/db/hash/ndbm.c,v 1.4 2005/11/12 23:01:55 swildner Exp $
37 * This package provides a dbm compatible interface to the new hashing
38 * package described in db(3).
41 #include <sys/param.h>
56 dbm_open(const char *file, int flags, int mode)
59 char path[MAXPATHLEN];
68 if( strlen(file) >= sizeof(path) - strlen(DBM_SUFFIX)) {
73 strcat(path, DBM_SUFFIX);
74 return ((DBM *)__hash_open(path, flags, mode, &info, 0));
89 dbm_fetch(DBM *db, datum key)
93 DBT dbtkey, dbtretdata;
95 dbtkey.data = key.dptr;
96 dbtkey.size = key.dsize;
97 status = (db->get)(db, &dbtkey, &dbtretdata, 0);
99 dbtretdata.data = NULL;
102 retdata.dptr = dbtretdata.data;
103 retdata.dsize = dbtretdata.size;
113 dbm_firstkey(DBM *db)
117 DBT dbtretkey, dbtretdata;
119 status = (db->seq)(db, &dbtretkey, &dbtretdata, R_FIRST);
121 dbtretkey.data = NULL;
122 retkey.dptr = dbtretkey.data;
123 retkey.dsize = dbtretkey.size;
137 DBT dbtretkey, dbtretdata;
139 status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT);
141 dbtretkey.data = NULL;
142 retkey.dptr = dbtretkey.data;
143 retkey.dsize = dbtretkey.size;
153 dbm_delete(DBM *db, datum key)
158 dbtkey.data = key.dptr;
159 dbtkey.size = key.dsize;
160 status = (db->del)(db, &dbtkey, 0);
171 * 1 if DBM_INSERT and entry exists
174 dbm_store(DBM *db, datum key, datum data, int flags)
178 dbtkey.data = key.dptr;
179 dbtkey.size = key.dsize;
180 dbtdata.data = data.dptr;
181 dbtdata.size = data.dsize;
182 return ((db->put)(db, &dbtkey, &dbtdata,
183 (flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
191 hp = (HTAB *)db->internal;
196 dbm_clearerr(DBM *db)
200 hp = (HTAB *)db->internal;
208 return(((HTAB *)db->internal)->fp);