1 | #ifndef NDBM_H |
---|
2 | #define NDBM_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id$ */ |
---|
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 | * 4. Neither the name of the University nor the names of its contributors |
---|
27 | * may be used to endorse or promote products derived from this software |
---|
28 | * without specific prior written permission. |
---|
29 | * |
---|
30 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
39 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
40 | * SUCH DAMAGE. |
---|
41 | * |
---|
42 | * @(#)ndbm.h 5.1 (Berkeley) 5/30/85 |
---|
43 | * |
---|
44 | * Par. 3 removed due to a license change (1999) |
---|
45 | * see ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change |
---|
46 | */ |
---|
47 | |
---|
48 | /* |
---|
49 | * Hashed key data base library. |
---|
50 | */ |
---|
51 | #define PBLKSIZ 1024 |
---|
52 | |
---|
53 | #define DBLKSIZ 4096 |
---|
54 | |
---|
55 | typedef struct { |
---|
56 | int dbm_dirf; /* open directory file */ |
---|
57 | int dbm_pagf; /* open page file */ |
---|
58 | int dbm_flags; /* flags, see below */ |
---|
59 | long dbm_maxbno; /* last ``bit'' in dir file */ |
---|
60 | long dbm_bitno; /* current bit number */ |
---|
61 | long dbm_hmask; /* hash mask */ |
---|
62 | long dbm_blkptr; /* current block for dbm_nextkey */ |
---|
63 | int dbm_keyptr; /* current key for dbm_nextkey */ |
---|
64 | long dbm_blkno; /* current page to read/write */ |
---|
65 | long dbm_pagbno; /* current page in pagbuf */ |
---|
66 | char dbm_pagbuf[PBLKSIZ]; /* page file block buffer */ |
---|
67 | long dbm_dirbno; /* current block in dirbuf */ |
---|
68 | char dbm_dirbuf[DBLKSIZ]; /* directory file block buffer */ |
---|
69 | } DBM; |
---|
70 | |
---|
71 | #define _DBM_RDONLY 0x01 /* data base open read-only */ |
---|
72 | #define _DBM_IOERR 0x02 /* data base I/O error */ |
---|
73 | |
---|
74 | #define dbm_rdonly(db) ((db)->dbm_flags & _DBM_RDONLY) |
---|
75 | |
---|
76 | #define dbm_error(db) ((db)->dbm_flags & _DBM_IOERR) |
---|
77 | /* use this one at your own risk! */ |
---|
78 | #define dbm_clearerr(db) ((db)->dbm_flags &= ~_DBM_IOERR) |
---|
79 | |
---|
80 | /* for flock(2) and fstat(2) */ |
---|
81 | #define dbm_dirfno(db) ((db)->dbm_dirf) |
---|
82 | #define dbm_pagfno(db) ((db)->dbm_pagf) |
---|
83 | |
---|
84 | typedef struct { |
---|
85 | char *dptr; |
---|
86 | int dsize; |
---|
87 | } datum; |
---|
88 | |
---|
89 | /* |
---|
90 | * flags to dbm_store() |
---|
91 | */ |
---|
92 | #define DBM_INSERT 0 |
---|
93 | #define DBM_REPLACE 1 |
---|
94 | |
---|
95 | DBM *dbm_open(char *file, int flags, int mode); |
---|
96 | void dbm_close(DBM *db); |
---|
97 | datum dbm_fetch(register DBM *db, datum key); |
---|
98 | datum dbm_firstkey(DBM *db); |
---|
99 | datum dbm_nextkey(register DBM *db); |
---|
100 | long dbm_forder(register DBM *db, datum key); |
---|
101 | int dbm_delete(register DBM *db, datum key); |
---|
102 | int dbm_store(register DBM *db, datum key, datum dat, int replace); |
---|
103 | |
---|
104 | #endif /* NDBM_H */ |
---|