Example #1
0
File: db.c Project: ryo/netbsd-src
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_NONBLOCK | O_RDONLY |		\
	 O_RDWR | O_SHLOCK | 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, (int)(flags & DB_FLAGS)));
        case DB_HASH:
            return (__hash_open(fname, flags & USE_OPEN_FLAGS,
                                mode, openinfo, (int)(flags & DB_FLAGS)));
        case DB_RECNO:
            return (__rec_open(fname, flags & USE_OPEN_FLAGS,
                               mode, openinfo, (int)(flags & DB_FLAGS)));
        }
    errno = EINVAL;
    return (NULL);
}
Example #2
0
extern int
hcreate(uint nel)
{
	HASHINFO info;

	info.nelem = nel;
	info.bsize = 256;
	info.ffactor = 8;
	info.cachesize = 0;
	info.hash = NULL;
	info.lorder = 0;
	dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0);
	return ((int)dbp);
}
Example #3
0
/*
 * Returns:
 * 	*DBM on success
 *	 NULL on failure
 */
extern DBM *
dbm_open(const char *file, int flags, int mode)
{
	HASHINFO info;
	char path[MAXPATHLEN];

	info.bsize = 4096;
	info.ffactor = 40;
	info.nelem = 1;
	info.cachesize = 0;
	info.hash = NULL;
	info.lorder = 0;
	(void)strcpy(path, file);
	(void)strcat(path, DBM_SUFFIX);
	return ((DBM *)__hash_open(path, flags, mode, &info, 0));
}
Example #4
0
DB *
dbopen(const char *fname, int flags, int 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)

	if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0)
		switch (type) {
		case DB_HASH:
			return (__hash_open(fname, flags & USE_OPEN_FLAGS,
			    mode, openinfo, flags & DB_FLAGS));
		default:
			break;
		}
	errno = EINVAL;
	return (NULL);
}
Example #5
0
/*
 * Returns:
 * 	*DBM on success
 *	 NULL on failure
 */
extern DBM *
dbm_open(const char *file, int flags, mode_t mode)
{
	HASHINFO info;
	char path[MAXPATHLEN];

	info.bsize = 4096;
	info.ffactor = 40;
	info.nelem = 1;
	info.cachesize = 0;
	info.hash = NULL;
	info.lorder = 0;

	if( strlen(file) >= sizeof(path) - strlen(DBM_SUFFIX)) {
		errno = ENAMETOOLONG;
		return(NULL);
	}
	(void)strcpy(path, file);
	(void)strcat(path, DBM_SUFFIX);
	return ((DBM *)__hash_open(path, flags, mode, &info, 0));
}