apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr-util/dbm/sdbm sdbm.c
Date Mon, 30 Apr 2001 14:34:53 GMT
wrowe       01/04/30 07:34:53

  Modified:    dbm/sdbm sdbm.c
  Log:
    Formatting changes, no code change, so the next patches are legible
  
  Revision  Changes    Path
  1.12      +340 -350  apr-util/dbm/sdbm/sdbm.c
  
  Index: sdbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/sdbm/sdbm.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- sdbm.c	2001/04/30 13:48:49	1.11
  +++ sdbm.c	2001/04/30 14:34:53	1.12
  @@ -99,14 +99,14 @@
   #define OFF_DIR(off)	(apr_off_t) (off) * DBLKSIZ
   
   static long masks[] = {
  -	000000000000, 000000000001, 000000000003, 000000000007,
  -	000000000017, 000000000037, 000000000077, 000000000177,
  -	000000000377, 000000000777, 000000001777, 000000003777,
  -	000000007777, 000000017777, 000000037777, 000000077777,
  -	000000177777, 000000377777, 000000777777, 000001777777,
  -	000003777777, 000007777777, 000017777777, 000037777777,
  -	000077777777, 000177777777, 000377777777, 000777777777,
  -	001777777777, 003777777777, 007777777777, 017777777777
  +        000000000000, 000000000001, 000000000003, 000000000007,
  +        000000000017, 000000000037, 000000000077, 000000000177,
  +        000000000377, 000000000777, 000000001777, 000000003777,
  +        000000007777, 000000017777, 000000037777, 000000077777,
  +        000000177777, 000000377777, 000000777777, 000001777777,
  +        000003777777, 000007777777, 000017777777, 000037777777,
  +        000077777777, 000177777777, 000377777777, 000777777777,
  +        001777777777, 003777777777, 007777777777, 017777777777
   };
   
   const sdbm_datum sdbm_nullitem = { NULL, 0 };
  @@ -123,8 +123,8 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t
  -sdbm_open(SDBM **db, const char *file, apr_int32_t flags, apr_fileperms_t perms, apr_pool_t
*p)
  +apr_status_t sdbm_open(SDBM **db, const char *file, apr_int32_t flags, 
  +                       apr_fileperms_t perms, apr_pool_t *p)
   {
       char *dirname = apr_pstrcat(p, file, SDBM_DIRFEXT, NULL);
       char *pagname = apr_pstrcat(p, file, SDBM_PAGFEXT, NULL);
  @@ -132,101 +132,98 @@
       return sdbm_prep(db, dirname, pagname, flags, perms, p);
   }
   
  -apr_status_t
  -sdbm_prep(SDBM **pdb, const char *dirname, const char *pagname, 
  -	  apr_int32_t flags, apr_fileperms_t perms, apr_pool_t *p)
  +apr_status_t sdbm_prep(SDBM **pdb, const char *dirname, const char *pagname,
  +                       apr_int32_t flags, apr_fileperms_t perms, apr_pool_t *p)
   {
  -        SDBM *db;
  -        apr_finfo_t finfo;
  -	apr_status_t status;
  +    SDBM *db;
  +    apr_finfo_t finfo;
  +    apr_status_t status;
   
  -        *pdb = NULL;
  +    *pdb = NULL;
   
  -	db = malloc(sizeof(*db));
  -        memset(db, 0, sizeof(*db));
  +    db = malloc(sizeof(*db));
  +    memset(db, 0, sizeof(*db));
   
  -	db->pool = p;
  +    db->pool = p;
   
  -        /*
  -         * adjust user flags so that WRONLY becomes RDWR, 
  -         * as required by this package. Also set our internal
  -         * flag for RDONLY if needed.
  -         */
  -	if (!(flags & APR_WRITE)) {
  -	    db->flags = SDBM_RDONLY;
  -	}
  +    /*
  +     * adjust user flags so that WRONLY becomes RDWR, 
  +     * as required by this package. Also set our internal
  +     * flag for RDONLY if needed.
  +     */
  +    if (!(flags & APR_WRITE)) {
  +        db->flags = SDBM_RDONLY;
  +    }
   
  -	flags |= APR_BINARY | APR_READ;
  +    flags |= APR_BINARY | APR_READ;
   
  -        /*
  -         * open the files in sequence, and stat the dirfile.
  -         * If we fail anywhere, undo everything, return NULL.
  -         */
  +    /*
  +     * open the files in sequence, and stat the dirfile.
  +     * If we fail anywhere, undo everything, return NULL.
  +     */
   
  -	if ((status = apr_file_open(&db->pagf, pagname, flags, perms, p))
  -	    != APR_SUCCESS)
  -            goto error;
  +    if ((status = apr_file_open(&db->pagf, pagname, flags, perms, p))
  +                != APR_SUCCESS)
  +        goto error;
   
  -        if ((status = sdbm_lock(db, !(db->flags & SDBM_RDONLY)))
  -            != APR_SUCCESS)
  -            goto error;
  +    if ((status = sdbm_lock(db, !(db->flags & SDBM_RDONLY)))
  +                != APR_SUCCESS)
  +        goto error;
   
  -        if ((status = apr_file_open(&db->dirf, dirname, flags, perms, p))
  -            != APR_SUCCESS)
  -            goto error;
  +    if ((status = apr_file_open(&db->dirf, dirname, flags, perms, p))
  +                != APR_SUCCESS)
  +        goto error;
   
  -        /*
  -         * need the dirfile size to establish max bit number.
  -         */
  -        if ((status = apr_file_info_get(&finfo, APR_FINFO_SIZE, db->dirf)) 
  +    /*
  +     * need the dirfile size to establish max bit number.
  +     */
  +    if ((status = apr_file_info_get(&finfo, APR_FINFO_SIZE, db->dirf)) 
                   != APR_SUCCESS)
  -            goto error;
  +        goto error;
   
  -        /*
  -         * zero size: either a fresh database, or one with a single,
  -         * unsplit data page: dirpage is all zeros.
  -         */
  -        db->dirbno = (!finfo.size) ? 0 : -1;
  -        db->pagbno = -1;
  -        db->maxbno = finfo.size * BYTESIZ;
  +    /*
  +     * zero size: either a fresh database, or one with a single,
  +     * unsplit data page: dirpage is all zeros.
  +     */
  +    db->dirbno = (!finfo.size) ? 0 : -1;
  +    db->pagbno = -1;
  +    db->maxbno = finfo.size * BYTESIZ;
   
  -        /* (apr_pcalloc zeroed the buffers) */
  +    /* (apr_pcalloc zeroed the buffers) */
   
  -        /* make sure that we close the database at some point */
  -        apr_pool_cleanup_register(p, db, database_cleanup, apr_pool_cleanup_null);
  +    /* make sure that we close the database at some point */
  +    apr_pool_cleanup_register(p, db, database_cleanup, apr_pool_cleanup_null);
   
  -        /* Done! */
  -        *pdb = db;
  -        return APR_SUCCESS;
  +    /* Done! */
  +    *pdb = db;
  +    return APR_SUCCESS;
   
  -  error:
  -        if (db->dirf != NULL)
  -            (void) apr_file_close(db->dirf);
  -        if (db->pagf != NULL) {
  -            (void) sdbm_unlock(db);
  -            (void) apr_file_close(db->pagf);
  -        }
  -        free(db);
  -        return status;
  +error:
  +    if (db->dirf != NULL)
  +        (void) apr_file_close(db->dirf);
  +    if (db->pagf != NULL) {
  +        (void) sdbm_unlock(db);
  +        (void) apr_file_close(db->pagf);
  +    }
  +    free(db);
  +    return status;
   }
   
  -void
  -sdbm_close(SDBM *db)
  +void sdbm_close(SDBM *db)
   {
       (void) apr_pool_cleanup_run(db->pool, db, database_cleanup);
   }
   
  -sdbm_datum
  -sdbm_fetch(SDBM *db, sdbm_datum key)
  +sdbm_datum sdbm_fetch(SDBM *db, sdbm_datum key)
   {
  -	if (db == NULL || bad(key))
  -		return sdbm_nullitem;
  +    if (db == NULL || bad(key))
  +        return sdbm_nullitem;
   
  -	if (getpage(db, exhash(key)) == APR_SUCCESS)
  -		return getpair(db->pagbuf, key);
  +    if (getpage(db, exhash(key)) == APR_SUCCESS)
  +        return getpair(db->pagbuf, key);
   
  -	ioerr(db);
  -	return sdbm_nullitem;
  +    ioerr(db);
  +    return sdbm_nullitem;
   }
   
   static apr_status_t write_page(SDBM *db, const char *buf, long pagno)
  @@ -235,95 +232,92 @@
       apr_off_t off = OFF_PAG(pagno);
       
       if ((status = apr_file_seek(db->pagf, APR_SET, &off)) != APR_SUCCESS ||
  -	(status = apr_file_write_full(db->pagf, buf, PBLKSIZ, NULL)) != APR_SUCCESS) {
  -	ioerr(db);
  -	return status;
  +        (status = apr_file_write_full(db->pagf, buf, PBLKSIZ, NULL)) 
  +                != APR_SUCCESS) {
  +        ioerr(db);
  +        return status;
       }
       
       return APR_SUCCESS;
   }
   
  -apr_status_t
  -sdbm_delete(SDBM *db, const sdbm_datum key)
  +apr_status_t sdbm_delete(SDBM *db, const sdbm_datum key)
   {
  -	apr_status_t status;
  +    apr_status_t status;
   
  -	if (db == NULL || bad(key))
  -		return APR_EINVAL;
  -	if (sdbm_rdonly(db))
  -		return APR_EINVAL;
  -
  -	if (getpage(db, exhash(key)) == APR_SUCCESS) {
  -		if (!delpair(db->pagbuf, key))
  -                        /* ### should we define some APRUTIL codes? */
  -			return APR_EGENERAL;
  -/*
  - * update the page file
  - */
  -		if ((status = write_page(db, db->pagbuf, db->pagbno)) != APR_SUCCESS)
  -		    return status;
  +    if (db == NULL || bad(key))
  +        return APR_EINVAL;
  +    if (sdbm_rdonly(db))
  +        return APR_EINVAL;
  +
  +    if (getpage(db, exhash(key)) == APR_SUCCESS) {
  +        if (!delpair(db->pagbuf, key))
  +            /* ### should we define some APRUTIL codes? */
  +            return APR_EGENERAL;
   
  +        /*
  +         * update the page file
  +         */
  +        if ((status = write_page(db, db->pagbuf, db->pagbno)) != APR_SUCCESS)
  +            return status;
   
  -		return APR_SUCCESS;
  -	}
  +        return APR_SUCCESS;
  +    }
   
  -	ioerr(db);
  -	return APR_EACCES;
  +    ioerr(db);
  +    return APR_EACCES;
   }
   
   apr_status_t sdbm_store(SDBM *db, sdbm_datum key, sdbm_datum val, int flags)
   {
  -	int need;
  -	register long hash;
  -	apr_status_t status;
  -
  -	if (db == NULL || bad(key))
  -		return APR_EINVAL;
  -	if (sdbm_rdonly(db))
  -		return APR_EINVAL;
  +    int need;
  +    register long hash;
  +    apr_status_t status;
   
  -	need = key.dsize + val.dsize;
  -/*
  - * is the pair too big (or too small) for this database ??
  - */
  -	if (need < 0 || need > PAIRMAX)
  -		return APR_EINVAL;
  +    if (db == NULL || bad(key))
  +        return APR_EINVAL;
  +    if (sdbm_rdonly(db))
  +        return APR_EINVAL;
  +
  +    need = key.dsize + val.dsize;
  +    /*
  +     * is the pair too big (or too small) for this database ??
  +     */
  +    if (need < 0 || need > PAIRMAX)
  +        return APR_EINVAL;
   
  -	if ((status = getpage(db, (hash = exhash(key)))) == APR_SUCCESS) {
  +    if ((status = getpage(db, (hash = exhash(key)))) == APR_SUCCESS) {
   
  -/*
  - * if we need to replace, delete the key/data pair
  - * first. If it is not there, ignore.
  - */
  -		if (flags == SDBM_REPLACE)
  -			(void) delpair(db->pagbuf, key);
  +        /*
  +         * if we need to replace, delete the key/data pair
  +         * first. If it is not there, ignore.
  +         */
  +        if (flags == SDBM_REPLACE)
  +            (void) delpair(db->pagbuf, key);
   #ifdef SEEDUPS
  -		else if (duppair(db->pagbuf, key))
  -			return APR_EEXIST;
  +        else if (duppair(db->pagbuf, key))
  +            return APR_EEXIST;
   #endif
  -/*
  - * if we do not have enough room, we have to split.
  - */
  -		if (!fitpair(db->pagbuf, need))
  -		    if ((status = makroom(db, hash, need)) != APR_SUCCESS)
  -			return status;
  -/*
  - * we have enough room or split is successful. insert the key,
  - * and update the page file.
  - */
  -		(void) putpair(db->pagbuf, key, val);
  +        /*
  +         * if we do not have enough room, we have to split.
  +         */
  +        if (!fitpair(db->pagbuf, need))
  +            if ((status = makroom(db, hash, need)) != APR_SUCCESS)
  +                return status;
  +        /*
  +         * we have enough room or split is successful. insert the key,
  +         * and update the page file.
  +         */
  +        (void) putpair(db->pagbuf, key, val);
   
  -		if ((status = write_page(db, db->pagbuf, db->pagbno)) != APR_SUCCESS)
  -		    return status;
  +        if ((status = write_page(db, db->pagbuf, db->pagbno)) != APR_SUCCESS)
  +            return status;
   
  -	/*
  -	 * success
  -	 */
  -		return APR_SUCCESS;
  -	}
  -	
  -	ioerr(db);
  -	return status;
  +        return APR_SUCCESS;
  +    }
  +    
  +    ioerr(db);
  +    return status;
   }
   
   /*
  @@ -331,77 +325,78 @@
    * this routine will attempt to make room for SPLTMAX times before
    * giving up.
    */
  -static apr_status_t
  -makroom(SDBM *db, long hash, int need)
  +static apr_status_t makroom(SDBM *db, long hash, int need)
   {
  -	long newp;
  -	char twin[PBLKSIZ];
  -	char *pag = db->pagbuf;
  -	char *new = twin;
  -	register int smax = SPLTMAX;
  -	apr_status_t status;
  +    long newp;
  +    char twin[PBLKSIZ];
  +    char *pag = db->pagbuf;
  +    char *new = twin;
  +    register int smax = SPLTMAX;
  +    apr_status_t status;
   
  -	do {
  -/*
  - * split the current page
  - */
  -		(void) splpage(pag, new, db->hmask + 1);
  -/*
  - * address of the new page
  - */
  -		newp = (hash & db->hmask) | (db->hmask + 1);
  +    do {
  +        /*
  +         * split the current page
  +         */
  +        (void) splpage(pag, new, db->hmask + 1);
  +        /*
  +         * address of the new page
  +         */
  +        newp = (hash & db->hmask) | (db->hmask + 1);
   
  -/*
  - * write delay, read avoidence/cache shuffle:
  - * select the page for incoming pair: if key is to go to the new page,
  - * write out the previous one, and copy the new one over, thus making
  - * it the current page. If not, simply write the new page, and we are
  - * still looking at the page of interest. current page is not updated
  - * here, as sdbm_store will do so, after it inserts the incoming pair.
  - */
  -		if (hash & (db->hmask + 1)) {
  -		    if ((status = write_page(db, db->pagbuf, db->pagbno)) != APR_SUCCESS)
  -			return status;
  -			    
  -		    db->pagbno = newp;
  -		    (void) memcpy(pag, new, PBLKSIZ);
  -		}
  -		else {
  -		    if ((status = write_page(db, new, newp)) != APR_SUCCESS)
  -			return status;
  -		}
  +        /*
  +         * write delay, read avoidence/cache shuffle:
  +         * select the page for incoming pair: if key is to go to the new page,
  +         * write out the previous one, and copy the new one over, thus making
  +         * it the current page. If not, simply write the new page, and we are
  +         * still looking at the page of interest. current page is not updated
  +         * here, as sdbm_store will do so, after it inserts the incoming pair.
  +         */
  +        if (hash & (db->hmask + 1)) {
  +            if ((status = write_page(db, db->pagbuf, db->pagbno)) 
  +                        != APR_SUCCESS)
  +                return status;
  +                    
  +            db->pagbno = newp;
  +            (void) memcpy(pag, new, PBLKSIZ);
  +        }
  +        else {
  +            if ((status = write_page(db, new, newp)) != APR_SUCCESS)
  +                return status;
  +        }
   
  -		if ((status = setdbit(db, db->curbit)) != APR_SUCCESS)
  -		    return status;
  -/*
  - * see if we have enough room now
  - */
  -		if (fitpair(pag, need))
  -		    return APR_SUCCESS;
  -/*
  - * try again... update curbit and hmask as getpage would have
  - * done. because of our update of the current page, we do not
  - * need to read in anything. BUT we have to write the current
  - * [deferred] page out, as the window of failure is too great.
  - */
  -		db->curbit = 2 * db->curbit +
  -			((hash & (db->hmask + 1)) ? 2 : 1);
  -		db->hmask |= db->hmask + 1;
  -		
  -		if ((status = write_page(db, db->pagbuf, db->pagbno))
  -		    != APR_SUCCESS)
  -		    return status;
  -		
  -	} while (--smax);
  -/*
  - * if we are here, this is real bad news. After SPLTMAX splits,
  - * we still cannot fit the key. say goodnight.
  - */
  +        if ((status = setdbit(db, db->curbit)) != APR_SUCCESS)
  +            return status;
  +        /*
  +         * see if we have enough room now
  +         */
  +        if (fitpair(pag, need))
  +            return APR_SUCCESS;
  +        /*
  +         * try again... update curbit and hmask as getpage would have
  +         * done. because of our update of the current page, we do not
  +         * need to read in anything. BUT we have to write the current
  +         * [deferred] page out, as the window of failure is too great.
  +         */
  +        db->curbit = 2 * db->curbit
  +                   + ((hash & (db->hmask + 1)) ? 2 : 1);
  +        db->hmask |= db->hmask + 1;
  +            
  +        if ((status = write_page(db, db->pagbuf, db->pagbno))
  +                    != APR_SUCCESS)
  +            return status;
  +            
  +    } while (--smax);
  +
  +    /*
  +     * if we are here, this is real bad news. After SPLTMAX splits,
  +     * we still cannot fit the key. say goodnight.
  +     */
   #if 0
  -	(void) write(2, "sdbm: cannot insert after SPLTMAX attempts.\n", 44);
  +    (void) write(2, "sdbm: cannot insert after SPLTMAX attempts.\n", 44);
   #endif
  -	/* ### ENOSPC not really appropriate but better than nothing */
  -	return APR_ENOSPC;
  +    /* ### ENOSPC not really appropriate but better than nothing */
  +    return APR_ENOSPC;
   
   }
   
  @@ -410,18 +405,18 @@
    * If EOF is returned while reading, this is taken as success.
    */
   static apr_status_t read_from(apr_file_t *f, void *buf, 
  -			     apr_off_t off, apr_size_t len)
  +             apr_off_t off, apr_size_t len)
   {
       apr_status_t status;
   
       if ((status = apr_file_seek(f, APR_SET, &off)) != APR_SUCCESS ||
  -	((status = apr_file_read_full(f, buf, len, NULL)) != APR_SUCCESS)) {
  -	/* if EOF is reached, pretend we read all zero's */
  -	if (status == APR_EOF) {
  -	    memset(buf, 0, len);
  -	    status = APR_SUCCESS;
  -	}
  -	return status;
  +        ((status = apr_file_read_full(f, buf, len, NULL)) != APR_SUCCESS)) {
  +        /* if EOF is reached, pretend we read all zero's */
  +        if (status == APR_EOF) {
  +            memset(buf, 0, len);
  +            status = APR_SUCCESS;
  +        }
  +        return status;
       }
   
       return APR_SUCCESS;
  @@ -431,172 +426,167 @@
    * the following two routines will break if
    * deletions aren't taken into account. (ndbm bug)
    */
  -sdbm_datum
  -sdbm_firstkey(SDBM *db)
  +sdbm_datum sdbm_firstkey(SDBM *db)
   {
  -/*
  - * start at page 0
  - */
  -	if (read_from(db->pagf, db->pagbuf, OFF_PAG(0), PBLKSIZ) != APR_SUCCESS) {
  -	    ioerr(db);
  -	    return sdbm_nullitem;
  -	}
  +    /*
  +     * start at page 0
  +     */
  +    if (read_from(db->pagf, db->pagbuf, OFF_PAG(0), PBLKSIZ) != APR_SUCCESS) {
  +        ioerr(db);
  +        return sdbm_nullitem;
  +    }
   
  -	db->pagbno = 0;
  -	db->blkptr = 0;
  -	db->keyptr = 0;
  +    db->pagbno = 0;
  +    db->blkptr = 0;
  +    db->keyptr = 0;
   
  -	return getnext(db);
  +    return getnext(db);
   }
   
  -sdbm_datum
  -sdbm_nextkey(SDBM *db)
  +sdbm_datum sdbm_nextkey(SDBM *db)
   {
  -	return getnext(db);
  +    return getnext(db);
   }
   
   /*
    * all important binary tree traversal
    */
  -static apr_status_t
  -getpage(SDBM *db, long hash)
  +static apr_status_t getpage(SDBM *db, long hash)
   {
  -	register int hbit;
  -	register long dbit;
  -	register long pagb;
  -	apr_status_t status;
  -
  -	dbit = 0;
  -	hbit = 0;
  -	while (dbit < db->maxbno && getdbit(db, dbit))
  -		dbit = 2 * dbit + ((hash & (1 << hbit++)) ? 2 : 1);
  -
  -	debug(("dbit: %d...", dbit));
  -
  -	db->curbit = dbit;
  -	db->hmask = masks[hbit];
  +    register int hbit;
  +    register long dbit;
  +    register long pagb;
  +    apr_status_t status;
   
  -	pagb = hash & db->hmask;
  -/*
  - * see if the block we need is already in memory.
  - * note: this lookaside cache has about 10% hit rate.
  - */
  -	if (pagb != db->pagbno) { 
  -/*
  - * note: here, we assume a "hole" is read as 0s.
  - * if not, must zero pagbuf first.
  - * ### joe: this assumption was surely never correct? but
  - * ### we make it so in read_from anyway.
  - */
  -		if ((status = read_from(db->pagf, db->pagbuf, OFF_PAG(pagb), PBLKSIZ)) 
  -		    != APR_SUCCESS) {
  -		    ioerr(db);		    
  -		    return status;
  -		}
  +    dbit = 0;
  +    hbit = 0;
  +    while (dbit < db->maxbno && getdbit(db, dbit))
  +    dbit = 2 * dbit + ((hash & (1 << hbit++)) ? 2 : 1);
  +
  +    debug(("dbit: %d...", dbit));
  +
  +    db->curbit = dbit;
  +    db->hmask = masks[hbit];
  +
  +    pagb = hash & db->hmask;
  +    /*
  +     * see if the block we need is already in memory.
  +     * note: this lookaside cache has about 10% hit rate.
  +     */
  +    if (pagb != db->pagbno) { 
  +        /*
  +         * note: here, we assume a "hole" is read as 0s.
  +         * if not, must zero pagbuf first.
  +         * ### joe: this assumption was surely never correct? but
  +         * ### we make it so in read_from anyway.
  +         */
  +        if ((status = read_from(db->pagf, db->pagbuf, OFF_PAG(pagb), PBLKSIZ)) 
  +            != APR_SUCCESS) {
  +            ioerr(db);		    
  +            return status;
  +        }
   
  -		if (!chkpage(db->pagbuf))
  -		    return APR_ENOSPC; /* ### better error? */
  -		db->pagbno = pagb;
  +        if (!chkpage(db->pagbuf))
  +            return APR_ENOSPC; /* ### better error? */
  +        db->pagbno = pagb;
   
  -		debug(("pag read: %d\n", pagb));
  -	}
  -	return APR_SUCCESS;
  +        debug(("pag read: %d\n", pagb));
  +    }
  +    return APR_SUCCESS;
   }
   
  -static int
  -getdbit(SDBM *db, long dbit)
  +static int getdbit(SDBM *db, long dbit)
   {
  -	register long c;
  -	register long dirb;
  +    register long c;
  +    register long dirb;
   
  -	c = dbit / BYTESIZ;
  -	dirb = c / DBLKSIZ;
  +    c = dbit / BYTESIZ;
  +    dirb = c / DBLKSIZ;
   
  -	if (dirb != db->dirbno) {
  -		if (read_from(db->dirf, db->dirbuf, OFF_DIR(dirb), DBLKSIZ)
  -		    != APR_SUCCESS)
  -		    return 0;
  +    if (dirb != db->dirbno) {
  +        if (read_from(db->dirf, db->dirbuf, OFF_DIR(dirb), DBLKSIZ)
  +                    != APR_SUCCESS)
  +            return 0;
   
  -		db->dirbno = dirb;
  +        db->dirbno = dirb;
   
  -		debug(("dir read: %d\n", dirb));
  -	}
  +        debug(("dir read: %d\n", dirb));
  +    }
   
  -	return db->dirbuf[c % DBLKSIZ] & (1 << dbit % BYTESIZ);
  +    return db->dirbuf[c % DBLKSIZ] & (1 << dbit % BYTESIZ);
   }
   
  -static apr_status_t
  -setdbit(SDBM *db, long dbit)
  +static apr_status_t setdbit(SDBM *db, long dbit)
   {
  -	register long c;
  -	register long dirb;
  -	apr_status_t status;
  -	apr_off_t off;
  -
  -	c = dbit / BYTESIZ;
  -	dirb = c / DBLKSIZ;
  +    register long c;
  +    register long dirb;
  +    apr_status_t status;
  +    apr_off_t off;
   
  -	if (dirb != db->dirbno) {
  -	    if ((status = read_from(db->dirf, db->dirbuf, OFF_DIR(dirb), DBLKSIZ))
  -		!= APR_SUCCESS)
  -		return status;
  +    c = dbit / BYTESIZ;
  +    dirb = c / DBLKSIZ;
   
  -	    db->dirbno = dirb;
  -	    
  -	    debug(("dir read: %d\n", dirb));
  -	}
  +    if (dirb != db->dirbno) {
  +        if ((status = read_from(db->dirf, db->dirbuf, OFF_DIR(dirb), DBLKSIZ))
  +                    != APR_SUCCESS)
  +            return status;
  +
  +        db->dirbno = dirb;
  +        
  +        debug(("dir read: %d\n", dirb));
  +    }
   
  -	db->dirbuf[c % DBLKSIZ] |= (1 << dbit % BYTESIZ);
  +    db->dirbuf[c % DBLKSIZ] |= (1 << dbit % BYTESIZ);
   
  -	if (dbit >= db->maxbno)
  -		db->maxbno += DBLKSIZ * BYTESIZ;
  +    if (dbit >= db->maxbno)
  +        db->maxbno += DBLKSIZ * BYTESIZ;
   
  -	off = OFF_DIR(dirb);
  -	if (((status = apr_file_seek(db->dirf, APR_SET, &off)) != APR_SUCCESS)
  -	    || (status = apr_file_write_full(db->dirf, db->dirbuf, DBLKSIZ,
  -                                       NULL)) != APR_SUCCESS) {
  -	    return status;
  -        }
  +    off = OFF_DIR(dirb);
  +    if (((status = apr_file_seek(db->dirf, APR_SET, &off)) != APR_SUCCESS)
  +        || (status = apr_file_write_full(db->dirf, db->dirbuf, DBLKSIZ,
  +                                   NULL)) != APR_SUCCESS) {
  +        return status;
  +    }
   
  -	return APR_SUCCESS;
  +    return APR_SUCCESS;
   }
   
   /*
  - * getnext - get the next key in the page, and if done with
  - * the page, try the next page in sequence
  - */
  -static sdbm_datum
  -getnext(SDBM *db)
  -{
  -	sdbm_datum key;
  +* getnext - get the next key in the page, and if done with
  +* the page, try the next page in sequence
  +*/
  +static sdbm_datum getnext(SDBM *db)
  +{
  +    sdbm_datum key;
  +
  +    for (;;) {
  +        db->keyptr++;
  +        key = getnkey(db->pagbuf, db->keyptr);
  +        if (key.dptr != NULL)
  +            return key;
  +        /*
  +         * we either run out, or there is nothing on this page..
  +         * try the next one... If we lost our position on the
  +         * file, we will have to seek.
  +         */
  +        db->keyptr = 0;
  +        if (db->pagbno != db->blkptr++) {
  +            apr_off_t off = OFF_PAG(db->blkptr);
  +            if (apr_file_seek(db->pagf, APR_SET, &off) != APR_SUCCESS)
  +                break;
  +        }
   
  -	for (;;) {
  -		db->keyptr++;
  -		key = getnkey(db->pagbuf, db->keyptr);
  -		if (key.dptr != NULL)
  -			return key;
  -/*
  - * we either run out, or there is nothing on this page..
  - * try the next one... If we lost our position on the
  - * file, we will have to seek.
  - */
  -		db->keyptr = 0;
  -		if (db->pagbno != db->blkptr++) {
  -		    apr_off_t off = OFF_PAG(db->blkptr);
  -		    if (apr_file_seek(db->pagf, APR_SET, &off) != APR_SUCCESS)
  -			break;
  -		}
  -
  -		db->pagbno = db->blkptr;
  -		/* ### EOF acceptable here too? */
  -		if (apr_file_read_full(db->pagf, db->pagbuf, PBLKSIZ, NULL) != APR_SUCCESS)
  -			break;
  -		if (!chkpage(db->pagbuf))
  -			break;
  -	}
  -		
  -	ioerr(db);
  -	return sdbm_nullitem;
  +        db->pagbno = db->blkptr;
  +        /* ### EOF acceptable here too? */
  +        if (apr_file_read_full(db->pagf, db->pagbuf, PBLKSIZ, NULL) 
  +                != APR_SUCCESS)
  +            break;
  +        if (!chkpage(db->pagbuf))
  +            break;
  +    }
  +    
  +    ioerr(db);
  +    return sdbm_nullitem;
   }
   
   
  
  
  

Mime
View raw message