2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. ***REMOVED*** - see
14 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
15 * 4. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #if defined(LIBC_SCCS) && !defined(lint)
33 static char sccsid
[] = "@(#)db.c 8.4 (Berkeley) 2/21/94";
34 #endif /* LIBC_SCCS and not lint */
38 #ifndef __DBINTERFACE_PRIVATE
39 #define __DBINTERFACE_PRIVATE
44 #include <sys/types.h>
54 /* a global flag that locks closed all databases */
55 int all_databases_locked_closed
= 0;
57 /* set or unset a global lock flag to disable the
58 * opening of any DBM file
61 dbSetOrClearDBLock(DBLockFlagEnum type
)
63 if(type
== LockOutDatabase
)
64 all_databases_locked_closed
= 1;
66 all_databases_locked_closed
= 0;
69 #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
74 dbopen(const char *fname
, int flags
,int mode
, DBTYPE type
, const void *openinfo
)
77 /* lock out all file databases. Let in-memory databases through
79 if(all_databases_locked_closed
&& fname
)
85 #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN)
88 #if 0 /* most systems don't have EXLOCK and SHLOCK */
89 #define USE_OPEN_FLAGS \
90 (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \
91 O_RDWR | O_SHLOCK | O_TRUNC)
93 #define USE_OPEN_FLAGS \
94 (O_CREAT | O_EXCL | O_RDONLY | \
98 if ((flags
& ~(USE_OPEN_FLAGS
| DB_FLAGS
)) == 0)
100 /* we don't need btree and recno right now */
103 return (__bt_open(fname
, flags
& USE_OPEN_FLAGS
,
104 mode
, openinfo
, flags
& DB_FLAGS
));
106 return (__rec_open(fname
, flags
& USE_OPEN_FLAGS
,
107 mode
, openinfo
, flags
& DB_FLAGS
));
111 return (__hash_open(fname
, flags
& USE_OPEN_FLAGS
,
112 mode
, (const HASHINFO
*)openinfo
, flags
& DB_FLAGS
));
130 * dbp: pointer to the DB structure.
135 /* The only thing that can succeed is a close. */
136 dbp
->del
= (int (*)(const struct __db
*, const DBT
*, uint
))__dberr
;
137 dbp
->fd
= (int (*)(const struct __db
*))__dberr
;
138 dbp
->get
= (int (*)(const struct __db
*, const DBT
*, DBT
*, uint
))__dberr
;
139 dbp
->put
= (int (*)(const struct __db
*, DBT
*, const DBT
*, uint
))__dberr
;
140 dbp
->seq
= (int (*)(const struct __db
*, DBT
*, DBT
*, uint
))__dberr
;
141 dbp
->sync
= (int (*)(const struct __db
*, uint
))__dberr
;