1 /*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)db.c 8.3 (Berkeley) 09/13/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/types.h> 13 14 #include <errno.h> 15 #include <fcntl.h> 16 #include <stddef.h> 17 #include <stdio.h> 18 19 #define __DBINTERFACE_PRIVATE 20 #include <db.h> 21 22 DB * 23 dbopen(fname, flags, mode, type, openinfo) 24 const char *fname; 25 int flags, mode; 26 DBTYPE type; 27 const void *openinfo; 28 { 29 30 #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) 31 #define USE_OPEN_FLAGS \ 32 (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ 33 O_RDWR | O_SHLOCK | O_TRUNC) 34 35 if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) 36 switch (type) { 37 case DB_BTREE: 38 return (__bt_open(fname, flags & USE_OPEN_FLAGS, 39 mode, openinfo, flags & DB_FLAGS)); 40 case DB_HASH: 41 return (__hash_open(fname, flags & USE_OPEN_FLAGS, 42 mode, openinfo, flags & DB_FLAGS)); 43 case DB_RECNO: 44 return (__rec_open(fname, flags & USE_OPEN_FLAGS, 45 mode, openinfo, flags & DB_FLAGS)); 46 } 47 errno = EINVAL; 48 return (NULL); 49 } 50 51 static int 52 __dberr() 53 { 54 return (RET_ERROR); 55 } 56 57 /* 58 * __DBPANIC -- Stop. 59 * 60 * Parameters: 61 * dbp: pointer to the DB structure. 62 */ 63 void 64 __dbpanic(dbp) 65 DB *dbp; 66 { 67 /* The only thing that can succeed is a close. */ 68 dbp->del = (int (*)())__dberr; 69 dbp->fd = (int (*)())__dberr; 70 dbp->get = (int (*)())__dberr; 71 dbp->put = (int (*)())__dberr; 72 dbp->seq = (int (*)())__dberr; 73 dbp->sync = (int (*)())__dberr; 74 } 75