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"
21 #define __declspec(t) /* kludge for EXTCONST below */
25 int dirf; /* directory file descriptor */
26 int pagf; /* page file descriptor */
27 int flags; /* status/error flags, see below */
28 long maxbno; /* size of dirfile in bits */
29 long curbit; /* current bit number */
30 long hmask; /* current hash mask */
31 long blkptr; /* current block for nextkey */
32 int keyptr; /* current key for nextkey */
33 long blkno; /* current page to read/write */
34 long pagbno; /* current page in pagbuf */
35 char pagbuf[PBLKSIZ]; /* page file block buffer */
36 long dirbno; /* current block in dirbuf */
37 char dirbuf[DBLKSIZ]; /* directory file block buffer */
40 #define DBM_RDONLY 0x1 /* data base open read-only */
41 #define DBM_IOERR 0x2 /* data base I/O error */
46 #define sdbm_rdonly(db) ((db)->flags & DBM_RDONLY)
47 #define sdbm_error(db) ((db)->flags & DBM_IOERR)
49 #define sdbm_clearerr(db) ((db)->flags &= ~DBM_IOERR) /* ouch */
51 #define sdbm_dirfno(db) ((db)->dirf)
52 #define sdbm_pagfno(db) ((db)->pagf)
59 EXTCONST datum nullitem
65 #if defined(__STDC__) || defined(__cplusplus) || defined(CAN_PROTOTYPE)
80 extern DBM *sdbm_open proto((char *, int, int));
81 extern void sdbm_close proto((DBM *));
82 extern datum sdbm_fetch proto((DBM *, datum));
83 extern int sdbm_delete proto((DBM *, datum));
84 extern int sdbm_store proto((DBM *, datum, datum, int));
85 extern datum sdbm_firstkey proto((DBM *));
86 extern datum sdbm_nextkey proto((DBM *));
91 extern DBM *sdbm_prep proto((char *, char *, int, int));
92 extern long sdbm_hash proto((char *, int));
95 #define dbm_open sdbm_open
96 #define dbm_close sdbm_close
97 #define dbm_fetch sdbm_fetch
98 #define dbm_store sdbm_store
99 #define dbm_delete sdbm_delete
100 #define dbm_firstkey sdbm_firstkey
101 #define dbm_nextkey sdbm_nextkey
102 #define dbm_error sdbm_error
103 #define dbm_clearerr sdbm_clearerr
106 /* Most of the following is stolen from perl.h. */
107 #ifndef H_PERL /* Include guard */
110 * The following contortions are brought to you on behalf of all the
111 * standards, semi-standards, de facto standards, not-so-de-facto standards
112 * of the world, as well as all the other botches anyone ever thought of.
113 * The basic theory is that if we work hard enough here, the rest of the
114 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
120 # include <net/errno.h>
124 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
125 # define STANDARD_C 1
132 #if defined(I_UNISTD)
141 #if !defined(MSDOS) && !defined(WIN32) && !defined(VMS)
142 # ifdef PARAM_NEEDS_TYPES
143 # include <sys/types.h>
145 # include <sys/param.h>
148 #ifndef _TYPES_ /* If types.h defines this it's easy. */
149 # ifndef major /* Does everyone's types.h define this? */
150 # include <sys/types.h>
154 #include <sys/stat.h>
158 # define SEEK_SET L_SET
160 # define SEEK_SET 0 /* Wild guess. */
164 /* Use all the "standard" definitions? */
165 #if defined(STANDARD_C) && defined(I_STDLIB)
167 #endif /* STANDARD_C */
169 #define MEM_SIZE Size_t
171 /* This comes after <stdlib.h> so we don't try to change the standard
172 * library prototypes; we'll use our own instead. */
174 #if defined(MYMALLOC) && (defined(HIDEMYMALLOC) || defined(EMBEDMYMALLOC))
177 # define malloc Mymalloc
178 # define calloc Mycalloc
179 # define realloc Myremalloc
182 # ifdef EMBEDMYMALLOC
183 # define malloc Perl_malloc
184 # define calloc Perl_calloc
185 # define realloc Perl_realloc
186 # define free Perl_free
189 Malloc_t malloc proto((MEM_SIZE nbytes));
190 Malloc_t calloc proto((MEM_SIZE elements, MEM_SIZE size));
191 Malloc_t realloc proto((Malloc_t where, MEM_SIZE nbytes));
192 Free_t free proto((Malloc_t where));
194 #endif /* MYMALLOC && (HIDEMYMALLOC || EMBEDMYMALLOC) */
211 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
213 extern char * memcpy proto((char*, char*, int));
219 # define memcpy(d,s,l) bcopy(s,d,l)
221 # define memcpy(d,s,l) my_bcopy(s,d,l)
224 #endif /* HAS_MEMCPY */
227 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
229 extern char *memset proto((char*, int, int));
232 # define memzero(d,l) memset(d,0,l)
236 # define memzero(d,l) bzero(d,l)
238 # define memzero(d,l) my_bzero(d,l)
241 #endif /* HAS_MEMSET */
243 #if defined(mips) && defined(ultrix) && !defined(__STDC__)
247 #if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
248 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
250 extern int memcmp proto((char*, char*, int));
254 # pragma function(memcmp)
258 /* maybe we should have included the full embedding header... */
260 # define memcmp my_memcmp
262 # define memcmp Perl_my_memcmp
265 extern int memcmp proto((char*, char*, int));
268 #endif /* HAS_MEMCMP */
272 # define bcmp(s1,s2,l) memcmp(s1,s2,l)
274 #endif /* !HAS_BCMP */
277 # define memNE(s1,s2,l) (memcmp(s1,s2,l))
278 # define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
280 # define memNE(s1,s2,l) (bcmp(s1,s2,l))
281 # define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
288 # include <netinet/in.h>
292 #endif /* Include guard */