Path: blob/main/crypto/krb5/src/plugins/kdb/db2/libdb2/hash/hsearch.c
34928 views
/*-1* Copyright (c) 1990, 19932* The Regents of the University of California. All rights reserved.3*4* This code is derived from software contributed to Berkeley by5* Margo Seltzer.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15* 3. All advertising materials mentioning features or use of this software16* must display the following acknowledgement:17* This product includes software developed by the University of18* California, Berkeley and its contributors.19* 4. Neither the name of the University nor the names of its contributors20* may be used to endorse or promote products derived from this software21* without specific prior written permission.22*23* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33* SUCH DAMAGE.34*/3536#if defined(LIBC_SCCS) && !defined(lint)37static char sccsid[] = "@(#)hsearch.c 8.5 (Berkeley) 9/21/94";38#endif /* LIBC_SCCS and not lint */3940#include <sys/types.h>4142#include <fcntl.h>43#include <string.h>4445#include "db-int.h"46#include "search.h"4748static DB *dbp = NULL;49static ENTRY retval;5051extern int52hcreate(u_int nel)53{54HASHINFO info;5556info.nelem = nel;57info.bsize = 256;58info.ffactor = 8;59info.cachesize = 0;60info.hash = NULL;61info.lorder = 0;62dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR | O_BINARY, 0600, &info, 0);63return (dbp != NULL);64}6566extern ENTRY *67hsearch(ENTRY item, ACTION action)68{69DBT key, val;70int status;7172if (!dbp)73return (NULL);74key.data = (u_char *)item.key;75key.size = strlen(item.key) + 1;7677if (action == ENTER) {78val.data = (u_char *)item.data;79val.size = strlen(item.data) + 1;80status = (dbp->put)(dbp, &key, &val, R_NOOVERWRITE);81if (status)82return (NULL);83} else {84/* FIND */85status = (dbp->get)(dbp, &key, &val, 0);86if (status)87return (NULL);88else89item.data = (char *)val.data;90}91retval.key = item.key;92retval.data = item.data;93return (&retval);94}9596extern void97hdestroy(void)98{99if (dbp) {100(void)(dbp->close)(dbp);101dbp = NULL;102}103}104105106