applied suggested patch; added missing prototype changes to
[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 *));
f4b9d880 82extern int sdbm_exists proto((DBM *, datum));
463ee0b2 83
84/*
85 * other
86 */
87extern DBM *sdbm_prep proto((char *, char *, int, int));
88extern long sdbm_hash proto((char *, int));
89
90#ifndef SDBM_ONLY
ff68c719 91#define dbm_open sdbm_open
92#define dbm_close sdbm_close
93#define dbm_fetch sdbm_fetch
94#define dbm_store sdbm_store
95#define dbm_delete sdbm_delete
96#define dbm_firstkey sdbm_firstkey
97#define dbm_nextkey sdbm_nextkey
98#define dbm_error sdbm_error
99#define dbm_clearerr sdbm_clearerr
463ee0b2 100#endif
85e6fe83 101
102/* Most of the following is stolen from perl.h. */
103#ifndef H_PERL /* Include guard */
104
105/*
106 * The following contortions are brought to you on behalf of all the
107 * standards, semi-standards, de facto standards, not-so-de-facto standards
108 * of the world, as well as all the other botches anyone ever thought of.
109 * The basic theory is that if we work hard enough here, the rest of the
110 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
111 */
112
113#include <errno.h>
114#ifdef HAS_SOCKET
115# ifdef I_NET_ERRNO
116# include <net/errno.h>
117# endif
118#endif
119
85e6fe83 120#if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
121# define STANDARD_C 1
122#endif
123
85e6fe83 124#include <stdio.h>
125#include <ctype.h>
126#include <setjmp.h>
127
17f28c40 128#if defined(I_UNISTD)
85e6fe83 129#include <unistd.h>
130#endif
131
bf99883d 132#ifdef VMS
17f28c40 133# include <file.h>
134# include <unixio.h>
bf99883d 135#endif
136
28e8609d 137#ifdef I_SYS_PARAM
138# if !defined(MSDOS) && !defined(WIN32) && !defined(VMS)
139# ifdef PARAM_NEEDS_TYPES
140# include <sys/types.h>
141# endif
142# include <sys/param.h>
85e6fe83 143# endif
85e6fe83 144#endif
145
146#ifndef _TYPES_ /* If types.h defines this it's easy. */
147# ifndef major /* Does everyone's types.h define this? */
148# include <sys/types.h>
149# endif
150#endif
151
85e6fe83 152#include <sys/stat.h>
153
154#ifndef SEEK_SET
155# ifdef L_SET
156# define SEEK_SET L_SET
157# else
158# define SEEK_SET 0 /* Wild guess. */
159# endif
160#endif
161
162/* Use all the "standard" definitions? */
94b6baf5 163#if defined(STANDARD_C) && defined(I_STDLIB)
85e6fe83 164# include <stdlib.h>
85e6fe83 165#endif /* STANDARD_C */
166
a0d0e21e 167#define MEM_SIZE Size_t
168
55497cff 169/* This comes after <stdlib.h> so we don't try to change the standard
170 * library prototypes; we'll use our own instead. */
171
08cdc9a3 172#if defined(MYMALLOC) && !defined(PERL_POLLUTE_MALLOC)
86058a2d 173# define malloc Perl_malloc
174# define calloc Perl_calloc
175# define realloc Perl_realloc
176# define free Perl_mfree
55497cff 177
86058a2d 178Malloc_t Perl_malloc proto((MEM_SIZE nbytes));
179Malloc_t Perl_calloc proto((MEM_SIZE elements, MEM_SIZE size));
180Malloc_t Perl_realloc proto((Malloc_t where, MEM_SIZE nbytes));
181Free_t Perl_mfree proto((Malloc_t where));
86058a2d 182#endif /* MYMALLOC */
55497cff 183
a0d0e21e 184#ifdef I_STRING
185#include <string.h>
186#else
187#include <strings.h>
188#endif
189
190#ifdef I_MEMORY
191#include <memory.h>
f0f333f4 192#endif
193
194#ifdef __cplusplus
195#define HAS_MEMCPY
a0d0e21e 196#endif
197
85e6fe83 198#ifdef HAS_MEMCPY
199# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
200# ifndef memcpy
1e7d9bb3 201 extern char * memcpy proto((char*, char*, int));
85e6fe83 202# endif
203# endif
204#else
205# ifndef memcpy
206# ifdef HAS_BCOPY
207# define memcpy(d,s,l) bcopy(s,d,l)
208# else
209# define memcpy(d,s,l) my_bcopy(s,d,l)
210# endif
211# endif
212#endif /* HAS_MEMCPY */
213
214#ifdef HAS_MEMSET
215# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
216# ifndef memset
1e7d9bb3 217 extern char *memset proto((char*, int, int));
85e6fe83 218# endif
219# endif
220# define memzero(d,l) memset(d,0,l)
221#else
222# ifndef memzero
223# ifdef HAS_BZERO
224# define memzero(d,l) bzero(d,l)
225# else
226# define memzero(d,l) my_bzero(d,l)
227# endif
228# endif
229#endif /* HAS_MEMSET */
230
36477c24 231#if defined(mips) && defined(ultrix) && !defined(__STDC__)
232# undef HAS_MEMCMP
233#endif
234
235#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 236# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
237# ifndef memcmp
1e7d9bb3 238 extern int memcmp proto((char*, char*, int));
85e6fe83 239# endif
240# endif
36477c24 241# ifdef BUGGY_MSC
242 # pragma function(memcmp)
243# endif
85e6fe83 244#else
245# ifndef memcmp
bf99883d 246 /* maybe we should have included the full embedding header... */
36477c24 247# ifdef NO_EMBED
248# define memcmp my_memcmp
249# else
250# define memcmp Perl_my_memcmp
251# endif
f0f333f4 252#ifndef __cplusplus
1e7d9bb3 253 extern int memcmp proto((char*, char*, int));
f0f333f4 254#endif
85e6fe83 255# endif
256#endif /* HAS_MEMCMP */
257
85e6fe83 258#ifndef HAS_BCMP
259# ifndef bcmp
260# define bcmp(s1,s2,l) memcmp(s1,s2,l)
261# endif
36477c24 262#endif /* !HAS_BCMP */
263
264#ifdef HAS_MEMCMP
265# define memNE(s1,s2,l) (memcmp(s1,s2,l))
266# define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
267#else
268# define memNE(s1,s2,l) (bcmp(s1,s2,l))
269# define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
270#endif
85e6fe83 271
272#ifdef I_NETINET_IN
bf99883d 273# ifdef VMS
274# include <in.h>
275# else
276# include <netinet/in.h>
277# endif
85e6fe83 278#endif
279
280#endif /* Include guard */
4e35701f 281