nhash.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * Common Development and Distribution License (the "License").
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
0d8fa8f8eba3ea46bc79d73445009505d1dd5d7dMartin Matuska * Use is subject to license terms.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#define bcopy(a, b, c) (void) memmove(b, a, c)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#else /* _KERNEL */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#endif /* _KERNEL */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens return (bcmp((char *)str1, (char *)str2, len));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* determine starting and ending positions */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* compute hash over all characters from start to end */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens /* return computed hash */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens int (*hfunc)(void *, int, int), int (*cfunc)(void *, void *, int))
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens if ((*cp = (Cache *) malloc(sizeof (**cp))) == NULL) {
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) fprintf(stderr, pkg_gt("malloc(Cache **cp)"));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (Bucket *) malloc(sizeof (*(*cp)->bp) * hsz)) == NULL) {
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (void) fprintf(stderr, pkg_gt("malloc(Bucket cp->bp)"));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * If cp is NULL, then init_cache() wasn't called. Quietly return the
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * error code and let the caller deal with it.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens bp = &cp->bp[(*cp->hfunc)(itemp->key, itemp->keyl, cp->hsz)];
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (Item **) malloc(sizeof (*bp->itempp) * cp->bsz);
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens (*cp->hfunc)(itemp->key, itemp->keyl, cp->hsz));
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#endif /* VERIFY_HASH_REALLOC */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#else /* !_KERNEL */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* _KERNEL */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If cp is NULL, then init_cache() wasn't called. Quietly return the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * error code and let the caller deal with it.
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby if (!(*cp->cfunc)((void *)bp->itempp[i]->key, datap, datalen)) {