dotsh.pl triggers new warnings
[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
86058a2d 171#if defined(MYMALLOC)
55497cff 172
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));
55497cff 182
86058a2d 183#endif /* MYMALLOC */
55497cff 184
a0d0e21e 185#ifdef I_STRING
186#include <string.h>
187#else
188#include <strings.h>
189#endif
190
191#ifdef I_MEMORY
192#include <memory.h>
f0f333f4 193#endif
194
195#ifdef __cplusplus
196#define HAS_MEMCPY
a0d0e21e 197#endif
198
85e6fe83 199#ifdef HAS_MEMCPY
200# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
201# ifndef memcpy
1e7d9bb3 202 extern char * memcpy proto((char*, char*, int));
85e6fe83 203# endif
204# endif
205#else
206# ifndef memcpy
207# ifdef HAS_BCOPY
208# define memcpy(d,s,l) bcopy(s,d,l)
209# else
210# define memcpy(d,s,l) my_bcopy(s,d,l)
211# endif
212# endif
213#endif /* HAS_MEMCPY */
214
215#ifdef HAS_MEMSET
216# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
217# ifndef memset
1e7d9bb3 218 extern char *memset proto((char*, int, int));
85e6fe83 219# endif
220# endif
221# define memzero(d,l) memset(d,0,l)
222#else
223# ifndef memzero
224# ifdef HAS_BZERO
225# define memzero(d,l) bzero(d,l)
226# else
227# define memzero(d,l) my_bzero(d,l)
228# endif
229# endif
230#endif /* HAS_MEMSET */
231
36477c24 232#if defined(mips) && defined(ultrix) && !defined(__STDC__)
233# undef HAS_MEMCMP
234#endif
235
236#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 237# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
238# ifndef memcmp
1e7d9bb3 239 extern int memcmp proto((char*, char*, int));
85e6fe83 240# endif
241# endif
36477c24 242# ifdef BUGGY_MSC
243 # pragma function(memcmp)
244# endif
85e6fe83 245#else
246# ifndef memcmp
bf99883d 247 /* maybe we should have included the full embedding header... */
36477c24 248# ifdef NO_EMBED
249# define memcmp my_memcmp
250# else
251# define memcmp Perl_my_memcmp
252# endif
f0f333f4 253#ifndef __cplusplus
1e7d9bb3 254 extern int memcmp proto((char*, char*, int));
f0f333f4 255#endif
85e6fe83 256# endif
257#endif /* HAS_MEMCMP */
258
85e6fe83 259#ifndef HAS_BCMP
260# ifndef bcmp
261# define bcmp(s1,s2,l) memcmp(s1,s2,l)
262# endif
36477c24 263#endif /* !HAS_BCMP */
264
265#ifdef HAS_MEMCMP
266# define memNE(s1,s2,l) (memcmp(s1,s2,l))
267# define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
268#else
269# define memNE(s1,s2,l) (bcmp(s1,s2,l))
270# define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
271#endif
85e6fe83 272
273#ifdef I_NETINET_IN
bf99883d 274# ifdef VMS
275# include <in.h>
276# else
277# include <netinet/in.h>
278# endif
85e6fe83 279#endif
280
281#endif /* Include guard */
4e35701f 282