comparison nss/lib/dbm/src/db.c @ 3:150b72113545

Add DBM and legacydb support
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 05 Aug 2014 18:32:02 +0200
parents
children
comparison
equal deleted inserted replaced
2:a945361df361 3:150b72113545
1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
18 *
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
29 * SUCH DAMAGE.
30 */
31
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 */
35
36 #ifndef __DBINTERFACE_PRIVATE
37 #define __DBINTERFACE_PRIVATE
38 #endif
39 #ifdef macintosh
40 #include <unix.h>
41 #else
42 #include <sys/types.h>
43 #endif
44
45 #include <errno.h>
46 #include <fcntl.h>
47 #include <stddef.h>
48 #include <stdio.h>
49
50 #include "mcom_db.h"
51
52 /* a global flag that locks closed all databases */
53 int all_databases_locked_closed = 0;
54
55 /* set or unset a global lock flag to disable the
56 * opening of any DBM file
57 */
58 void
59 dbSetOrClearDBLock(DBLockFlagEnum type)
60 {
61 if(type == LockOutDatabase)
62 all_databases_locked_closed = 1;
63 else
64 all_databases_locked_closed = 0;
65 }
66
67 DB *
68 dbopen(const char *fname, int flags,int mode, DBTYPE type, const void *openinfo)
69 {
70
71 /* lock out all file databases. Let in-memory databases through
72 */
73 if(all_databases_locked_closed && fname)
74 {
75 errno = EINVAL;
76 return(NULL);
77 }
78
79 #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN)
80
81
82 #if 0 /* most systems don't have EXLOCK and SHLOCK */
83 #define USE_OPEN_FLAGS \
84 (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \
85 O_RDWR | O_SHLOCK | O_TRUNC)
86 #else
87 #define USE_OPEN_FLAGS \
88 (O_CREAT | O_EXCL | O_RDONLY | \
89 O_RDWR | O_TRUNC)
90 #endif
91
92 if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0)
93 switch (type) {
94 /* we don't need btree and recno right now */
95 #if 0
96 case DB_BTREE:
97 return (__bt_open(fname, flags & USE_OPEN_FLAGS,
98 mode, openinfo, flags & DB_FLAGS));
99 case DB_RECNO:
100 return (__rec_open(fname, flags & USE_OPEN_FLAGS,
101 mode, openinfo, flags & DB_FLAGS));
102 #endif
103
104 case DB_HASH:
105 return (__hash_open(fname, flags & USE_OPEN_FLAGS,
106 mode, (const HASHINFO *)openinfo, flags & DB_FLAGS));
107 default:
108 break;
109 }
110 errno = EINVAL;
111 return (NULL);
112 }
113
114 static int
115 __dberr()
116 {
117 return (RET_ERROR);
118 }
119
120 /*
121 * __DBPANIC -- Stop.
122 *
123 * Parameters:
124 * dbp: pointer to the DB structure.
125 */
126 void
127 __dbpanic(DB *dbp)
128 {
129 /* The only thing that can succeed is a close. */
130 dbp->del = (int (*)(const struct __db *, const DBT *, uint))__dberr;
131 dbp->fd = (int (*)(const struct __db *))__dberr;
132 dbp->get = (int (*)(const struct __db *, const DBT *, DBT *, uint))__dberr;
133 dbp->put = (int (*)(const struct __db *, DBT *, const DBT *, uint))__dberr;
134 dbp->seq = (int (*)(const struct __db *, DBT *, DBT *, uint))__dberr;
135 dbp->sync = (int (*)(const struct __db *, uint))__dberr;
136 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)