ndbm.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#include <stdio.h>
#include <errno.h>
#include <ndbm.h>
/*add support for batched writing for NIS*/
#define _DBM_DEFWRITE 0x4
#define _DBM_DIRTY 0x8
#define _DBM_DIRDIRTY 0x10
/*used to make a dbm file all at once instead of incrementally*/
{
}
{
int ok=0;
return(ok);
}
{
int ok=0;
ok= -1;
}
}
return(ok);
}
{
int ok=0;
ok= -1;
}
}
return(ok);
}
#define BYTESIZ 8
static long dcalchash();
extern int errno;
extern char *malloc();
extern char *strcpy();
extern char *strcat();
DBM *
char *file;
{
int serrno;
return ((DBM *)0);
}
sizeof (db->dbm_pagbuf) ||
sizeof (db->dbm_pagbuf)) {
/*
* file.pag does not fit into dbm_pagbuf.
* fails with ENAMETOOLONG.
*/
goto bad;
}
goto bad;
}
/*
* We know this won't overflow so it is safe to ignore the
* return value; we use strl* to prevent false hits in
* code sweeps.
*/
goto bad1;
}
return (db);
bad1:
bad:
return ((DBM *)0);
}
void
{
(void) dbm_close_status(db);
}
/*close with return code*/
int
{
int ok;
ok=0;
return(ok);
}
long
{
long hash;
break;
}
}
{
register i;
goto err;
return (item);
}
err:
return (item);
}
{
register i;
return (-1);
if (dbm_rdonly(db)) {
return (-1);
}
return (-1);
goto err;
if (dbm_defwrite(db)) {
}
else {
err:
return (-1);
}
}
return (0);
}
int replace;
{
register i;
return (-1);
if (dbm_rdonly(db)) {
return (-1);
}
loop:
if (!replace)
return (1);
return (-1);
}
}
goto split;
if (dbm_defwrite(db)) {
}
else {
return (-1);
}
}
return (0);
return (-1);
}
for (i=0;;) {
break;
/*(void) fprintf(stderr, "ndbm: split not paired\n");*/
break;
}
return (-1);
}
continue;
}
i += 2;
}
return (-1);
}
return (-1);
}
return (-1);
}
goto loop;
}
static long
long hash;
{
long bit;
for(;;) {
bit >>= 1;
if(bit == 0)
return(0L);
}
}
long hash;
{
register i,j;
loop:
j=0;
for(i=2;; i+=2) {
break;
j=i;
}
}
return(bitem);
}
if(hash == 0)
return(item); /*null item*/
goto loop;
}
{
db->dbm_blkptr = 0L;
db->dbm_keyptr = 0;
return (dbm_firsthash(db, 0L));
}
{
}
/*this is used if keyptr-2,blocknum doesn't point to the previous
specific key allowing the fast hash order search --
its use indicates user tampering with our state variables,
which some evil users might do to search from some specific place.
It finds the first key at or after blkptr,keyptr in block seq order
this requires looking at all sorts of emtpy blocks in many cases*/
static
{
goto err;
for (;;) {
#ifdef DEBUG
#endif
}
/*Am I an empty block?*/
if (((short *)db->dbm_pagbuf)[0] != 0) {
return (item);
}
db->dbm_keyptr = 0;
}
/*go to next sequential block*/
break;
}
err:
return (item);
}
{
long hash;
int f;
register i;
register j;
register short *sp;
register n;
return (item);
}
/*user has supplied lastkey*/
}
}
else {
/*is this a manual firstkey request? */
if (db->dbm_blkptr == 0L &&
db->dbm_keyptr == 0)
return(dbm_firsthash(db, 0L));
/*no -- get lastkey this is like dbm_access by blkptr*/
#ifdef DEBUG
#endif
}
/*now just make up last key datum*/
/* the keyptr pagbuf have failed us, the user must
be an extra clever moron who depends on
these variables and their former meaning.
If we set the variables this would have got
us the key for sure! So give him the old algorithm.*/
}
/*at this point the last key is paged in and
we can proceed as in old dbm -- like Ken did his. */
f = 1;
j=0;
for(i=0;; i+=2) {
/*begin put makdatum inline*/
if ((unsigned)i >= sp[0]) {
break; /*from below*/
}
else {
}
/* item = makdatum(db->dbm_pagbuf, i);*/
/*end put makdatum inline*/
break;
/*inline cmpdatum*/
else { }
else {
if(n == 0) continue;
do
else continue;
while(--n);
continue;
}
/*end inline cmpdatum*/
/*if(cmpdatum(key, item) <= 0)
continue;*/
if (f) {
j=i;
f = 0;
}
else {
/* if(cmpdatum(bitem, item) < 0)*/
{
j=i;
}
}
else if (n != 0) {
do
j=i;
}
break;
}
while(--n);
}
}
}
if(f == 0) {
return(bitem);
}
/*really need hash at this point*/
/*if he gave us a key we have already calculated the hash*/
/*if not get it*/
if(hash == 0)
return(item); /*null*/
/*get first item on next page in hash table order*/
}
static
long hash;
{
register b, i, n;
register long bn;
register long my_bitno;
register long my_hmask;
register long my_blkno;
/*getbit inline*/
if (b != db->dbm_dirbno) {
db->dbm_dirbno = b;
}
/*
if (getbit(db) == 0)
break;
*/
}
/*copy*/
}
}
#ifdef DEBUG
#endif
}
}
static
{
long bn;
register b, i, n;
return (0);
if (b != db->dbm_dirbno) {
db->dbm_dirbno = b;
}
}
static
{
long bn;
register i, n, b;
if (b != db->dbm_dirbno) {
db->dbm_dirbno = b;
}
db->dbm_dirbno = b;
if (dbm_defwrite(db)) {
} else{
return (-1);
}
}
return (0);
}
static datum
{
register short *sp;
register t;
if ((unsigned)n >= sp[0]) {
return (item);
}
t = PBLKSIZ;
if (n > 0)
t = sp[n];
return (item);
}
{
register n;
if(n == 0)
return(0);
do
while(--n);
return(0);
}
static
{
register short *sp;
register int i, n, j;
n = PBLKSIZ;
n -= sp[i+1];
continue;
return (i);
}
return (-1);
}
static int hitab[16]
/* ken's
{
055,043,036,054,063,014,004,005,
010,064,077,000,035,027,025,071,
};
*/
= { 61, 57, 53, 49, 45, 41, 37, 33,
29, 25, 21, 17, 13, 9, 5, 1,
};
static long hltab[64]
= {
06100151277L,06106161736L,06452611562L,05001724107L,
02614772546L,04120731531L,04665262210L,07347467531L,
06735253126L,06042345173L,03072226605L,01464164730L,
03247435524L,07652510057L,01546775256L,05714532133L,
06173260402L,07517101630L,02431460343L,01743245566L,
00261675137L,02433103631L,03421772437L,04447707466L,
04435620103L,03757017115L,03641531772L,06767633246L,
02673230344L,00260612216L,04133454451L,00615531516L,
06137717526L,02574116560L,02304023373L,07061702261L,
05153031405L,05322056705L,07401116734L,06552375715L,
06165233473L,05311063631L,01212221723L,01052267235L,
06000615237L,01075222665L,06330216006L,04402355630L,
01451177262L,02000133436L,06025467062L,07121076461L,
03123433522L,01010635225L,01716177066L,05161746527L,
01736635071L,06243505026L,03637211610L,01756474365L,
04723077174L,03642763134L,05750130273L,03655541561L,
};
static long
{
register int s, c, j;
register char *cp;
register long hashl;
register int hashi;
hashl = 0;
hashi = 0;
c = *cp++;
for (j=0; j<BYTESIZ; j+=4) {
c >>= 4;
}
}
return (hashl);
}
/*
* Delete pairs of items (n & n+1).
*/
static
{
if ((unsigned)n >= i2 || (n & 1))
return (0);
if (n == i2-2) {
sp[0] -= 2;
return (1);
}
if (n > 0)
if (i1 > 0) {
}
sp[0] -= 2;
return (1);
}
/*
* Add pairs of items (item & item1).
*/
static
{
register short *sp;
if (i2 > 0)
return (0);
sp[0] += 2;
return (1);
}
#ifdef DEBUG
static
{
register short *sp;
register t, i;
t = PBLKSIZ;
for (i=0; i<sp[0]; i++) {
if (sp[i+1] > t)
return (-1);
t = sp[i+1];
}
if (t < (sp[0]+1)*sizeof(short))
return (-1);
return (0);
}
#endif