2
* Copyright (c) 1991, 1993
3
* The Regents of the University of California. All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. All advertising materials mentioning features or use of this software
14
* must display the following acknowledgement:
15
* This product includes software developed by the University of
16
* California, Berkeley and its contributors.
17
* 4. Neither the name of the University nor the names of its contributors
18
* may be used to endorse or promote products derived from this software
19
* without specific prior written permission.
21
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
* @(#)compat.h 8.13 (Berkeley) 2/21/94
42
/* deal with autoconf-based stuff */
44
#define DB_LITTLE_ENDIAN 1234
45
#define DB_BIG_ENDIAN 4321
51
#ifdef HAVE_MACHINE_ENDIAN_H
52
# include <machine/endian.h>
54
#ifdef HAVE_SYS_PARAM_H
55
# include <sys/param.h>
57
/* Handle both BIG and LITTLE defined and BYTE_ORDER matches one, or
58
just one defined; both with and without leading underscores.
60
Ignore "PDP endian" machines, this code doesn't support them
62
#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER)
63
# ifdef __LITTLE_ENDIAN__
64
# define LITTLE_ENDIAN __LITTLE_ENDIAN__
66
# ifdef __BIG_ENDIAN__
67
# define BIG_ENDIAN __BIG_ENDIAN__
70
#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER)
71
# ifdef _LITTLE_ENDIAN
72
# define LITTLE_ENDIAN _LITTLE_ENDIAN
75
# define BIG_ENDIAN _BIG_ENDIAN
78
# define BYTE_ORDER _BYTE_ORDER
81
#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER)
82
# ifdef __LITTLE_ENDIAN
83
# define LITTLE_ENDIAN __LITTLE_ENDIAN
86
# define BIG_ENDIAN __BIG_ENDIAN
89
# define BYTE_ORDER __BYTE_ORDER
93
#if defined(_MIPSEL) && !defined(LITTLE_ENDIAN)
94
# define LITTLE_ENDIAN
96
#if defined(_MIPSEB) && !defined(BIG_ENDIAN)
100
#if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) && defined(BYTE_ORDER)
101
# if LITTLE_ENDIAN == BYTE_ORDER
102
# define DB_BYTE_ORDER DB_LITTLE_ENDIAN
103
# elif BIG_ENDIAN == BYTE_ORDER
104
# define DB_BYTE_ORDER DB_BIG_ENDIAN
106
# error "LITTLE_ENDIAN and BIG_ENDIAN defined, but can't determine byte order"
108
#elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
109
# define DB_BYTE_ORDER DB_LITTLE_ENDIAN
110
#elif defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
111
# define DB_BYTE_ORDER DB_BIG_ENDIAN
113
# error "can't determine byte order from included system headers"
117
#ifdef WORDS_BIGENDIAN
118
#define DB_BYTE_ORDER DB_BIG_ENDIAN
120
#define DB_BYTE_ORDER DB_LITTLE_ENDIAN
124
/* end autoconf-based stuff */
126
/* include necessary system header files */
138
#ifdef HAVE_INTTYPES_H
139
/* Tru64 5.1: int8_t is defined here, and stdint.h doesn't exist. */
140
#include <inttypes.h>
142
#include <sys/types.h>
143
#include <sys/stat.h>
144
#include <sys/param.h>
146
/* types and constants used for database structure */
148
#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
149
typedef u_int32_t db_pgno_t;
150
#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
151
typedef u_int16_t indx_t;
152
#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
153
typedef u_int32_t recno_t;
156
* Little endian <==> big endian 32-bit swap macros.
157
* M_32_SWAP swap a memory location
158
* P_32_SWAP swap a referenced memory location
159
* P_32_COPY swap from one location to another
161
#define M_32_SWAP(a) { \
162
u_int32_t _tmp = a; \
163
((char *)&a)[0] = ((char *)&_tmp)[3]; \
164
((char *)&a)[1] = ((char *)&_tmp)[2]; \
165
((char *)&a)[2] = ((char *)&_tmp)[1]; \
166
((char *)&a)[3] = ((char *)&_tmp)[0]; \
168
#define P_32_SWAP(a) { \
169
u_int32_t _tmp = *(u_int32_t *)a; \
170
((char *)a)[0] = ((char *)&_tmp)[3]; \
171
((char *)a)[1] = ((char *)&_tmp)[2]; \
172
((char *)a)[2] = ((char *)&_tmp)[1]; \
173
((char *)a)[3] = ((char *)&_tmp)[0]; \
175
#define P_32_COPY(a, b) { \
176
((char *)&(b))[0] = ((char *)&(a))[3]; \
177
((char *)&(b))[1] = ((char *)&(a))[2]; \
178
((char *)&(b))[2] = ((char *)&(a))[1]; \
179
((char *)&(b))[3] = ((char *)&(a))[0]; \
183
* Little endian <==> big endian 16-bit swap macros.
184
* M_16_SWAP swap a memory location
185
* P_16_SWAP swap a referenced memory location
186
* P_16_COPY swap from one location to another
188
#define M_16_SWAP(a) { \
189
u_int16_t _tmp = a; \
190
((char *)&a)[0] = ((char *)&_tmp)[1]; \
191
((char *)&a)[1] = ((char *)&_tmp)[0]; \
193
#define P_16_SWAP(a) { \
194
u_int16_t _tmp = *(u_int16_t *)a; \
195
((char *)a)[0] = ((char *)&_tmp)[1]; \
196
((char *)a)[1] = ((char *)&_tmp)[0]; \
198
#define P_16_COPY(a, b) { \
199
((char *)&(b))[0] = ((char *)&(a))[1]; \
200
((char *)&(b))[1] = ((char *)&(a))[0]; \
203
/* open functions for each database type, used in dbopen() */
205
#define __bt_open __kdb2_bt_open
206
#define __hash_open __kdb2_hash_open
207
#define __rec_open __kdb2_rec_open
208
#define __dbpanic __kdb2_dbpanic
210
DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
211
DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));
212
DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
213
void __dbpanic __P((DB *dbp));
216
* There is no portable way to figure out the maximum value of a file
217
* offset, so we put it here.
220
#define DB_OFF_T_MAX OFF_T_MAX
222
#define DB_OFF_T_MAX LONG_MAX
225
#ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */
226
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
230
* If you can't provide lock values in the open(2) call. Note, this
231
* allows races to happen.
233
#ifndef O_EXLOCK /* 4.4BSD extension. */
237
#ifndef O_SHLOCK /* 4.4BSD extension. */
242
#define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
245
#ifndef STDERR_FILENO
246
#define STDIN_FILENO 0 /* ANSI C #defines */
247
#define STDOUT_FILENO 1
248
#define STDERR_FILENO 2
252
#define SEEK_SET 0 /* POSIX 1003.1 seek values */
257
#ifndef NULL /* ANSI C #defines NULL everywhere. */
261
#ifndef MAX /* Usually found in <sys/param.h>. */
262
#define MAX(_a,_b) ((_a)<(_b)?(_b):(_a))
264
#ifndef MIN /* Usually found in <sys/param.h>. */
265
#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
268
#ifndef S_ISDIR /* POSIX 1003.1 file type tests. */
269
#define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */
270
#define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */
271
#define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */
272
#define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */
273
#define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */
275
#ifndef S_ISLNK /* BSD POSIX 1003.1 extensions */
276
#define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */
277
#define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */
281
#define O_BINARY 0 /* Needed for Win32 compiles */
283
#endif /* _DB_INT_H_ */