2 * sdbm - ndbm work-alike hashed database library
3 * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
4 * author: oz@nexus.yorku.ca
5 * status: public domain.
9 #define PAIRMAX 1008 /* arbitrary on PBLKSIZ-N */
10 #define SPLTMAX 10 /* maximum allowed splits */
11 /* for a single insertion */
13 #define DIRFEXT ".sdbm_dir"
15 #define DIRFEXT ".dir"
17 #define PAGFEXT ".pag"
20 int dirf; /* directory file descriptor */
21 int pagf; /* page file descriptor */
22 int flags; /* status/error flags, see below */
23 long maxbno; /* size of dirfile in bits */
24 long curbit; /* current bit number */
25 long hmask; /* current hash mask */
26 long blkptr; /* current block for nextkey */
27 int keyptr; /* current key for nextkey */
28 long blkno; /* current page to read/write */
29 long pagbno; /* current page in pagbuf */
30 char pagbuf[PBLKSIZ]; /* page file block buffer */
31 long dirbno; /* current block in dirbuf */
32 char dirbuf[DBLKSIZ]; /* directory file block buffer */
35 #define DBM_RDONLY 0x1 /* data base open read-only */
36 #define DBM_IOERR 0x2 /* data base I/O error */
41 #define sdbm_rdonly(db) ((db)->flags & DBM_RDONLY)
42 #define sdbm_error(db) ((db)->flags & DBM_IOERR)
44 #define sdbm_clearerr(db) ((db)->flags &= ~DBM_IOERR) /* ouch */
46 #define sdbm_dirfno(db) ((db)->dirf)
47 #define sdbm_pagfno(db) ((db)->pagf)
54 EXTCONST datum nullitem
60 #if defined(__STDC__) || defined(__cplusplus) || defined(CAN_PROTOTYPE)
75 extern DBM *sdbm_open proto((char *, int, int));
76 extern void sdbm_close proto((DBM *));
77 extern datum sdbm_fetch proto((DBM *, datum));
78 extern int sdbm_delete proto((DBM *, datum));
79 extern int sdbm_store proto((DBM *, datum, datum, int));
80 extern datum sdbm_firstkey proto((DBM *));
81 extern datum sdbm_nextkey proto((DBM *));
86 extern DBM *sdbm_prep proto((char *, char *, int, int));
87 extern long sdbm_hash proto((char *, int));
90 #define dbm_open sdbm_open
91 #define dbm_close sdbm_close
92 #define dbm_fetch sdbm_fetch
93 #define dbm_store sdbm_store
94 #define dbm_delete sdbm_delete
95 #define dbm_firstkey sdbm_firstkey
96 #define dbm_nextkey sdbm_nextkey
97 #define dbm_error sdbm_error
98 #define dbm_clearerr sdbm_clearerr
101 /* Most of the following is stolen from perl.h. */
102 #ifndef H_PERL /* Include guard */
105 * The following contortions are brought to you on behalf of all the
106 * standards, semi-standards, de facto standards, not-so-de-facto standards
107 * of the world, as well as all the other botches anyone ever thought of.
108 * The basic theory is that if we work hard enough here, the rest of the
109 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
115 # include <net/errno.h>
119 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
120 # define STANDARD_C 1
127 #if defined(I_UNISTD)
137 # if !defined(MSDOS) && !defined(WIN32) && !defined(VMS)
138 # ifdef PARAM_NEEDS_TYPES
139 # include <sys/types.h>
141 # include <sys/param.h>
145 #ifndef _TYPES_ /* If types.h defines this it's easy. */
146 # ifndef major /* Does everyone's types.h define this? */
147 # include <sys/types.h>
151 #include <sys/stat.h>
155 # define SEEK_SET L_SET
157 # define SEEK_SET 0 /* Wild guess. */
161 /* Use all the "standard" definitions? */
162 #if defined(STANDARD_C) && defined(I_STDLIB)
164 #endif /* STANDARD_C */
166 #define MEM_SIZE Size_t
168 /* This comes after <stdlib.h> so we don't try to change the standard
169 * library prototypes; we'll use our own instead. */
171 #if defined(MYMALLOC) && (defined(HIDEMYMALLOC) || defined(EMBEDMYMALLOC))
174 # define malloc Mymalloc
175 # define calloc Mycalloc
176 # define realloc Myremalloc
179 # ifdef EMBEDMYMALLOC
180 # define malloc Perl_malloc
181 # define calloc Perl_calloc
182 # define realloc Perl_realloc
183 # define free Perl_free
186 Malloc_t malloc proto((MEM_SIZE nbytes));
187 Malloc_t calloc proto((MEM_SIZE elements, MEM_SIZE size));
188 Malloc_t realloc proto((Malloc_t where, MEM_SIZE nbytes));
189 Free_t free proto((Malloc_t where));
191 #endif /* MYMALLOC && (HIDEMYMALLOC || EMBEDMYMALLOC) */
208 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
210 extern char * memcpy proto((char*, char*, int));
216 # define memcpy(d,s,l) bcopy(s,d,l)
218 # define memcpy(d,s,l) my_bcopy(s,d,l)
221 #endif /* HAS_MEMCPY */
224 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
226 extern char *memset proto((char*, int, int));
229 # define memzero(d,l) memset(d,0,l)
233 # define memzero(d,l) bzero(d,l)
235 # define memzero(d,l) my_bzero(d,l)
238 #endif /* HAS_MEMSET */
240 #if defined(mips) && defined(ultrix) && !defined(__STDC__)
244 #if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
245 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
247 extern int memcmp proto((char*, char*, int));
251 # pragma function(memcmp)
255 /* maybe we should have included the full embedding header... */
257 # define memcmp my_memcmp
259 # define memcmp Perl_my_memcmp
262 extern int memcmp proto((char*, char*, int));
265 #endif /* HAS_MEMCMP */
269 # define bcmp(s1,s2,l) memcmp(s1,s2,l)
271 #endif /* !HAS_BCMP */
274 # define memNE(s1,s2,l) (memcmp(s1,s2,l))
275 # define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
277 # define memNE(s1,s2,l) (bcmp(s1,s2,l))
278 # define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
285 # include <netinet/in.h>
289 #endif /* Include guard */