Deleted Added
sdiff udiff text old ( 190489 ) new ( 190491 )
full compact
1/*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Margo Seltzer.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/lib/libc/db/hash/hash.c 190489 2009-03-28 06:23:10Z delphij $");
38
39#include "namespace.h"
40#include <sys/param.h>
41#include <sys/stat.h>
42
43#include <errno.h>
44#include <fcntl.h>
45#include <stdio.h>

--- 488 unchanged lines hidden (view full) ---

534
535static int
536hash_put(const DB *dbp, DBT *key, const DBT *data, u_int32_t flag)
537{
538 HTAB *hashp;
539
540 hashp = (HTAB *)dbp->internal;
541 if (flag && flag != R_NOOVERWRITE) {
542 hashp->error = EINVAL;
543 errno = EINVAL;
544 return (ERROR);
545 }
546 if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
547 hashp->error = errno = EPERM;
548 return (ERROR);
549 }
550 return (hash_access(hashp, flag == R_NOOVERWRITE ?
551 HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data));

--- 162 unchanged lines hidden (view full) ---

714#ifdef HASH_STATISTICS
715 hash_accesses++;
716#endif
717 if ((hashp->cbucket < 0) || (flag == R_FIRST)) {
718 hashp->cbucket = 0;
719 hashp->cndx = 1;
720 hashp->cpage = NULL;
721 }
722
723 for (bp = NULL; !bp || !bp[0]; ) {
724 if (!(bufp = hashp->cpage)) {
725 for (bucket = hashp->cbucket;
726 bucket <= hashp->MAX_BUCKET;
727 bucket++, hashp->cndx = 1) {
728 bufp = __get_buf(hashp, bucket, NULL, 0);
729 if (!bufp)
730 return (ERROR);
731 hashp->cpage = bufp;
732 bp = (u_int16_t *)bufp->page;
733 if (bp[0])
734 break;
735 }
736 hashp->cbucket = bucket;
737 if ((u_int32_t)hashp->cbucket > hashp->MAX_BUCKET) {
738 hashp->cbucket = -1;
739 return (ABNORMAL);
740 }
741 } else
742 bp = (u_int16_t *)hashp->cpage->page;
743
744#ifdef DEBUG
745 assert(bp);
746 assert(bufp);
747#endif
748 while (bp[hashp->cndx + 1] == OVFLPAGE) {
749 bufp = hashp->cpage =
750 __get_buf(hashp, bp[hashp->cndx], bufp, 0);

--- 11 unchanged lines hidden (view full) ---

762 if (bp[ndx + 1] < REAL_KEY) {
763 if (__big_keydata(hashp, bufp, key, data, 1))
764 return (ERROR);
765 } else {
766 key->data = (u_char *)hashp->cpage->page + bp[ndx];
767 key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx];
768 data->data = (u_char *)hashp->cpage->page + bp[ndx + 1];
769 data->size = bp[ndx] - bp[ndx + 1];
770 ndx += 2;
771 if (ndx > bp[0]) {
772 hashp->cpage = NULL;
773 hashp->cbucket++;
774 hashp->cndx = 1;
775 } else
776 hashp->cndx = ndx;
777 }
778 return (SUCCESS);
779}
780
781/********************************* UTILITIES ************************/
782
783/*
784 * Returns:

--- 179 unchanged lines hidden ---