This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Constant data in .c, not in a .h
[perl5.git] / ext / SDBM_File / sdbm.h
CommitLineData
463ee0b2
LW
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
HM
12#ifdef VMS
13#define DIRFEXT ".sdbm_dir"
14#else
463ee0b2 15#define DIRFEXT ".dir"
bf99883d 16#endif
463ee0b2
LW
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 {
d3f5e399 50 const char *dptr;
463ee0b2
LW
51 int dsize;
52} datum;
53
7b3bf35e 54extern const datum nullitem;
463ee0b2 55
c31fac66 56#if defined(__STDC__) || defined(__cplusplus) || defined(CAN_PROTOTYPE)
463ee0b2
LW
57#define proto(p) p
58#else
59#define proto(p) ()
60#endif
61
62/*
63 * flags to sdbm_store
64 */
65#define DBM_INSERT 0
66#define DBM_REPLACE 1
67
68/*
69 * ndbm interface
70 */
71extern DBM *sdbm_open proto((char *, int, int));
72extern void sdbm_close proto((DBM *));
73extern datum sdbm_fetch proto((DBM *, datum));
74extern int sdbm_delete proto((DBM *, datum));
75extern int sdbm_store proto((DBM *, datum, datum, int));
76extern datum sdbm_firstkey proto((DBM *));
77extern datum sdbm_nextkey proto((DBM *));
f4b9d880 78extern int sdbm_exists proto((DBM *, datum));
463ee0b2
LW
79
80/*
81 * other
82 */
83extern DBM *sdbm_prep proto((char *, char *, int, int));
d3f5e399 84extern long sdbm_hash proto((const char *, int));
463ee0b2
LW
85
86#ifndef SDBM_ONLY
ff68c719
PP
87#define dbm_open sdbm_open
88#define dbm_close sdbm_close
89#define dbm_fetch sdbm_fetch
90#define dbm_store sdbm_store
91#define dbm_delete sdbm_delete
92#define dbm_firstkey sdbm_firstkey
93#define dbm_nextkey sdbm_nextkey
94#define dbm_error sdbm_error
95#define dbm_clearerr sdbm_clearerr
463ee0b2 96#endif
85e6fe83 97
72d0d2ff
AD
98/* Most of the following is stolen from perl.h. We don't include
99 perl.h here because we just want the portability parts of perl.h,
100 not everything else.
101*/
85e6fe83 102#ifndef H_PERL /* Include guard */
72d0d2ff 103#include "embed.h" /* Follow all the global renamings. */
85e6fe83
LW
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
LW
120#if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
121# define STANDARD_C 1
122#endif
123
85e6fe83
LW
124#include <stdio.h>
125#include <ctype.h>
126#include <setjmp.h>
127
17f28c40 128#if defined(I_UNISTD)
85e6fe83
LW
129#include <unistd.h>
130#endif
131
bf99883d 132#ifdef VMS
17f28c40
CB
133# include <file.h>
134# include <unixio.h>
bf99883d
HM
135#endif
136
28e8609d
JH
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
LW
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
LW
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
LW
165#endif /* STANDARD_C */
166
a0d0e21e
LW
167#define MEM_SIZE Size_t
168
55497cff
PP
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
GS
173# define malloc Perl_malloc
174# define calloc Perl_calloc
175# define realloc Perl_realloc
176# define free Perl_mfree
55497cff 177
86f11a3d
CB
178#ifdef __cplusplus
179extern "C" {
180#endif
181
86058a2d
GS
182Malloc_t Perl_malloc proto((MEM_SIZE nbytes));
183Malloc_t Perl_calloc proto((MEM_SIZE elements, MEM_SIZE size));
184Malloc_t Perl_realloc proto((Malloc_t where, MEM_SIZE nbytes));
185Free_t Perl_mfree proto((Malloc_t where));
86f11a3d
CB
186
187#ifdef __cplusplus
188}
189#endif
190
86058a2d 191#endif /* MYMALLOC */
55497cff 192
a0d0e21e 193#ifdef I_STRING
5518ecd4
JH
194# ifndef __ultrix__
195# include <string.h>
196# endif
a0d0e21e 197#else
5518ecd4 198# include <strings.h>
a0d0e21e
LW
199#endif
200
201#ifdef I_MEMORY
202#include <memory.h>
f0f333f4
NIS
203#endif
204
205#ifdef __cplusplus
206#define HAS_MEMCPY
a0d0e21e
LW
207#endif
208
85e6fe83
LW
209#ifdef HAS_MEMCPY
210# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
211# ifndef memcpy
1e7d9bb3 212 extern char * memcpy proto((char*, char*, int));
85e6fe83
LW
213# endif
214# endif
215#else
216# ifndef memcpy
217# ifdef HAS_BCOPY
218# define memcpy(d,s,l) bcopy(s,d,l)
219# else
220# define memcpy(d,s,l) my_bcopy(s,d,l)
221# endif
222# endif
223#endif /* HAS_MEMCPY */
224
225#ifdef HAS_MEMSET
226# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
227# ifndef memset
1e7d9bb3 228 extern char *memset proto((char*, int, int));
85e6fe83
LW
229# endif
230# endif
231# define memzero(d,l) memset(d,0,l)
232#else
233# ifndef memzero
234# ifdef HAS_BZERO
235# define memzero(d,l) bzero(d,l)
236# else
237# define memzero(d,l) my_bzero(d,l)
238# endif
239# endif
240#endif /* HAS_MEMSET */
241
36477c24
PP
242#if defined(mips) && defined(ultrix) && !defined(__STDC__)
243# undef HAS_MEMCMP
244#endif
245
246#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83
LW
247# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
248# ifndef memcmp
1e7d9bb3 249 extern int memcmp proto((char*, char*, int));
85e6fe83
LW
250# endif
251# endif
36477c24 252# ifdef BUGGY_MSC
7e4e8c89 253# pragma function(memcmp)
36477c24 254# endif
85e6fe83
LW
255#else
256# ifndef memcmp
bf99883d 257 /* maybe we should have included the full embedding header... */
bce1a96b 258# define memcmp Perl_my_memcmp
f0f333f4 259#ifndef __cplusplus
1e7d9bb3 260 extern int memcmp proto((char*, char*, int));
f0f333f4 261#endif
85e6fe83
LW
262# endif
263#endif /* HAS_MEMCMP */
264
85e6fe83
LW
265#ifndef HAS_BCMP
266# ifndef bcmp
267# define bcmp(s1,s2,l) memcmp(s1,s2,l)
268# endif
36477c24
PP
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
85e6fe83
LW
278
279#ifdef I_NETINET_IN
bf99883d
HM
280# ifdef VMS
281# include <in.h>
282# else
283# include <netinet/in.h>
284# endif
85e6fe83
LW
285#endif
286
287#endif /* Include guard */
4e35701f 288