#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <db.h>
static int __dberr(void);
static int __dberr_del(const struct __db *, const DBT *, unsigned int);
static int __dberr_fd(const struct __db *);
static int __dberr_get(const struct __db *, const DBT *, DBT *, unsigned int);
static int __dberr_put(const struct __db *, DBT *, const DBT *, unsigned int);
static int __dberr_seq(const struct __db *, DBT *, DBT *, unsigned int);
static int __dberr_sync(const struct __db *, unsigned int);
DB *
dbopen(const char *fname, int flags, mode_t mode, DBTYPE type, const void *openinfo)
{
#define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN)
#define USE_OPEN_FLAGS \
(O_CREAT | O_EXCL | O_EXLOCK | O_NOFOLLOW | O_NONBLOCK | \
O_RDONLY | O_RDWR | O_SHLOCK | O_SYNC | O_TRUNC | O_CLOEXEC)
if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0)
switch (type) {
case DB_BTREE:
return (__bt_open(fname, flags & USE_OPEN_FLAGS,
mode, openinfo, flags & DB_FLAGS));
case DB_HASH:
return (__hash_open(fname, flags & USE_OPEN_FLAGS,
mode, openinfo, flags & DB_FLAGS));
case DB_RECNO:
return (__rec_open(fname, flags & USE_OPEN_FLAGS,
mode, openinfo, flags & DB_FLAGS));
}
errno = EINVAL;
return (NULL);
}
static int
__dberr(void)
{
return (RET_ERROR);
}
static int
__dberr_del(const struct __db *dbp __unused, const DBT *key __unused,
unsigned int flags __unused)
{
return (__dberr());
}
static int
__dberr_fd(const struct __db *dbp __unused)
{
return (__dberr());
}
static int
__dberr_get(const struct __db *dbp __unused, const DBT *key __unused,
DBT *data __unused, unsigned int flag __unused)
{
return (__dberr());
}
static int
__dberr_put(const struct __db *dbp __unused, DBT *key __unused,
const DBT *data __unused, unsigned int flag __unused)
{
return (__dberr());
}
static int
__dberr_seq(const struct __db *dbp __unused, DBT *key __unused,
DBT *data __unused, unsigned int flag __unused)
{
return (__dberr());
}
static int
__dberr_sync(const struct __db *dbp __unused, unsigned int flags __unused)
{
return (__dberr());
}
void
__dbpanic(DB *dbp)
{
dbp->del = __dberr_del;
dbp->fd = __dberr_fd;
dbp->get = __dberr_get;
dbp->put = __dberr_put;
dbp->seq = __dberr_seq;
dbp->sync = __dberr_sync;
}