This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] remove __declspec kludge in sdbm.h in favor of setting a
[perl5.git] / ext / SDBM_File / sdbm / sdbm.h
1 /*
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. 
6  */
7 #define DBLKSIZ 4096
8 #define PBLKSIZ 1024
9 #define PAIRMAX 1008                    /* arbitrary on PBLKSIZ-N */
10 #define SPLTMAX 10                      /* maximum allowed splits */
11                                         /* for a single insertion */
12 #ifdef VMS
13 #define DIRFEXT ".sdbm_dir"
14 #else
15 #define DIRFEXT ".dir"
16 #endif
17 #define PAGFEXT ".pag"
18
19 typedef struct {
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 */
33 } DBM;
34
35 #define DBM_RDONLY      0x1            /* data base open read-only */
36 #define DBM_IOERR       0x2            /* data base I/O error */
37
38 /*
39  * utility macros
40  */
41 #define sdbm_rdonly(db)         ((db)->flags & DBM_RDONLY)
42 #define sdbm_error(db)          ((db)->flags & DBM_IOERR)
43
44 #define sdbm_clearerr(db)       ((db)->flags &= ~DBM_IOERR)  /* ouch */
45
46 #define sdbm_dirfno(db) ((db)->dirf)
47 #define sdbm_pagfno(db) ((db)->pagf)
48
49 typedef struct {
50         char *dptr;
51         int dsize;
52 } datum;
53
54 EXTCONST datum nullitem
55 #ifdef DOINIT
56                         = {0, 0}
57 #endif
58                                    ;
59
60 #if defined(__STDC__) || defined(__cplusplus) || defined(CAN_PROTOTYPE)
61 #define proto(p) p
62 #else
63 #define proto(p) ()
64 #endif
65
66 /*
67  * flags to sdbm_store
68  */
69 #define DBM_INSERT      0
70 #define DBM_REPLACE     1
71
72 /*
73  * ndbm interface
74  */
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 *));
82
83 /*
84  * other
85  */
86 extern DBM *sdbm_prep proto((char *, char *, int, int));
87 extern long sdbm_hash proto((char *, int));
88
89 #ifndef SDBM_ONLY
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
99 #endif
100
101 /* Most of the following is stolen from perl.h. */
102 #ifndef H_PERL  /* Include guard */
103
104 /*
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...
110  */
111
112 #include <errno.h>
113 #ifdef HAS_SOCKET
114 #   ifdef I_NET_ERRNO
115 #     include <net/errno.h>
116 #   endif
117 #endif
118
119 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
120 # define STANDARD_C 1
121 #endif
122
123 #include <stdio.h>
124 #include <ctype.h>
125 #include <setjmp.h>
126
127 #if defined(I_UNISTD)
128 #include <unistd.h>
129 #endif
130
131 #ifdef VMS
132 #  include <file.h>
133 #  include <unixio.h>
134 #endif
135
136 #if !defined(MSDOS) && !defined(WIN32) && !defined(VMS)
137 #   ifdef PARAM_NEEDS_TYPES
138 #       include <sys/types.h>
139 #   endif
140 #   include <sys/param.h>
141 #endif
142
143 #ifndef _TYPES_         /* If types.h defines this it's easy. */
144 #   ifndef major                /* Does everyone's types.h define this? */
145 #       include <sys/types.h>
146 #   endif
147 #endif
148
149 #include <sys/stat.h>
150
151 #ifndef SEEK_SET
152 # ifdef L_SET
153 #  define SEEK_SET      L_SET
154 # else
155 #  define SEEK_SET      0  /* Wild guess. */
156 # endif
157 #endif
158
159 /* Use all the "standard" definitions? */
160 #if defined(STANDARD_C) && defined(I_STDLIB)
161 #   include <stdlib.h>
162 #endif /* STANDARD_C */
163
164 #define MEM_SIZE Size_t
165
166 /* This comes after <stdlib.h> so we don't try to change the standard
167  * library prototypes; we'll use our own instead. */
168
169 #if defined(MYMALLOC) && (defined(HIDEMYMALLOC) || defined(EMBEDMYMALLOC))
170
171 #   ifdef HIDEMYMALLOC
172 #       define malloc  Mymalloc
173 #       define calloc  Mycalloc
174 #       define realloc Myremalloc
175 #       define free    Myfree
176 #   endif
177 #   ifdef EMBEDMYMALLOC
178 #       define malloc  Perl_malloc
179 #       define calloc  Perl_calloc
180 #       define realloc Perl_realloc
181 #       define free    Perl_free
182 #   endif
183
184     Malloc_t malloc proto((MEM_SIZE nbytes));
185     Malloc_t calloc proto((MEM_SIZE elements, MEM_SIZE size));
186     Malloc_t realloc proto((Malloc_t where, MEM_SIZE nbytes));
187     Free_t   free proto((Malloc_t where));
188
189 #endif /* MYMALLOC && (HIDEMYMALLOC || EMBEDMYMALLOC) */
190
191 #ifdef I_STRING
192 #include <string.h>
193 #else
194 #include <strings.h>
195 #endif
196
197 #ifdef I_MEMORY
198 #include <memory.h>
199 #endif      
200
201 #ifdef __cplusplus
202 #define HAS_MEMCPY
203 #endif
204
205 #ifdef HAS_MEMCPY
206 #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
207 #    ifndef memcpy
208         extern char * memcpy proto((char*, char*, int));
209 #    endif
210 #  endif
211 #else
212 #   ifndef memcpy
213 #       ifdef HAS_BCOPY
214 #           define memcpy(d,s,l) bcopy(s,d,l)
215 #       else
216 #           define memcpy(d,s,l) my_bcopy(s,d,l)
217 #       endif
218 #   endif
219 #endif /* HAS_MEMCPY */
220
221 #ifdef HAS_MEMSET
222 #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
223 #    ifndef memset
224         extern char *memset proto((char*, int, int));
225 #    endif
226 #  endif
227 #  define memzero(d,l) memset(d,0,l)
228 #else
229 #   ifndef memzero
230 #       ifdef HAS_BZERO
231 #           define memzero(d,l) bzero(d,l)
232 #       else
233 #           define memzero(d,l) my_bzero(d,l)
234 #       endif
235 #   endif
236 #endif /* HAS_MEMSET */
237
238 #if defined(mips) && defined(ultrix) && !defined(__STDC__)
239 #   undef HAS_MEMCMP
240 #endif
241
242 #if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
243 #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
244 #    ifndef memcmp
245         extern int memcmp proto((char*, char*, int));
246 #    endif
247 #  endif
248 #  ifdef BUGGY_MSC
249   #  pragma function(memcmp)
250 #  endif
251 #else
252 #   ifndef memcmp
253         /* maybe we should have included the full embedding header... */
254 #       ifdef NO_EMBED
255 #           define memcmp my_memcmp
256 #       else
257 #           define memcmp Perl_my_memcmp
258 #       endif
259 #ifndef __cplusplus
260         extern int memcmp proto((char*, char*, int));
261 #endif
262 #   endif
263 #endif /* HAS_MEMCMP */
264
265 #ifndef HAS_BCMP
266 #   ifndef bcmp
267 #       define bcmp(s1,s2,l) memcmp(s1,s2,l)
268 #   endif
269 #endif /* !HAS_BCMP */
270
271 #ifdef HAS_MEMCMP
272 #  define memNE(s1,s2,l) (memcmp(s1,s2,l))
273 #  define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
274 #else
275 #  define memNE(s1,s2,l) (bcmp(s1,s2,l))
276 #  define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
277 #endif
278
279 #ifdef I_NETINET_IN
280 #  ifdef VMS
281 #    include <in.h>
282 #  else
283 #    include <netinet/in.h>
284 #  endif
285 #endif
286
287 #endif /* Include guard */
288