/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#include "lint.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <ndbm.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
/* add support for batched writing for NIS */
/*
* forward declarations
*/
static void dbm_access(DBM *, unsigned long);
static int delitem(char *, int);
static int dbm_flushdir(DBM *);
/* the following three are required by mapfile-vers */
int dbm_close_status(DBM *);
/* used to make a dbm file all at once instead of incrementally */
void
{
}
int
{
}
int
{
}
int
{
int ok = 0;
if (dbm_flushpag(db) < 0)
ok = -1;
if (dbm_flushdir(db) < 0)
ok = -1;
return (ok);
}
static int
{
int ok = 0;
ok = -1;
}
}
return (ok);
}
static int
{
int ok = 0;
ok = -1;
}
}
return (ok);
}
DBM *
{
int serrno;
return ((DBM *)0);
}
sizeof (db->dbm_pagbuf) ||
sizeof (db->dbm_pagbuf)) {
/*
* file.pag does not fit into dbm_pagbuf.
* fail 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;
ok = -1;
ok = -1;
ok = -1;
return (ok);
}
long
{
unsigned long hash;
break;
}
}
{
int i;
goto err;
return (item);
}
err:
return (item);
}
int
{
int i;
return (-1);
if (dbm_rdonly(db)) {
return (-1);
}
return (-1);
goto err;
if (dbm_defwrite(db)) {
} else {
err:
return (-1);
}
}
return (0);
}
int
{
int 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);
hashdiff = 0;
return (-1);
}
for (i = 0; ; ) {
break;
hashdiff++;
}
/* (void) fprintf(stderr, "ndbm: */
/* split not paired\n"); */
break;
}
return (-1);
}
continue;
}
i += 2;
}
return (-1);
}
return (-1);
}
return (-1);
}
if (hashdiff == 0) {
return (-1);
}
goto loop;
}
static unsigned long
{
long bit;
for (;;) {
bit >>= 1;
if (bit == 0)
return (0L);
}
}
{
int i, j;
loop:
j = 0;
for (i = 2; ; i += 2) {
break;
j = i;
}
}
return (bitem);
}
if (hash == 0)
return (item); /* null item */
goto loop;
}
{
/*
* For some reason, the Posix specification (SUSv3)
* says that dbm_firstkey() is not a cancellation point.
* It really should be, but in order to pass the SUSv3
* test suite we make it not a cancellation point.
* XXX: fix me when the SUSv3 specification gets fixed.
*/
int cancel_state;
db->dbm_blkptr = 0L;
db->dbm_keyptr = 0;
return (rval);
}
{
}
/*
* 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 (;;) {
PBLKSIZ))
#ifdef DEBUG
#endif
}
/* Am I an empty block? */
return (item);
}
db->dbm_keyptr = 0;
}
/* go to next sequential block */
break;
}
err:
return (item);
}
{
unsigned long hash;
int f;
int i;
int j;
short *sp;
size_t 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 */
PBLKSIZ))
#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.
*/
return (dbm_slow_nextkey(db));
}
/*
* 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 */
continue;
} else {
if (n == 0) continue;
do {
goto keep_going;
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 void
{
long b, i, n;
long bn;
long my_bitno;
long my_hmask;
long my_blkno;
int j = (sizeof (my_hmask)) * 8;
/* getbit inline */
if (b != db->dbm_dirbno) {
if (dbm_dirdirty(db))
db->dbm_dirbno = b;
DBLKSIZ))
}
/*
* if (getbit(db) == 0)
* break;
*/
}
/* copy */
PBLKSIZ)) {
}
}
#ifdef DEBUG
#endif
}
}
static int
{
long bn;
long b, i, n;
return (0);
if (b != db->dbm_dirbno) {
if (dbm_dirdirty(db))
db->dbm_dirbno = b;
}
}
static int
{
long bn;
long i, n, b;
if (b != db->dbm_dirbno) {
if (dbm_dirdirty(db))
(void) dbm_flushdir(db);
db->dbm_dirbno = b;
}
db->dbm_dirbno = b;
if (dbm_defwrite(db)) {
} else {
return (-1);
}
}
return (0);
}
static datum
{
short *sp;
int t;
if ((unsigned)n >= sp[0]) {
return (item);
}
t = PBLKSIZ;
if (n > 0)
t = sp[n];
return (item);
}
static int
{
long n;
if (n == 0)
return (0);
do {
else {
p1++;
p2++;
}
} while (--n);
return (0);
}
static int
{
short *sp;
int i, n, j;
n = PBLKSIZ;
n -= sp[i + 1];
continue;
return (i);
}
return (-1);
}
/*
* 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,
};
/* could consider to make it 32-bit int table to minimize memory usage */
= {
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 unsigned long
{
long s;
int c, j;
char *cp;
unsigned long hashl;
long 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 int
{
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 int
{
short *sp;
if (i2 > 0)
return (0);
sp[0] += 2;
return (1);
}
#ifdef DEBUG
static int
{
short *sp;
int 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