Back to index

lightning-sunbird  0.9+nobinonly
db.c
Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1991, 1993
00003  *     The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. ***REMOVED*** - see 
00014  *    ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
00015  * 4. Neither the name of the University nor the names of its contributors
00016  *    may be used to endorse or promote products derived from this software
00017  *    without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00020  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00025  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00026  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00028  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  */
00031 
00032 #if defined(LIBC_SCCS) && !defined(lint)
00033 static char sccsid[] = "@(#)db.c   8.4 (Berkeley) 2/21/94";
00034 #endif /* LIBC_SCCS and not lint */
00035 
00036 #include "watcomfx.h"
00037 
00038 #ifndef __DBINTERFACE_PRIVATE
00039 #define __DBINTERFACE_PRIVATE
00040 #endif
00041 #ifdef macintosh
00042 #include <unix.h>
00043 #else
00044 #include <sys/types.h>
00045 #endif
00046 
00047 #include <errno.h>
00048 #include <fcntl.h>
00049 #include <stddef.h>
00050 #include <stdio.h>
00051 
00052 #include "mcom_db.h"
00053 
00054 /* a global flag that locks closed all databases */
00055 int all_databases_locked_closed = 0;
00056 
00057 /* set or unset a global lock flag to disable the
00058  * opening of any DBM file
00059  */
00060 void 
00061 dbSetOrClearDBLock(DBLockFlagEnum type)
00062 {
00063        if(type == LockOutDatabase)
00064               all_databases_locked_closed = 1;
00065        else
00066               all_databases_locked_closed = 0;
00067 }
00068 
00069 #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
00070 DB *
00071 #else
00072 PR_IMPLEMENT(DB *)
00073 #endif
00074 dbopen(const char *fname, int flags,int mode, DBTYPE type, const void *openinfo)
00075 {
00076 
00077        /* lock out all file databases.  Let in-memory databases through
00078         */
00079        if(all_databases_locked_closed && fname)
00080          {
00081               errno = EINVAL;
00082               return(NULL);
00083          }
00084 
00085 #define       DB_FLAGS      (DB_LOCK | DB_SHMEM | DB_TXN)
00086 
00087 
00088 #if 0  /* most systems dont have EXLOCK and SHLOCK */
00089 #define       USE_OPEN_FLAGS                                                 \
00090        (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY |         \
00091         O_RDWR | O_SHLOCK | O_TRUNC)
00092 #else
00093 #define       USE_OPEN_FLAGS                                                 \
00094        (O_CREAT | O_EXCL  | O_RDONLY |           \
00095         O_RDWR | O_TRUNC)
00096 #endif
00097 
00098        if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0)
00099               switch (type) {
00100 /* we don't need btree and recno right now */    
00101 #if 0
00102               case DB_BTREE:
00103                      return (__bt_open(fname, flags & USE_OPEN_FLAGS,
00104                          mode, openinfo, flags & DB_FLAGS));
00105               case DB_RECNO:
00106                      return (__rec_open(fname, flags & USE_OPEN_FLAGS,
00107                          mode, openinfo, flags & DB_FLAGS));
00108 #endif
00109 
00110               case DB_HASH:
00111                      return (__hash_open(fname, flags & USE_OPEN_FLAGS,
00112                          mode, (const HASHINFO *)openinfo, flags & DB_FLAGS));
00113               default:
00114                      break;
00115               }
00116        errno = EINVAL;
00117        return (NULL);
00118 }
00119 
00120 static int
00121 __dberr()
00122 {
00123        return (RET_ERROR);
00124 }
00125 
00126 /*
00127  * __DBPANIC -- Stop.
00128  *
00129  * Parameters:
00130  *     dbp:   pointer to the DB structure.
00131  */
00132 void
00133 __dbpanic(DB *dbp)
00134 {
00135        /* The only thing that can succeed is a close. */
00136        dbp->del = (int (*)(const struct __db *, const DBT *, uint))__dberr;
00137        dbp->fd = (int (*)(const struct __db *))__dberr;
00138        dbp->get = (int (*)(const struct __db *, const DBT *, DBT *, uint))__dberr;
00139        dbp->put = (int (*)(const struct __db *, DBT *, const DBT *, uint))__dberr;
00140        dbp->seq = (int (*)(const struct __db *, DBT *, DBT *, uint))__dberr;
00141        dbp->sync = (int (*)(const struct __db *, uint))__dberr;
00142 }