utils/db1-ast/db/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. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  * This product includes software developed by the University of
00016  * California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  */
00033 
00034 #if defined(LIBC_SCCS) && !defined(lint)
00035 static char sccsid[] = "@(#)db.c 8.4 (Berkeley) 2/21/94";
00036 #endif /* LIBC_SCCS and not lint */
00037 
00038 #include <sys/types.h>
00039 
00040 #include <errno.h>
00041 #include <fcntl.h>
00042 #include <stddef.h>
00043 #include <stdio.h>
00044 
00045 #include "../include/db.h"
00046 
00047 DB *
00048 dbopen(fname, flags, mode, type, openinfo)
00049    const char *fname;
00050    int flags, mode;
00051    DBTYPE type;
00052    const void *openinfo;
00053 {
00054 
00055 #define  DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN)
00056 #define  USE_OPEN_FLAGS                   \
00057    (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY |      \
00058     O_RDWR | O_SHLOCK | O_TRUNC)
00059 
00060    if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0)
00061       switch (type) {
00062       case DB_BTREE:
00063          return (__bt_open(fname, flags & USE_OPEN_FLAGS,
00064              mode, openinfo, flags & DB_FLAGS));
00065       case DB_HASH:
00066          return (__hash_open(fname, flags & USE_OPEN_FLAGS,
00067              mode, openinfo, flags & DB_FLAGS));
00068       case DB_RECNO:
00069          return (__rec_open(fname, flags & USE_OPEN_FLAGS,
00070              mode, openinfo, flags & DB_FLAGS));
00071       }
00072    errno = EINVAL;
00073    return (NULL);
00074 }
00075 
00076 static int
00077 __dberr __P((void))
00078 {
00079    return (RET_ERROR);
00080 }
00081 
00082 /*
00083  * __DBPANIC -- Stop.
00084  *
00085  * Parameters:
00086  * dbp:  pointer to the DB structure.
00087  */
00088 void
00089 __dbpanic(dbp)
00090    DB *dbp;
00091 {
00092    /* The only thing that can succeed is a close. */
00093    dbp->del = (int (*)__P((const struct __db *,
00094             const DBT *, u_int))) __dberr;
00095    dbp->get = (int (*)__P((const struct __db *,
00096             const DBT *, DBT *, u_int))) __dberr;
00097    dbp->put = (int (*)__P((const struct __db *,
00098             DBT *, const DBT *, u_int))) __dberr;
00099    dbp->seq = (int (*)__P((const struct __db *,
00100             DBT *, DBT *, u_int))) __dberr;
00101    dbp->sync = (int (*)__P((const struct __db *, u_int))) __dberr;
00102    dbp->fd = (int (*)__P((const struct __db *))) __dberr;
00103 }

Generated on Thu Apr 16 06:27:32 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6