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 extern const datum nullitem;
65 extern DBM *sdbm_open(char *, int, int);
66 extern void sdbm_close(DBM *);
67 extern datum sdbm_fetch(DBM *, datum);
68 extern int sdbm_delete(DBM *, datum);
69 extern int sdbm_store(DBM *, datum, datum, int);
70 extern datum sdbm_firstkey(DBM *);
71 extern datum sdbm_nextkey(DBM *);
72 extern int sdbm_exists(DBM *, datum);
77 extern DBM *sdbm_prep(char *, char *, int, int);
78 extern long sdbm_hash(const char *, int);
81 #define dbm_open sdbm_open
82 #define dbm_close sdbm_close
83 #define dbm_fetch sdbm_fetch
84 #define dbm_store sdbm_store
85 #define dbm_delete sdbm_delete
86 #define dbm_firstkey sdbm_firstkey
87 #define dbm_nextkey sdbm_nextkey
88 #define dbm_error sdbm_error
89 #define dbm_clearerr sdbm_clearerr
92 /* Most of the following is stolen from perl.h. We don't include
93 perl.h here because we just want the portability parts of perl.h,
96 #ifndef H_PERL /* Include guard */
97 #include "embed.h" /* Follow all the global renamings. */
100 * The following contortions are brought to you on behalf of all the
101 * standards, semi-standards, de facto standards, not-so-de-facto standards
102 * of the world, as well as all the other botches anyone ever thought of.
103 * The basic theory is that if we work hard enough here, the rest of the
104 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
110 # include <net/errno.h>
114 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
115 # define STANDARD_C 1
122 #if defined(I_UNISTD)
132 # if !defined(MSDOS) && !defined(WIN32) && !defined(VMS)
133 # ifdef PARAM_NEEDS_TYPES
134 # include <sys/types.h>
136 # include <sys/param.h>
140 #ifndef _TYPES_ /* If types.h defines this it's easy. */
141 # ifndef major /* Does everyone's types.h define this? */
142 # include <sys/types.h>
146 #include <sys/stat.h>
150 # define SEEK_SET L_SET
152 # define SEEK_SET 0 /* Wild guess. */
156 /* Use all the "standard" definitions */
159 #define MEM_SIZE Size_t
161 /* This comes after <stdlib.h> so we don't try to change the standard
162 * library prototypes; we'll use our own instead. */
164 #if defined(MYMALLOC) && !defined(PERL_POLLUTE_MALLOC)
165 # define malloc Perl_malloc
166 # define calloc Perl_calloc
167 # define realloc Perl_realloc
168 # define free Perl_mfree
174 Malloc_t Perl_malloc(MEM_SIZE nbytes);
175 Malloc_t Perl_calloc(MEM_SIZE elements, MEM_SIZE size);
176 Malloc_t Perl_realloc(Malloc_t where, MEM_SIZE nbytes);
177 Free_t Perl_mfree(Malloc_t where);
183 #endif /* MYMALLOC */
190 # include <strings.h>
197 #define memzero(d,l) memset(d,0,l)
200 # pragma function(memcmp)
203 #define memNE(s1,s2,l) (memcmp(s1,s2,l))
204 #define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
210 # include <netinet/in.h>
214 #endif /* Include guard */