Change HASHINFO element ncached to cachesize for consistency
[unix-history] / usr / src / lib / libc / db / hash / hsearch.c
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Margo Seltzer.
*
* %sccs.include.redist.c%
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)hsearch.c 5.5 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <db.h>
#include "search.h"
static DB *dbp = NULL;
static ENTRY retval;
extern int
hcreate ( nel )
unsigned nel;
{
int status;
HASHINFO info;
info.nelem = nel;
info.bsize = 256;
info.ffactor = 8;
info.cachesize = NULL;
info.hash = NULL;
info.lorder = 0;
dbp = hash_open ( NULL, O_CREAT|O_RDWR, 0600, &info );
return ( (int) dbp );
}
extern ENTRY *
hsearch ( item, action )
ENTRY item;
ACTION action;
{
int status;
DBT key, val;
if ( !dbp ) {
return(NULL);
}
key.data = (u_char *)item.key;
key.size = strlen(item.key) + 1;
if ( action == ENTER ) {
val.data = (u_char *)item.data;
val.size = strlen(item.data) + 1;
status = (dbp->put) ( dbp, &key, &val, R_NOOVERWRITE );
if ( status ) {
return(NULL);
}
} else {
/* FIND */
status = (dbp->get) ( dbp, &key, &val, 0 );
if ( status ) {
return ( NULL );
} else {
item.data = (char *)val.data;
}
}
retval.key = item.key;
retval.data = item.data;
return ( &retval );
}
extern void
hdestroy ()
{
if (dbp) {
(void)(dbp->close) (dbp);
dbp = NULL;
}
return;
}