Loading...
Searching...
No Matches
ndbm.h File Reference

Go to the source code of this file.

## Data Structures

struct | DBM
struct | datum

## Macros

#define | PBLKSIZ 1024
#define | DBLKSIZ 4096
#define | _DBM_RDONLY 0x01 /* data base open read-only */
#define | _DBM_IOERR 0x02 /* data base I/O error */
#define | dbm_rdonly(db)
#define | dbm_error(db)
#define | dbm_clearerr(db)
#define | dbm_dirfno(db)
#define | dbm_pagfno(db)
#define | DBM_INSERT 0
#define | DBM_REPLACE 1

## Functions

DBM * | dbm_open (char *file, int flags, int mode)
void | dbm_close (DBM *db)
datum | dbm_fetch (DBM *db, datum key)
datum | dbm_firstkey (DBM *db)
datum | dbm_nextkey (DBM *db)
long | dbm_forder (DBM *db, datum key)
int | dbm_delete (DBM *db, datum key)
int | dbm_store (DBM *db, datum key, datum dat, int replace)

## Data Structure Documentation

## DBM

struct DBM

Definition at line 54 of file ndbm.h.

Data Fields
long | dbm_bitno |
long | dbm_blkno |
long | dbm_blkptr |
long | dbm_dirbno |
char | dbm_dirbuf[DBLKSIZ] |
int | dbm_dirf |
int | dbm_flags |
long | dbm_hmask |
int | dbm_keyptr |
long | dbm_maxbno |
long | dbm_pagbno |
char | dbm_pagbuf[PBLKSIZ] |
int | dbm_pagf |

## datum

struct datum

Definition at line 83 of file ndbm.h.

Data Fields
char * | dptr |
int | dsize |

## Macro Definition Documentation

## _DBM_IOERR

#define _DBM_IOERR 0x02 /* data base I/O error */

Definition at line 71 of file ndbm.h.

## _DBM_RDONLY

#define _DBM_RDONLY 0x01 /* data base open read-only */

Definition at line 70 of file ndbm.h.

## DBLKSIZ

#define DBLKSIZ 4096

Definition at line 52 of file ndbm.h.

## dbm_clearerr

#define dbm_clearerr | ( |  | db | ) |

Value:
((db)->dbm_flags &= ~_DBM_IOERR)
_DBM_IOERR
#define _DBM_IOERR
Definition ndbm.h:71

Definition at line 77 of file ndbm.h.

## dbm_dirfno

#define dbm_dirfno | ( |  | db | ) |

Value:
((db)->dbm_dirf)

Definition at line 80 of file ndbm.h.

## dbm_error

#define dbm_error | ( |  | db | ) |

Value:
((db)->dbm_flags & _DBM_IOERR)

Definition at line 75 of file ndbm.h.

## DBM_INSERT

#define DBM_INSERT 0

Definition at line 91 of file ndbm.h.

## dbm_pagfno

#define dbm_pagfno | ( |  | db | ) |

Value:
((db)->dbm_pagf)

Definition at line 81 of file ndbm.h.

## dbm_rdonly

#define dbm_rdonly | ( |  | db | ) |

Value:
((db)->dbm_flags & _DBM_RDONLY)
_DBM_RDONLY
#define _DBM_RDONLY
Definition ndbm.h:70

Definition at line 73 of file ndbm.h.

## DBM_REPLACE

#define DBM_REPLACE 1

Definition at line 92 of file ndbm.h.

## PBLKSIZ

#define PBLKSIZ 1024

Definition at line 50 of file ndbm.h.

## Function Documentation

## dbm_close()

void dbm_close | ( | DBM * | db | ) |

Definition at line 97 of file ndbm.cc.

{
(void) si_close(db->dbm_dirf);
(void) si_close(db->dbm_pagf);
free((char *)db);
}
DBM::dbm_pagf
int dbm_pagf
Definition ndbm.h:56
DBM::dbm_dirf
int dbm_dirf
Definition ndbm.h:55
free
#define free
Definition omAllocFunc.c:14

## dbm_delete()

int dbm_delete | ( | DBM * | db,
|  | datum | key )

Definition at line 139 of file ndbm.cc.

