[92e539] | 1 | #ifndef NDBM_H |
---|
| 2 | #define NDBM_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[416465] | 6 | /* $Id: ndbm.h,v 1.2 1999-11-15 17:20:36 obachman Exp $ */ |
---|
[92e539] | 7 | /* |
---|
| 8 | * ABSTRACT: DBM |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | /* |
---|
| 12 | * Copyright (c) 1983 Regents of the University of California. |
---|
| 13 | * All rights reserved. The Berkeley software License Agreement |
---|
| 14 | * specifies the terms and conditions for redistribution. |
---|
| 15 | * |
---|
| 16 | * |
---|
| 17 | * |
---|
| 18 | * Redistribution and use in source and binary forms, with or without |
---|
| 19 | * modification, are permitted provided that the following conditions |
---|
| 20 | * are met: |
---|
| 21 | * 1. Redistributions of source code must retain the above copyright |
---|
| 22 | * notice, this list of conditions and the following disclaimer. |
---|
| 23 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 24 | * notice, this list of conditions and the following disclaimer in the |
---|
| 25 | * documentation and/or other materials provided with the distribution. |
---|
| 26 | * 3. All advertising materials mentioning features or use of this software |
---|
| 27 | * must display the following acknowledgement: |
---|
| 28 | * This product includes software developed by the University of |
---|
| 29 | * California, Berkeley and its contributors. |
---|
| 30 | * 4. Neither the name of the University nor the names of its contributors |
---|
| 31 | * may be used to endorse or promote products derived from this software |
---|
| 32 | * without specific prior written permission. |
---|
| 33 | * |
---|
| 34 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
| 35 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 36 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 37 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
| 38 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
| 39 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
| 40 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 41 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 42 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
| 43 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
| 44 | * SUCH DAMAGE. |
---|
| 45 | * |
---|
| 46 | * @(#)ndbm.h 5.1 (Berkeley) 5/30/85 |
---|
| 47 | */ |
---|
| 48 | |
---|
| 49 | /* |
---|
| 50 | * Hashed key data base library. |
---|
| 51 | */ |
---|
| 52 | #define PBLKSIZ 1024 |
---|
| 53 | |
---|
| 54 | #define DBLKSIZ 4096 |
---|
| 55 | |
---|
| 56 | typedef struct { |
---|
| 57 | int dbm_dirf; /* open directory file */ |
---|
| 58 | int dbm_pagf; /* open page file */ |
---|
| 59 | int dbm_flags; /* flags, see below */ |
---|
| 60 | long dbm_maxbno; /* last ``bit'' in dir file */ |
---|
| 61 | long dbm_bitno; /* current bit number */ |
---|
| 62 | long dbm_hmask; /* hash mask */ |
---|
| 63 | long dbm_blkptr; /* current block for dbm_nextkey */ |
---|
| 64 | int dbm_keyptr; /* current key for dbm_nextkey */ |
---|
| 65 | long dbm_blkno; /* current page to read/write */ |
---|
| 66 | long dbm_pagbno; /* current page in pagbuf */ |
---|
| 67 | char dbm_pagbuf[PBLKSIZ]; /* page file block buffer */ |
---|
| 68 | long dbm_dirbno; /* current block in dirbuf */ |
---|
| 69 | char dbm_dirbuf[DBLKSIZ]; /* directory file block buffer */ |
---|
| 70 | } DBM; |
---|
| 71 | |
---|
| 72 | #define _DBM_RDONLY 0x01 /* data base open read-only */ |
---|
| 73 | #define _DBM_IOERR 0x02 /* data base I/O error */ |
---|
| 74 | |
---|
| 75 | #define dbm_rdonly(db) ((db)->dbm_flags & _DBM_RDONLY) |
---|
| 76 | |
---|
| 77 | #define dbm_error(db) ((db)->dbm_flags & _DBM_IOERR) |
---|
| 78 | /* use this one at your own risk! */ |
---|
| 79 | #define dbm_clearerr(db) ((db)->dbm_flags &= ~_DBM_IOERR) |
---|
| 80 | |
---|
| 81 | /* for flock(2) and fstat(2) */ |
---|
| 82 | #define dbm_dirfno(db) ((db)->dbm_dirf) |
---|
| 83 | #define dbm_pagfno(db) ((db)->dbm_pagf) |
---|
| 84 | |
---|
| 85 | typedef struct { |
---|
| 86 | char *dptr; |
---|
| 87 | int dsize; |
---|
| 88 | } datum; |
---|
| 89 | |
---|
| 90 | /* |
---|
| 91 | * flags to dbm_store() |
---|
| 92 | */ |
---|
| 93 | #define DBM_INSERT 0 |
---|
| 94 | #define DBM_REPLACE 1 |
---|
| 95 | |
---|
| 96 | DBM *dbm_open(char *file, int flags, int mode); |
---|
| 97 | void dbm_close(DBM *db); |
---|
| 98 | datum dbm_fetch(register DBM *db, datum key); |
---|
| 99 | datum dbm_firstkey(DBM *db); |
---|
| 100 | datum dbm_nextkey(register DBM *db); |
---|
| 101 | long dbm_forder(register DBM *db, datum key); |
---|
| 102 | int dbm_delete(register DBM *db, datum key); |
---|
| 103 | int dbm_store(register DBM *db, datum key, datum dat, int replace); |
---|
| 104 | |
---|
| 105 | #endif /* NDBM_H */ |
---|