integrate cfgperl changes into mainline
[p5sagit/p5-mst-13.2.git] / ext / SDBM_File / sdbm / sdbm.h
CommitLineData
463ee0b2 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 */
bf99883d 12#ifdef VMS
13#define DIRFEXT ".sdbm_dir"
14#else
463ee0b2 15#define DIRFEXT ".dir"
bf99883d 16#endif
463ee0b2 17#define PAGFEXT ".pag"
18
19typedef 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
49typedef struct {
50 char *dptr;
51 int dsize;
52} datum;
53
17f28c40 54EXTCONST datum nullitem
55#ifdef DOINIT
dd2664b9 56 = {0, 0}
17f28c40 57#endif
58 ;
463ee0b2 59
c31fac66 60#if defined(__STDC__) || defined(__cplusplus) || defined(CAN_PROTOTYPE)
463ee0b2 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 */
75extern DBM *sdbm_open proto((char *, int, int));
76extern void sdbm_close proto((DBM *));
77extern datum sdbm_fetch proto((DBM *, datum));
78extern int sdbm_delete proto((DBM *, datum));
79extern int sdbm_store proto((DBM *, datum, datum, int));
80extern datum sdbm_firstkey proto((DBM *));
81extern datum sdbm_nextkey proto((DBM *));
82
83/*
84 * other
85 */
86extern DBM *sdbm_prep proto((char *, char *, int, int));
87extern long sdbm_hash proto((char *, int));
88
89#ifndef SDBM_ONLY
ff68c719 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
463ee0b2 99#endif
85e6fe83 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
85e6fe83 119#if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
120# define STANDARD_C 1
121#endif
122
85e6fe83 123#include <stdio.h>
124#include <ctype.h>
125#include <setjmp.h>
126
17f28c40 127#if defined(I_UNISTD)
85e6fe83 128#include <unistd.h>
129#endif
130
bf99883d 131#ifdef VMS
17f28c40 132# include <file.h>
133# include <unixio.h>
bf99883d 134#endif
135
28e8609d 136#ifdef I_SYS_PARAM
137# if !defined(MSDOS) && !defined(WIN32) && !defined(VMS)
138# ifdef PARAM_NEEDS_TYPES
139# include <sys/types.h>
140# endif
141# include <sys/param.h>
85e6fe83 142# endif
85e6fe83 143#endif
144
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>
148# endif
149#endif
150
85e6fe83 151#include <sys/stat.h>
152
153#ifndef SEEK_SET
154# ifdef L_SET
155# define SEEK_SET L_SET
156# else
157# define SEEK_SET 0 /* Wild guess. */
158# endif
159#endif
160
161/* Use all the "standard" definitions? */
94b6baf5 162#if defined(STANDARD_C) && defined(I_STDLIB)
85e6fe83 163# include <stdlib.h>
85e6fe83 164#endif /* STANDARD_C */
165
a0d0e21e 166#define MEM_SIZE Size_t
167
55497cff 168/* This comes after <stdlib.h> so we don't try to change the standard
169 * library prototypes; we'll use our own instead. */
170
171#if defined(MYMALLOC) && (defined(HIDEMYMALLOC) || defined(EMBEDMYMALLOC))
172
173# ifdef HIDEMYMALLOC
174# define malloc Mymalloc
175# define calloc Mycalloc
176# define realloc Myremalloc
177# define free Myfree
178# endif
179# ifdef EMBEDMYMALLOC
180# define malloc Perl_malloc
181# define calloc Perl_calloc
182# define realloc Perl_realloc
183# define free Perl_free
184# endif
185
1e7d9bb3 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));
55497cff 190
191#endif /* MYMALLOC && (HIDEMYMALLOC || EMBEDMYMALLOC) */
192
a0d0e21e 193#ifdef I_STRING
194#include <string.h>
195#else
196#include <strings.h>
197#endif
198
199#ifdef I_MEMORY
200#include <memory.h>
f0f333f4 201#endif
202
203#ifdef __cplusplus
204#define HAS_MEMCPY
a0d0e21e 205#endif
206
85e6fe83 207#ifdef HAS_MEMCPY
208# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
209# ifndef memcpy
1e7d9bb3 210 extern char * memcpy proto((char*, char*, int));
85e6fe83 211# endif
212# endif
213#else
214# ifndef memcpy
215# ifdef HAS_BCOPY
216# define memcpy(d,s,l) bcopy(s,d,l)
217# else
218# define memcpy(d,s,l) my_bcopy(s,d,l)
219# endif
220# endif
221#endif /* HAS_MEMCPY */
222
223#ifdef HAS_MEMSET
224# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
225# ifndef memset
1e7d9bb3 226 extern char *memset proto((char*, int, int));
85e6fe83 227# endif
228# endif
229# define memzero(d,l) memset(d,0,l)
230#else
231# ifndef memzero
232# ifdef HAS_BZERO
233# define memzero(d,l) bzero(d,l)
234# else
235# define memzero(d,l) my_bzero(d,l)
236# endif
237# endif
238#endif /* HAS_MEMSET */
239
36477c24 240#if defined(mips) && defined(ultrix) && !defined(__STDC__)
241# undef HAS_MEMCMP
242#endif
243
244#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 245# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
246# ifndef memcmp
1e7d9bb3 247 extern int memcmp proto((char*, char*, int));
85e6fe83 248# endif
249# endif
36477c24 250# ifdef BUGGY_MSC
251 # pragma function(memcmp)
252# endif
85e6fe83 253#else
254# ifndef memcmp
bf99883d 255 /* maybe we should have included the full embedding header... */
36477c24 256# ifdef NO_EMBED
257# define memcmp my_memcmp
258# else
259# define memcmp Perl_my_memcmp
260# endif
f0f333f4 261#ifndef __cplusplus
1e7d9bb3 262 extern int memcmp proto((char*, char*, int));
f0f333f4 263#endif
85e6fe83 264# endif
265#endif /* HAS_MEMCMP */
266
85e6fe83 267#ifndef HAS_BCMP
268# ifndef bcmp
269# define bcmp(s1,s2,l) memcmp(s1,s2,l)
270# endif
36477c24 271#endif /* !HAS_BCMP */
272
273#ifdef HAS_MEMCMP
274# define memNE(s1,s2,l) (memcmp(s1,s2,l))
275# define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
276#else
277# define memNE(s1,s2,l) (bcmp(s1,s2,l))
278# define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
279#endif
85e6fe83 280
281#ifdef I_NETINET_IN
bf99883d 282# ifdef VMS
283# include <in.h>
284# else
285# include <netinet/in.h>
286# endif
85e6fe83 287#endif
288
289#endif /* Include guard */
4e35701f 290