{
int i;
// datum item;
if (dbm_error(db))
return (-1);
if (dbm_rdonly(db))
{
errno = EPERM;
return (-1);
}
dbm_access(db, dcalchash(key));
if ((i = finddatum(db->dbm_pagbuf, key)) < 0)
return (-1);
if (!delitem(db->dbm_pagbuf, i))
goto err;
db->dbm_pagbno = db->dbm_blkno;
(void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, SEEK_SET);
if (si_write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
{
err:
db->dbm_flags |= _DBM_IOERR;
return (-1);
}
return (0);
}
i
int i
Definition cfEzgcd.cc:132
SEEK_SET
#define SEEK_SET
Definition mod2.h:115
dbm_access
static void dbm_access(DBM *db, long hash)
Definition ndbm.cc:304
delitem
static int delitem(char buf[PBLKSIZ], int n)
Definition ndbm.cc:467
finddatum
static int finddatum(char buf[PBLKSIZ], datum item)
Definition ndbm.cc:394
dcalchash
static long dcalchash(datum item)
Definition ndbm.cc:442
dbm_rdonly
#define dbm_rdonly(db)
Definition ndbm.h:73
dbm_error
#define dbm_error(db)
Definition ndbm.h:75
DBM::dbm_pagbno
long dbm_pagbno
Definition ndbm.h:64
DBM::dbm_flags
int dbm_flags
Definition ndbm.h:57
DBM::dbm_blkno
long dbm_blkno
Definition ndbm.h:63
PBLKSIZ
#define PBLKSIZ
Definition ndbm.h:50
DBM::dbm_pagbuf
char dbm_pagbuf[PBLKSIZ]
Definition ndbm.h:65

## dbm_fetch()

datum dbm_fetch | ( | DBM * | db,
|  | datum | key )

Definition at line 119 of file ndbm.cc.

{
int i;
datum item;
if (dbm_error(db))
goto err;
dbm_access(db, dcalchash(key));
if ((i = finddatum(db->dbm_pagbuf, key)) >= 0)
{
item = makdatum(db->dbm_pagbuf, i+1);
if (item.dptr != NULL)
return (item);
}
err:
item.dptr = NULL;
item.dsize = 0;
return (item);
}
makdatum
static datum makdatum(char buf[PBLKSIZ], int n)
Definition ndbm.cc:373
datum::dptr
char * dptr
Definition ndbm.h:84
datum::dsize
int dsize
Definition ndbm.h:85
datum
Definition ndbm.h:83
NULL
#define NULL
Definition omList.c:12

## dbm_firstkey()

datum dbm_firstkey | ( | DBM * | db | ) |

Definition at line 252 of file ndbm.cc.

{
db->dbm_blkptr = 0L;
db->dbm_keyptr = 0;
return (dbm_nextkey(db));
}
dbm_nextkey
datum dbm_nextkey(DBM *db)
Definition ndbm.cc:260
DBM::dbm_keyptr
int dbm_keyptr
Definition ndbm.h:62
DBM::dbm_blkptr
long dbm_blkptr
Definition ndbm.h:61

## dbm_forder()

long dbm_forder | ( | DBM * | db,
|  | datum | key )

Definition at line 104 of file ndbm.cc.

{
long hash;
hash = dcalchash(key);
for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1)
{
db->dbm_blkno = hash & db->dbm_hmask;
db->dbm_bitno = db->dbm_blkno + db->dbm_hmask;
if (getbit(db) == 0)
break;
}
return (db->dbm_blkno);
}
getbit
static int getbit(DBM *db)
Definition ndbm.cc:326
DBM::dbm_hmask
long dbm_hmask
Definition ndbm.h:60
DBM::dbm_bitno
long dbm_bitno
Definition ndbm.h:59

## dbm_nextkey()

datum dbm_nextkey | ( | DBM * | db | ) |

Definition at line 260 of file ndbm.cc.

