diff options
author | pst <pst@FreeBSD.org> | 1996-02-27 19:42:00 +0000 |
---|---|---|
committer | pst <pst@FreeBSD.org> | 1996-02-27 19:42:00 +0000 |
commit | 912836fc11fb14d3f93b1bbd3d937daf0364a21f (patch) | |
tree | 282ca344758456835717d95b22f07b9d665d2134 /lib/libc/db/hash | |
parent | 221f5fcda8cae5ef7821d99fddd45a0d52a012f2 (diff) | |
download | FreeBSD-src-912836fc11fb14d3f93b1bbd3d937daf0364a21f.zip FreeBSD-src-912836fc11fb14d3f93b1bbd3d937daf0364a21f.tar.gz |
Fix conflicts and merge into mainline
Diffstat (limited to 'lib/libc/db/hash')
-rw-r--r-- | lib/libc/db/hash/hash.c | 56 | ||||
-rw-r--r-- | lib/libc/db/hash/hash.h | 125 | ||||
-rw-r--r-- | lib/libc/db/hash/hash_page.c | 170 | ||||
-rw-r--r-- | lib/libc/db/hash/ndbm.c | 6 |
4 files changed, 183 insertions, 174 deletions
diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c index d2707cd..68176e4 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993 + * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash.c 8.7 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -60,13 +60,13 @@ static int alloc_segs __P((HTAB *, int)); static int flush_meta __P((HTAB *)); static int hash_access __P((HTAB *, ACTION, DBT *, DBT *)); static int hash_close __P((DB *)); -static int hash_delete __P((const DB *, const DBT *, u_int)); +static int hash_delete __P((const DB *, const DBT *, u_int32_t)); static int hash_fd __P((const DB *)); -static int hash_get __P((const DB *, const DBT *, DBT *, u_int)); -static int hash_put __P((const DB *, DBT *, const DBT *, u_int)); +static int hash_get __P((const DB *, const DBT *, DBT *, u_int32_t)); +static int hash_put __P((const DB *, DBT *, const DBT *, u_int32_t)); static void *hash_realloc __P((SEGMENT **, int, int)); -static int hash_seq __P((const DB *, DBT *, DBT *, u_int)); -static int hash_sync __P((const DB *, u_int)); +static int hash_seq __P((const DB *, DBT *, DBT *, u_int32_t)); +static int hash_sync __P((const DB *, u_int32_t)); static int hdestroy __P((HTAB *)); static HTAB *init_hash __P((HTAB *, const char *, HASHINFO *)); static int init_htab __P((HTAB *, int)); @@ -86,7 +86,7 @@ static void swap_header_copy __P((HASHHDR *, HASHHDR *)); #define ABNORMAL (1) #ifdef HASH_STATISTICS -long hash_accesses, hash_collisions, hash_expansions, hash_overflows; +int hash_accesses, hash_collisions, hash_expansions, hash_overflows; #endif /************************** INTERFACE ROUTINES ***************************/ @@ -186,7 +186,7 @@ __hash_open(file, flags, mode, info, dflags) (hashp->BSHIFT + BYTE_SHIFT); hashp->nmaps = bpages; - (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_long *)); + (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *)); } /* Initialize Buffer Manager */ @@ -373,7 +373,7 @@ init_htab(hashp, nelem) hashp->LAST_FREED = 2; /* First bitmap page is at: splitpoint l2 page offset 1 */ - if (__init_bitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) + if (__ibitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) return (-1); hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1; @@ -458,7 +458,7 @@ hdestroy(hashp) static int hash_sync(dbp, flags) const DB *dbp; - u_int flags; + u_int32_t flags; { HTAB *hashp; @@ -537,7 +537,7 @@ hash_get(dbp, key, data, flag) const DB *dbp; const DBT *key; DBT *data; - u_int flag; + u_int32_t flag; { HTAB *hashp; @@ -554,7 +554,7 @@ hash_put(dbp, key, data, flag) const DB *dbp; DBT *key; const DBT *data; - u_int flag; + u_int32_t flag; { HTAB *hashp; @@ -575,7 +575,7 @@ static int hash_delete(dbp, key, flag) const DB *dbp; const DBT *key; - u_int flag; /* Ignored */ + u_int32_t flag; /* Ignored */ { HTAB *hashp; @@ -602,10 +602,10 @@ hash_access(hashp, action, key, val) { register BUFHEAD *rbufp; BUFHEAD *bufp, *save_bufp; - register u_short *bp; + register u_int16_t *bp; register int n, ndx, off, size; register char *kp; - u_short pageno; + u_int16_t pageno; #ifdef HASH_STATISTICS hash_accesses++; @@ -621,7 +621,7 @@ hash_access(hashp, action, key, val) /* Pin the bucket chain */ rbufp->flags |= BUF_PIN; - for (bp = (u_short *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) + for (bp = (u_int16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) if (bp[1] >= REAL_KEY) { /* Real key/data pair */ if (size == off - *bp && @@ -640,7 +640,7 @@ hash_access(hashp, action, key, val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_short *)rbufp->page; + bp = (u_int16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -662,7 +662,7 @@ hash_access(hashp, action, key, val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_short *)rbufp->page; + bp = (u_int16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -696,7 +696,7 @@ found: save_bufp->flags &= ~BUF_PIN; return (ABNORMAL); case HASH_GET: - bp = (u_short *)rbufp->page; + bp = (u_int16_t *)rbufp->page; if (bp[ndx + 1] < REAL_KEY) { if (__big_return(hashp, rbufp, ndx, val, 0)) return (ERROR); @@ -727,12 +727,12 @@ static int hash_seq(dbp, key, data, flag) const DB *dbp; DBT *key, *data; - u_int flag; + u_int32_t flag; { - register u_int bucket; + register u_int32_t bucket; register BUFHEAD *bufp; HTAB *hashp; - u_short *bp, ndx; + u_int16_t *bp, ndx; hashp = (HTAB *)dbp->internal; if (flag && flag != R_FIRST && flag != R_NEXT) { @@ -757,7 +757,7 @@ hash_seq(dbp, key, data, flag) if (!bufp) return (ERROR); hashp->cpage = bufp; - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; if (bp[0]) break; } @@ -767,7 +767,7 @@ hash_seq(dbp, key, data, flag) return (ABNORMAL); } } else - bp = (u_short *)hashp->cpage->page; + bp = (u_int16_t *)hashp->cpage->page; #ifdef DEBUG assert(bp); @@ -778,7 +778,7 @@ hash_seq(dbp, key, data, flag) __get_buf(hashp, bp[hashp->cndx], bufp, 0); if (!bufp) return (ERROR); - bp = (u_short *)(bufp->page); + bp = (u_int16_t *)(bufp->page); hashp->cndx = 1; } if (!bp[0]) { @@ -817,7 +817,7 @@ extern int __expand_table(hashp) HTAB *hashp; { - u_int old_bucket, new_bucket; + u_int32_t old_bucket, new_bucket; int dirsize, new_segnum, spare_ndx; #ifdef HASH_STATISTICS @@ -884,7 +884,7 @@ hash_realloc(p_ptr, oldsize, newsize) return (p); } -extern u_int +extern u_int32_t __call_hash(hashp, k, len) HTAB *hashp; char *k; diff --git a/lib/libc/db/hash/hash.h b/lib/libc/db/hash/hash.h index 8664bd4..504a9b6 100644 --- a/lib/libc/db/hash/hash.h +++ b/lib/libc/db/hash/hash.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993 + * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)hash.h 8.2 (Berkeley) 2/21/94 + * @(#)hash.h 8.3 (Berkeley) 5/31/94 */ /* Operations */ @@ -45,12 +45,12 @@ typedef enum { typedef struct _bufhead BUFHEAD; struct _bufhead { - BUFHEAD *prev; /* LRU links */ - BUFHEAD *next; /* LRU links */ - BUFHEAD *ovfl; /* Overflow page buffer header */ - u_int addr; /* Address of this page */ - char *page; /* Actual page data */ - char flags; + BUFHEAD *prev; /* LRU links */ + BUFHEAD *next; /* LRU links */ + BUFHEAD *ovfl; /* Overflow page buffer header */ + u_int32_t addr; /* Address of this page */ + char *page; /* Actual page data */ + char flags; #define BUF_MOD 0x0001 #define BUF_DISK 0x0002 #define BUF_BUCKET 0x0004 @@ -62,51 +62,60 @@ struct _bufhead { typedef BUFHEAD **SEGMENT; /* Hash Table Information */ -typedef struct hashhdr { /* Disk resident portion */ - int magic; /* Magic NO for hash tables */ - int version; /* Version ID */ - long lorder; /* Byte Order */ - int bsize; /* Bucket/Page Size */ - int bshift; /* Bucket shift */ - int dsize; /* Directory Size */ - int ssize; /* Segment Size */ - int sshift; /* Segment shift */ - int ovfl_point; /* Where overflow pages are being allocated */ - int last_freed; /* Last overflow page freed */ - int max_bucket; /* ID of Maximum bucket in use */ - int high_mask; /* Mask to modulo into entire table */ - int low_mask; /* Mask to modulo into lower half of table */ - int ffactor; /* Fill factor */ - int nkeys; /* Number of keys in hash table */ - int hdrpages; /* Size of table header */ - int h_charkey; /* value of hash(CHARKEY) */ -#define NCACHED 32 /* number of bit maps and spare points */ - int spares[NCACHED];/* spare pages for overflow */ - u_short bitmaps[NCACHED]; /* address of overflow page bitmaps */ +typedef struct hashhdr { /* Disk resident portion */ + int magic; /* Magic NO for hash tables */ + int version; /* Version ID */ + u_int32_t lorder; /* Byte Order */ + int bsize; /* Bucket/Page Size */ + int bshift; /* Bucket shift */ + int dsize; /* Directory Size */ + int ssize; /* Segment Size */ + int sshift; /* Segment shift */ + int ovfl_point; /* Where overflow pages are being + * allocated */ + int last_freed; /* Last overflow page freed */ + int max_bucket; /* ID of Maximum bucket in use */ + int high_mask; /* Mask to modulo into entire table */ + int low_mask; /* Mask to modulo into lower half of + * table */ + int ffactor; /* Fill factor */ + int nkeys; /* Number of keys in hash table */ + int hdrpages; /* Size of table header */ + int h_charkey; /* value of hash(CHARKEY) */ +#define NCACHED 32 /* number of bit maps and spare + * points */ + int spares[NCACHED];/* spare pages for overflow */ + u_int16_t bitmaps[NCACHED]; /* address of overflow page + * bitmaps */ } HASHHDR; -typedef struct htab { /* Memory resident data structure */ - HASHHDR hdr; /* Header */ - int nsegs; /* Number of allocated segments */ - int exsegs; /* Number of extra allocated segments */ - u_int32_t /* Hash function */ +typedef struct htab { /* Memory resident data structure */ + HASHHDR hdr; /* Header */ + int nsegs; /* Number of allocated segments */ + int exsegs; /* Number of extra allocated + * segments */ + u_int32_t /* Hash function */ (*hash)__P((const void *, size_t)); - int flags; /* Flag values */ - int fp; /* File pointer */ - char *tmp_buf; /* Temporary Buffer for BIG data */ - char *tmp_key; /* Temporary Buffer for BIG keys */ - BUFHEAD *cpage; /* Current page */ - int cbucket; /* Current bucket */ - int cndx; /* Index of next item on cpage */ - int error; /* Error Number -- for DBM compatability */ - int new_file; /* Indicates if fd is backing store or no */ - int save_file; /* Indicates whether we need to flush file at - * exit */ - u_long *mapp[NCACHED]; /* Pointers to page maps */ - int nmaps; /* Initial number of bitmaps */ - int nbufs; /* Number of buffers left to allocate */ - BUFHEAD bufhead; /* Header of buffer lru list */ - SEGMENT *dir; /* Hash Bucket directory */ + int flags; /* Flag values */ + int fp; /* File pointer */ + char *tmp_buf; /* Temporary Buffer for BIG data */ + char *tmp_key; /* Temporary Buffer for BIG keys */ + BUFHEAD *cpage; /* Current page */ + int cbucket; /* Current bucket */ + int cndx; /* Index of next item on cpage */ + int error; /* Error Number -- for DBM + * compatability */ + int new_file; /* Indicates if fd is backing store + * or no */ + int save_file; /* Indicates whether we need to flush + * file at + * exit */ + u_int32_t *mapp[NCACHED]; /* Pointers to page maps */ + int nmaps; /* Initial number of bitmaps */ + int nbufs; /* Number of buffers left to + * allocate */ + BUFHEAD bufhead; /* Header of buffer lru list */ + SEGMENT *dir; /* Hash Bucket directory */ } HTAB; /* @@ -129,14 +138,14 @@ typedef struct htab { /* Memory resident data structure */ #define BYTE_SHIFT 3 #define INT_TO_BYTE 2 #define INT_BYTE_SHIFT 5 -#define ALL_SET ((u_int)0xFFFFFFFF) +#define ALL_SET ((u_int32_t)0xFFFFFFFF) #define ALL_CLEAR 0 -#define PTROF(X) ((BUFHEAD *)((u_int)(X)&~0x3)) -#define ISMOD(X) ((u_int)(X)&0x1) -#define DOMOD(X) ((X) = (char *)((u_int)(X)|0x1)) -#define ISDISK(X) ((u_int)(X)&0x2) -#define DODISK(X) ((X) = (char *)((u_int)(X)|0x2)) +#define PTROF(X) ((BUFHEAD *)((ptrdiff_t)(X)&~0x3)) +#define ISMOD(X) ((u_int32_t)(ptrdiff_t)(X)&0x1) +#define DOMOD(X) ((X) = (char *)((ptrdiff_t)(X)|0x1)) +#define ISDISK(X) ((u_int32_t)(ptrdiff_t)(X)&0x2) +#define DODISK(X) ((X) = (char *)((ptrdiff_t)(X)|0x2)) #define BITS_PER_MAP 32 @@ -156,9 +165,9 @@ typedef struct htab { /* Memory resident data structure */ #define SPLITSHIFT 11 #define SPLITMASK 0x7FF -#define SPLITNUM(N) (((u_int)(N)) >> SPLITSHIFT) +#define SPLITNUM(N) (((u_int32_t)(N)) >> SPLITSHIFT) #define OPAGENUM(N) ((N) & SPLITMASK) -#define OADDR_OF(S,O) ((u_int)((u_int)(S) << SPLITSHIFT) + (O)) +#define OADDR_OF(S,O) ((u_int32_t)((u_int32_t)(S) << SPLITSHIFT) + (O)) #define BUCKET_TO_PAGE(B) \ (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((B)+1)-1] : 0) diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 7b018cb..2c05090 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993 + * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_page.c 8.4 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -72,19 +72,19 @@ static char sccsid[] = "@(#)hash_page.c 8.4 (Berkeley) 2/21/94"; #include "page.h" #include "extern.h" -static u_long *fetch_bitmap __P((HTAB *, int)); -static u_long first_free __P((u_long)); +static u_int32_t *fetch_bitmap __P((HTAB *, int)); +static u_int32_t first_free __P((u_int32_t)); static int open_temp __P((HTAB *)); -static u_short overflow_page __P((HTAB *)); +static u_int16_t overflow_page __P((HTAB *)); static void putpair __P((char *, const DBT *, const DBT *)); -static void squeeze_key __P((u_short *, const DBT *, const DBT *)); +static void squeeze_key __P((u_int16_t *, const DBT *, const DBT *)); static int ugly_split - __P((HTAB *, u_int, BUFHEAD *, BUFHEAD *, int, int)); + __P((HTAB *, u_int32_t, BUFHEAD *, BUFHEAD *, int, int)); #define PAGE_INIT(P) { \ - ((u_short *)(P))[0] = 0; \ - ((u_short *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_short); \ - ((u_short *)(P))[2] = hashp->BSIZE; \ + ((u_int16_t *)(P))[0] = 0; \ + ((u_int16_t *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_int16_t); \ + ((u_int16_t *)(P))[2] = hashp->BSIZE; \ } /* @@ -97,9 +97,9 @@ putpair(p, key, val) char *p; const DBT *key, *val; { - register u_short *bp, n, off; + register u_int16_t *bp, n, off; - bp = (u_short *)p; + bp = (u_int16_t *)p; /* Enter the key first. */ n = bp[0]; @@ -115,7 +115,7 @@ putpair(p, key, val) /* Adjust page info. */ bp[0] = n; - bp[n + 1] = off - ((n + 3) * sizeof(u_short)); + bp[n + 1] = off - ((n + 3) * sizeof(u_int16_t)); bp[n + 2] = off; } @@ -130,11 +130,11 @@ __delpair(hashp, bufp, ndx) BUFHEAD *bufp; register int ndx; { - register u_short *bp, newoff; + register u_int16_t *bp, newoff; register int n; - u_short pairlen; + u_int16_t pairlen; - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; n = bp[0]; if (bp[ndx + 1] < REAL_KEY) @@ -165,7 +165,7 @@ __delpair(hashp, bufp, ndx) } /* Finally adjust the page data */ bp[n] = OFFSET(bp) + pairlen; - bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_short); + bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_int16_t); bp[0] = n - 2; hashp->NKEYS--; @@ -180,18 +180,18 @@ __delpair(hashp, bufp, ndx) extern int __split_page(hashp, obucket, nbucket) HTAB *hashp; - u_int obucket, nbucket; + u_int32_t obucket, nbucket; { register BUFHEAD *new_bufp, *old_bufp; - register u_short *ino; + register u_int16_t *ino; register char *np; DBT key, val; int n, ndx, retval; - u_short copyto, diff, off, moved; + u_int16_t copyto, diff, off, moved; char *op; - copyto = (u_short)hashp->BSIZE; - off = (u_short)hashp->BSIZE; + copyto = (u_int16_t)hashp->BSIZE; + off = (u_int16_t)hashp->BSIZE; old_bufp = __get_buf(hashp, obucket, NULL, 0); if (old_bufp == NULL) return (-1); @@ -202,7 +202,7 @@ __split_page(hashp, obucket, nbucket) old_bufp->flags |= (BUF_MOD | BUF_PIN); new_bufp->flags |= (BUF_MOD | BUF_PIN); - ino = (u_short *)(op = old_bufp->page); + ino = (u_int16_t *)(op = old_bufp->page); np = new_bufp->page; moved = 0; @@ -244,13 +244,13 @@ __split_page(hashp, obucket, nbucket) /* Now clean up the page */ ino[0] -= moved; - FREESPACE(ino) = copyto - sizeof(u_short) * (ino[0] + 3); + FREESPACE(ino) = copyto - sizeof(u_int16_t) * (ino[0] + 3); OFFSET(ino) = copyto; #ifdef DEBUG3 (void)fprintf(stderr, "split %d/%d\n", - ((u_short *)np)[0] / 2, - ((u_short *)op)[0] / 2); + ((u_int16_t *)np)[0] / 2, + ((u_int16_t *)op)[0] / 2); #endif /* unpin both pages */ old_bufp->flags &= ~BUF_PIN; @@ -276,28 +276,28 @@ __split_page(hashp, obucket, nbucket) static int ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) HTAB *hashp; - u_int obucket; /* Same as __split_page. */ + u_int32_t obucket; /* Same as __split_page. */ BUFHEAD *old_bufp, *new_bufp; int copyto; /* First byte on page which contains key/data values. */ int moved; /* Number of pairs moved to new page. */ { register BUFHEAD *bufp; /* Buffer header for ino */ - register u_short *ino; /* Page keys come off of */ - register u_short *np; /* New page */ - register u_short *op; /* Page keys go on to if they aren't moving */ + register u_int16_t *ino; /* Page keys come off of */ + register u_int16_t *np; /* New page */ + register u_int16_t *op; /* Page keys go on to if they aren't moving */ BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */ DBT key, val; SPLIT_RETURN ret; - u_short n, off, ov_addr, scopyto; + u_int16_t n, off, ov_addr, scopyto; char *cino; /* Character value of ino */ bufp = old_bufp; - ino = (u_short *)old_bufp->page; - np = (u_short *)new_bufp->page; - op = (u_short *)old_bufp->page; + ino = (u_int16_t *)old_bufp->page; + np = (u_int16_t *)new_bufp->page; + op = (u_int16_t *)old_bufp->page; last_bfp = NULL; - scopyto = (u_short)copyto; /* ANSI */ + scopyto = (u_int16_t)copyto; /* ANSI */ n = ino[0] - 1; while (n < ino[0]) { @@ -308,16 +308,16 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) old_bufp = ret.oldp; if (!old_bufp) return (-1); - op = (u_short *)old_bufp->page; + op = (u_int16_t *)old_bufp->page; new_bufp = ret.newp; if (!new_bufp) return (-1); - np = (u_short *)new_bufp->page; + np = (u_int16_t *)new_bufp->page; bufp = ret.nextp; if (!bufp) return (0); cino = (char *)bufp->page; - ino = (u_short *)cino; + ino = (u_int16_t *)cino; last_bfp = ret.nextp; } else if (ino[n + 1] == OVFLPAGE) { ov_addr = ino[n]; @@ -327,14 +327,14 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) */ ino[0] -= (moved + 2); FREESPACE(ino) = - scopyto - sizeof(u_short) * (ino[0] + 3); + scopyto - sizeof(u_int16_t) * (ino[0] + 3); OFFSET(ino) = scopyto; bufp = __get_buf(hashp, ov_addr, bufp, 0); if (!bufp) return (-1); - ino = (u_short *)bufp->page; + ino = (u_int16_t *)bufp->page; n = 1; scopyto = hashp->BSIZE; moved = 0; @@ -362,7 +362,7 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) __add_ovflpage(hashp, old_bufp); if (!old_bufp) return (-1); - op = (u_short *)old_bufp->page; + op = (u_int16_t *)old_bufp->page; putpair((char *)op, &key, &val); } old_bufp->flags |= BUF_MOD; @@ -375,7 +375,7 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) __add_ovflpage(hashp, new_bufp); if (!new_bufp) return (-1); - np = (u_short *)new_bufp->page; + np = (u_int16_t *)new_bufp->page; putpair((char *)np, &key, &val); } new_bufp->flags |= BUF_MOD; @@ -400,10 +400,10 @@ __addel(hashp, bufp, key, val) BUFHEAD *bufp; const DBT *key, *val; { - register u_short *bp, *sop; + register u_int16_t *bp, *sop; int do_expand; - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; do_expand = 0; while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY)) /* Exception case */ @@ -415,7 +415,7 @@ __addel(hashp, bufp, key, val) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; } else /* Try to squeeze key on this page */ if (FREESPACE(bp) > PAIRSIZE(key, val)) { @@ -425,7 +425,7 @@ __addel(hashp, bufp, key, val) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; } if (PAIRFITS(bp, key, val)) @@ -435,7 +435,7 @@ __addel(hashp, bufp, key, val) bufp = __add_ovflpage(hashp, bufp); if (!bufp) return (-1); - sop = (u_short *)bufp->page; + sop = (u_int16_t *)bufp->page; if (PAIRFITS(sop, key, val)) putpair((char *)sop, key, val); @@ -466,12 +466,12 @@ __add_ovflpage(hashp, bufp) HTAB *hashp; BUFHEAD *bufp; { - register u_short *sp; - u_short ndx, ovfl_num; + register u_int16_t *sp; + u_int16_t ndx, ovfl_num; #ifdef DEBUG1 int tmp1, tmp2; #endif - sp = (u_short *)bufp->page; + sp = (u_int16_t *)bufp->page; /* Check if we are dynamically determining the fill factor */ if (hashp->FFACTOR == DEF_FFACTOR) { @@ -518,12 +518,12 @@ extern int __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) HTAB *hashp; char *p; - u_int bucket; + u_int32_t bucket; int is_bucket, is_disk, is_bitmap; { register int fd, page, size; int rsize; - u_short *bp; + u_int16_t *bp; fd = hashp->fp; size = hashp->BSIZE; @@ -539,7 +539,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || ((rsize = read(fd, p, size)) == -1)) return (-1); - bp = (u_short *)p; + bp = (u_int16_t *)p; if (!rsize) bp[0] = 0; /* We hit the EOF, so initialize a new page */ else @@ -556,7 +556,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) - M_32_SWAP(((long *)p)[i]); + M_32_SWAP(((int *)p)[i]); } else { M_16_SWAP(bp[0]); max = bp[0] + 2; @@ -578,7 +578,7 @@ extern int __put_page(hashp, p, bucket, is_bucket, is_bitmap) HTAB *hashp; char *p; - u_int bucket; + u_int32_t bucket; int is_bucket, is_bitmap; { register int fd, page, size; @@ -596,11 +596,11 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) - M_32_SWAP(((long *)p)[i]); + M_32_SWAP(((int *)p)[i]); } else { - max = ((u_short *)p)[0] + 2; + max = ((u_int16_t *)p)[0] + 2; for (i = 0; i <= max; i++) - M_16_SWAP(((u_short *)p)[i]); + M_16_SWAP(((u_int16_t *)p)[i]); } } if (is_bucket) @@ -624,14 +624,14 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) * once they are read in. */ extern int -__init_bitmap(hashp, pnum, nbits, ndx) +__ibitmap(hashp, pnum, nbits, ndx) HTAB *hashp; int pnum, nbits, ndx; { - u_long *ip; + u_int32_t *ip; int clearbytes, clearints; - if ((ip = (u_long *)malloc(hashp->BSIZE)) == NULL) + if ((ip = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) return (1); hashp->nmaps++; clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1; @@ -641,16 +641,16 @@ __init_bitmap(hashp, pnum, nbits, ndx) hashp->BSIZE - clearbytes); ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK); SETBIT(ip, 0); - hashp->BITMAPS[ndx] = (u_short)pnum; + hashp->BITMAPS[ndx] = (u_int16_t)pnum; hashp->mapp[ndx] = ip; return (0); } -static u_long +static u_int32_t first_free(map) - u_long map; + u_int32_t map; { - register u_long i, mask; + register u_int32_t i, mask; mask = 0x1; for (i = 0; i < BITS_PER_MAP; i++) { @@ -661,13 +661,13 @@ first_free(map) return (i); } -static u_short +static u_int16_t overflow_page(hashp) HTAB *hashp; { - register u_long *freep; + register u_int32_t *freep; register int max_free, offset, splitnum; - u_short addr; + u_int16_t addr; int bit, first_page, free_bit, free_page, i, in_use_bits, j; #ifdef DEBUG2 int tmp1, tmp2; @@ -681,9 +681,9 @@ overflow_page(hashp) /* Look through all the free maps to find the first free block */ first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT); for ( i = first_page; i <= free_page; i++ ) { - if (!(freep = (u_long *)hashp->mapp[i]) && + if (!(freep = (u_int32_t *)hashp->mapp[i]) && !(freep = fetch_bitmap(hashp, i))) - return (NULL); + return (0); if (i == free_page) in_use_bits = free_bit; else @@ -713,7 +713,7 @@ overflow_page(hashp) if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); + return (0); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; @@ -726,7 +726,7 @@ overflow_page(hashp) free_page++; if (free_page >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); + return (0); } /* * This is tricky. The 1 indicates that you want the new page @@ -739,9 +739,9 @@ overflow_page(hashp) * don't have to if we tell init_bitmap not to leave it clear * in the first place. */ - if (__init_bitmap(hashp, (int)OADDR_OF(splitnum, offset), - 1, free_page)) - return (NULL); + if (__ibitmap(hashp, + (int)OADDR_OF(splitnum, offset), 1, free_page)) + return (0); hashp->SPARES[splitnum]++; #ifdef DEBUG2 free_bit = 2; @@ -751,7 +751,7 @@ overflow_page(hashp) if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); + return (0); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; @@ -795,7 +795,7 @@ found: for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++); offset = (i ? bit - hashp->SPARES[i - 1] : bit); if (offset >= SPLITMASK) - return (NULL); /* Out of overflow pages */ + return (0); /* Out of overflow pages */ addr = OADDR_OF(i, offset); #ifdef DEBUG2 (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", @@ -814,16 +814,16 @@ __free_ovflpage(hashp, obufp) HTAB *hashp; BUFHEAD *obufp; { - register u_short addr; - u_long *freep; + register u_int16_t addr; + u_int32_t *freep; int bit_address, free_page, free_bit; - u_short ndx; + u_int16_t ndx; addr = obufp->addr; #ifdef DEBUG1 (void)fprintf(stderr, "Freeing %d\n", addr); #endif - ndx = (((u_short)addr) >> SPLITSHIFT); + ndx = (((u_int16_t)addr) >> SPLITSHIFT); bit_address = (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1; if (bit_address < hashp->LAST_FREED) @@ -879,11 +879,11 @@ open_temp(hashp) */ static void squeeze_key(sp, key, val) - u_short *sp; + u_int16_t *sp; const DBT *key, *val; { register char *p; - u_short free_space, n, off, pageno; + u_int16_t free_space, n, off, pageno; p = (char *)sp; n = sp[0]; @@ -904,14 +904,14 @@ squeeze_key(sp, key, val) OFFSET(sp) = off; } -static u_long * +static u_int32_t * fetch_bitmap(hashp, ndx) HTAB *hashp; int ndx; { if (ndx >= hashp->nmaps) return (NULL); - if ((hashp->mapp[ndx] = (u_long *)malloc(hashp->BSIZE)) == NULL) + if ((hashp->mapp[ndx] = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) return (NULL); if (__get_page(hashp, (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) { diff --git a/lib/libc/db/hash/ndbm.c b/lib/libc/db/hash/ndbm.c index 2b54402..28adce4 100644 --- a/lib/libc/db/hash/ndbm.c +++ b/lib/libc/db/hash/ndbm.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ndbm.c 8.2 (Berkeley) 9/11/93"; +static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -45,10 +45,10 @@ static char sccsid[] = "@(#)ndbm.c 8.2 (Berkeley) 9/11/93"; #include <sys/param.h> -#include <ndbm.h> #include <stdio.h> #include <string.h> +#include <ndbm.h> #include "hash.h" /* @@ -67,7 +67,7 @@ dbm_open(file, flags, mode) info.bsize = 4096; info.ffactor = 40; info.nelem = 1; - info.cachesize = NULL; + info.cachesize = 0; info.hash = NULL; info.lorder = 0; (void)strcpy(path, file); |