- if ( hdrsize == -1 ) {
- RETURN_ERROR(errno, error1);
- }
- if ( hdrsize != sizeof(HASHHDR) ) {
- RETURN_ERROR(EFTYPE, error1);
- }
-
- /* Verify file type, versions and hash function */
- if ( hashp->MAGIC != HASHMAGIC )
- RETURN_ERROR ( EFTYPE, error1 );
- if ( hashp->VERSION != VERSION_NO )
- RETURN_ERROR ( EFTYPE, error1 );
- if (hashp->hash ( CHARKEY, sizeof(CHARKEY) ) != hashp->H_CHARKEY ) {
- RETURN_ERROR ( EFTYPE, error1 );
- }
-
- /*
- Figure out how many segments we need.
- */
- nsegs = (hashp->MAX_BUCKET + hashp->SGSIZE -1)/ hashp->SGSIZE;
- hashp->nsegs = 0;
- if (alloc_segs( nsegs )) {
- /*
- If alloc_segs fails, table will have been destroyed
- and errno will have been set.
- */
- return( (DB *) NULL );
- }
-
- /* Read in bitmaps */
- bpages = (hashp->SPARES[__log2(hashp->MAX_BUCKET)] +
- (hashp->BSIZE << BYTE_SHIFT) - 1) >>
- (hashp->BSHIFT + BYTE_SHIFT);
-
- hashp->mapp[0] = (u_long *)malloc(bpages<<hashp->BSHIFT);
- if ( !hashp->mapp[0] ) {
- RETURN_ERROR(errno, error2);
- }
- for ( i = 0; i < bpages; i++ ) {
- hashp->mapp[i] = &hashp->mapp[0][i<<hashp->BSHIFT];
- if (__get_page ((char *)hashp->mapp[i],
- hashp->BITMAPS[i], 0, 1, 1)) {
- RETURN_ERROR(errno, error2);
- }
- }
-
- }
-
- /* Initialize Buffer Manager */
- if ( info && info->ncached ) {
- __buf_init (info->ncached);
- } else {
- __buf_init (DEF_BUFSIZE);
- }
-
- hashp->new_file = new_table;
- hashp->save_file = file && !(hashp->flags&O_RDONLY);
- hashp->cbucket = -1;
- if ( !(dbp = (DB *)malloc ( sizeof (DB) )) ) {
- save_errno = errno;
- hdestroy();
- errno = save_errno;
- return ( NULL );
- }
- dbp->internal = (char *)hashp;
- dbp->close = hash_close;
- dbp->delete = hash_delete;
- dbp->get = hash_get;
- dbp->put = hash_put;
- dbp->seq = hash_seq;
- dbp->sync = hash_sync;
+ if (hdrsize == -1)
+ RETURN_ERROR(errno, error1);
+ if (hdrsize != sizeof(HASHHDR))
+ RETURN_ERROR(EFTYPE, error1);
+ /* Verify file type, versions and hash function */
+ if (hashp->MAGIC != HASHMAGIC)
+ RETURN_ERROR(EFTYPE, error1);
+ if (hashp->VERSION != HASHVERSION)
+ RETURN_ERROR(EFTYPE, error1);
+ if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY)
+ RETURN_ERROR(EFTYPE, error1);
+ /*
+ * Figure out how many segments we need. Max_Bucket is the
+ * maximum bucket number, so the number of buckets is
+ * max_bucket + 1.
+ */
+ nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) /
+ hashp->SGSIZE;
+ hashp->nsegs = 0;
+ if (alloc_segs(hashp, nsegs))
+ /*
+ * If alloc_segs fails, table will have been destroyed
+ * and errno will have been set.
+ */
+ return (NULL);
+ /* Read in bitmaps */
+ bpages = (hashp->SPARES[hashp->OVFL_POINT] +
+ (hashp->BSIZE << BYTE_SHIFT) - 1) >>
+ (hashp->BSHIFT + BYTE_SHIFT);
+
+ hashp->nmaps = bpages;
+ (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_long *));
+ }
+
+ /* Initialize Buffer Manager */
+ if (info && info->cachesize)
+ __buf_init(hashp, info->cachesize);
+ else
+ __buf_init(hashp, DEF_BUFSIZE);
+
+ hashp->new_file = new_table;
+ hashp->save_file = file && (hashp->flags & O_RDWR);
+ hashp->cbucket = -1;
+ if (!(dbp = malloc(sizeof(DB)))) {
+ save_errno = errno;
+ hdestroy(hashp);
+ errno = save_errno;
+ return (NULL);
+ }
+ dbp->internal = hashp;
+ dbp->close = hash_close;
+ dbp->del = hash_delete;
+ dbp->fd = hash_fd;
+ dbp->get = hash_get;
+ dbp->put = hash_put;
+ dbp->seq = hash_seq;
+ dbp->sync = hash_sync;
+ dbp->type = DB_HASH;