{
struct stat statb;
datum item;
if (dbm_error(db)
|| singular_fstat(db->dbm_pagf, &statb) < 0
)
goto err;
statb.st_size /= PBLKSIZ;
for (;;)
{
if (db->dbm_blkptr != db->dbm_pagbno)
{
db->dbm_pagbno = db->dbm_blkptr;
(void) lseek(db->dbm_pagf, db->dbm_blkptr*PBLKSIZ, SEEK_SET);
if (si_read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
memset(db->dbm_pagbuf, 0, PBLKSIZ);
#ifdef DEBUG
else if (chkblk(db->dbm_pagbuf) < 0)
db->dbm_flags |= _DBM_IOERR;
#endif
}
short tmp;
memcpy(&tmp, db->dbm_pagbuf, sizeof(tmp));
if (tmp != 0)
{
item = makdatum(db->dbm_pagbuf, db->dbm_keyptr);
if (item.dptr != NULL)
{
db->dbm_keyptr += 2;
return (item);
}
db->dbm_keyptr = 0;
}
if (++db->dbm_blkptr >= statb.st_size)
break;
}
err:
item.dptr = NULL;
item.dsize = 0;
return (item);
}
singular_fstat
int singular_fstat(int fd, struct stat *buf)
Definition misc_ip.cc:1084

## dbm_open()

DBM * dbm_open | ( | char * | file,
|  | int | flags,
|  | int | mode )

Definition at line 59 of file ndbm.cc.

{
struct stat statb;
DBM *db;
if ((db = (DBM *)malloc(sizeof *db)) == 0)
{
errno = ENOMEM;
return ((DBM *)0);
}
#ifdef MSDOS
// default mode of open is ascii, we need binary mode.
flags |= O_BINARY;
#endif
db->dbm_flags = (flags & 03) == O_RDONLY ? _DBM_RDONLY : 0;
if ((flags & 03) == O_WRONLY)
flags = (flags & ~03) | O_RDWR;
strcpy(db->dbm_pagbuf, file);
strcat(db->dbm_pagbuf, ".pag");
db->dbm_pagf = si_open(db->dbm_pagbuf, flags, mode);
if (db->dbm_pagf < 0)
goto bad;
strcpy(db->dbm_pagbuf, file);
strcat(db->dbm_pagbuf, ".dir");
db->dbm_dirf = si_open(db->dbm_pagbuf, flags, mode);
if (db->dbm_dirf < 0)
goto bad1;
singular_fstat(db->dbm_dirf, &statb);
db->dbm_maxbno = statb.st_size*BYTESIZ-1;
db->dbm_pagbno = db->dbm_dirbno = -1;
return (db);
bad1:
(void) si_close(db->dbm_pagf);
bad:
free((char *)db);
return ((DBM *)0);
}
bad
bool bad
Definition facFactorize.cc:64
BYTESIZ
#define BYTESIZ
Definition ndbm.cc:46
DBM
Definition ndbm.h:54
malloc
#define malloc
Definition omAllocFunc.c:12
si_open
#define si_open(...)
flags
int status int void size_t count const char int flags
Definition si_signals.h:83

## dbm_store()

int dbm_store | ( | DBM * | db,
|  | datum | key,
|  | datum | dat,
|  | int | replace )

Definition at line 167 of file ndbm.cc.

{
int i;
int ret;
datum item, item1;
char ovfbuf[PBLKSIZ];
if (dbm_error(db))
return (-1);
if (dbm_rdonly(db))
{
errno = EPERM;
return (-1);
}
_loop:
dbm_access(db, dcalchash(key));
if ((i = finddatum(db->dbm_pagbuf, key)) >= 0)
{
if (!replace)
return (1);
if (!delitem(db->dbm_pagbuf, i))
{
db->dbm_flags |= _DBM_IOERR;
return (-1);
}
}
if (!additem(db->dbm_pagbuf, key, dat))
goto split;
db->dbm_pagbno = db->dbm_blkno;
(void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, SEEK_SET);
if ( (ret=si_write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ)) != PBLKSIZ)
{
db->dbm_flags |= _DBM_IOERR;
return (-1);
}
return (0);
split:
if (key.dsize+dat.dsize+3*sizeof(short) >= PBLKSIZ)
{
db->dbm_flags |= _DBM_IOERR;
errno = ENOSPC;
return (-1);
}
memset(ovfbuf, 0, PBLKSIZ);
for (i=0;;) {
item = makdatum(db->dbm_pagbuf, i);
if (item.dptr == NULL)
break;
if (dcalchash(item) & (db->dbm_hmask+1))
{
item1 = makdatum(db->dbm_pagbuf, i+1);
if (item1.dptr == NULL) {
fprintf(stderr, "ndbm: split not paired\n");
db->dbm_flags |= _DBM_IOERR;
break;
}
if (!additem(ovfbuf, item, item1) ||
!delitem(db->dbm_pagbuf, i))
{
db->dbm_flags |= _DBM_IOERR;
return (-1);
}
continue;
}
i += 2;
}
db->dbm_pagbno = db->dbm_blkno;
(void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, SEEK_SET);
if (si_write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
{
db->dbm_flags |= _DBM_IOERR;
return (-1);
}
(void) lseek(db->dbm_pagf, (db->dbm_blkno+db->dbm_hmask+1)*PBLKSIZ, SEEK_SET);
if (si_write(db->dbm_pagf, ovfbuf, PBLKSIZ) != PBLKSIZ)
{
db->dbm_flags |= _DBM_IOERR;
return (-1);
}
setbit(db);
goto _loop;
}
split
static CFList split(const CanonicalForm &F, const int m, const Variable &x)
Definition facMul.cc:3475
additem
static int additem(char buf[PBLKSIZ], datum item, datum item1)
Definition ndbm.cc:499
setbit
static void setbit(DBM *db)
Definition ndbm.cc:348