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.4 (Berkeley) 02/21/94"; 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 #include <db.h> 20 21 DB * 22 dbopen(fname, flags, mode, type, openinfo) 23 const char *fname; 24 int flags, mode; 25 DBTYPE type; 26 const void *openinfo; 27 { 28 29 #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) 30 #define USE_OPEN_FLAGS \ 31 (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ 32 O_RDWR | O_SHLOCK | O_TRUNC) 33 34 if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) 35 switch (type) { 36 case DB_BTREE: 37 return (__bt_open(fname, flags & USE_OPEN_FLAGS, 38 mode, openinfo, flags & DB_FLAGS)); 39 case DB_HASH: 40 return (__hash_open(fname, flags & USE_OPEN_FLAGS, 41 mode, openinfo, flags & DB_FLAGS)); 42 case DB_RECNO: 43 return (__rec_open(fname, flags & USE_OPEN_FLAGS, 44 mode, openinfo, flags & DB_FLAGS)); 45 } 46 errno = EINVAL; 47 return (NULL); 48 } 49 50 static int 51 __dberr() 52 { 53 return (RET_ERROR); 54 } 55 56 /* 57 * __DBPANIC -- Stop. 58 * 59 * Parameters: 60 * dbp: pointer to the DB structure. 61 */ 62 void 63 __dbpanic(dbp) 64 DB *dbp; 65 { 66 /* The only thing that can succeed is a close. */ 67 dbp->del = (int (*)())__dberr; 68 dbp->fd = (int (*)())__dberr; 69 dbp->get = (int (*)())__dberr; 70 dbp->put = (int (*)())__dberr; 71 dbp->seq = (int (*)())__dberr; 72 dbp->sync = (int (*)())__dberr; 73 } 74