Bug 359675 - provide an option to manually fill forms and log in. p=poshannessy@mozil...
[wine-gecko.git] / dbm / include / mcom_db.h
blobd265f432256886db6067d8b3de509a87267826b0
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*-
3 * Copyright (c) 1990, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. ***REMOVED*** - see
15 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
32 * @(#)db.h 8.7 (Berkeley) 6/16/94
35 #ifndef _DB_H_
36 #define _DB_H_
39 #ifdef WINCE
40 #define off_t long
41 #endif
43 #ifndef macintosh
44 #include <sys/types.h>
45 #endif
46 #include "prtypes.h"
48 #include <limits.h>
50 #ifdef __DBINTERFACE_PRIVATE
52 #ifdef HAVE_SYS_CDEFS_H
53 #include <sys/cdefs.h>
54 #else
55 #include "cdefs.h"
56 #endif
58 #ifdef HAVE_SYS_BYTEORDER_H
59 #include <sys/byteorder.h>
60 #endif
62 #if defined(__linux) || defined(__BEOS__)
63 #include <endian.h>
64 #ifndef BYTE_ORDER
65 #define BYTE_ORDER __BYTE_ORDER
66 #define BIG_ENDIAN __BIG_ENDIAN
67 #define LITTLE_ENDIAN __LITTLE_ENDIAN
68 #endif
69 #endif /* __linux */
71 #ifdef __sgi
72 #define BYTE_ORDER BIG_ENDIAN
73 #define BIG_ENDIAN 4321
74 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
75 #endif
77 #ifdef __sun
78 #define BIG_ENDIAN 4321
79 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
81 #ifndef __SVR4
82 /* compat.h is only in 4.1.3 machines. - dp */
83 #include <compat.h>
84 #endif
86 /* XXX - dp
87 * Need to find a general way of defining endian-ness in SunOS 5.3
88 * SunOS 5.4 defines _BIG_ENDIAN and _LITTLE_ENDIAN
89 * SunOS 5.3 does nothing like this.
92 #ifndef BYTE_ORDER
94 #if defined(_BIG_ENDIAN)
95 #define BYTE_ORDER BIG_ENDIAN
96 #elif defined(_LITTLE_ENDIAN)
97 #define BYTE_ORDER LITTLE_ENDIAN
98 #elif !defined(__SVR4)
99 /* 4.1.3 is always BIG_ENDIAN as it was released only on sparc platforms. */
100 #define BYTE_ORDER BIG_ENDIAN
101 #elif !defined(vax) && !defined(ntohl) && !defined(lint) && !defined(i386)
102 /* 5.3 big endian. Copied this above line from sys/byteorder.h */
103 /* Now we are in a 5.3 SunOS rather non 5.4 or above SunOS */
104 #define BYTE_ORDER BIG_ENDIAN
105 #else
106 #define BYTE_ORDER LITTLE_ENDIAN
107 #endif
109 #endif /* !BYTE_ORDER */
110 #endif /* __sun */
112 #if defined(__hpux) || defined(__hppa)
113 #define BYTE_ORDER BIG_ENDIAN
114 #define BIG_ENDIAN 4321
115 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
116 #endif
118 #if defined(AIXV3) || defined(AIX)
119 /* BYTE_ORDER, LITTLE_ENDIAN, BIG_ENDIAN are all defined here */
120 #include <sys/machine.h>
121 #endif
123 /* Digital Unix */
124 #ifdef __osf__
125 #include <machine/endian.h>
126 #endif
128 #ifdef __alpha
129 #ifndef WIN32
130 #else
131 /* Alpha NT */
132 #define BYTE_ORDER LITTLE_ENDIAN
133 #define BIG_ENDIAN 4321
134 #define LITTLE_ENDIAN 1234
135 #endif
136 #endif
138 #ifdef NCR
139 #include <sys/endian.h>
140 #endif
142 #ifdef __QNX__
143 #ifdef __QNXNTO__
144 #include <sys/param.h>
145 #else
146 #define LITTLE_ENDIAN 1234
147 #define BIG_ENDIAN 4321
148 #define BYTE_ORDER LITTLE_ENDIAN
149 #endif
150 #endif
152 #ifdef SNI
153 /* #include <sys/hetero.h> */
154 #define BYTE_ORDER BIG_ENDIAN
155 #define BIG_ENDIAN 4321
156 #define LITTLE_ENDIAN 1234
157 #endif
159 #if defined(_WINDOWS) || defined(XP_OS2_VACPP)
160 #ifdef BYTE_ORDER
161 #undef BYTE_ORDER
162 #endif
164 #define BYTE_ORDER LITTLE_ENDIAN
165 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
166 #define BIG_ENDIAN 4321
167 #endif
169 #ifdef macintosh
170 #define BIG_ENDIAN 4321
171 #define LITTLE_ENDIAN 1234
172 #define BYTE_ORDER BIG_ENDIAN
173 #endif
175 #endif /* __DBINTERFACE_PRIVATE */
177 #ifdef SCO
178 #define MAXPATHLEN 1024
179 #endif
181 #include <fcntl.h>
183 #if defined(_WINDOWS) || defined(XP_OS2)
184 #include <stdio.h>
185 #include <io.h>
187 #ifndef XP_OS2
188 #define MAXPATHLEN 1024
189 #endif
191 #ifdef XP_OS2_VACPP
192 #include <os2.h>
193 #define MAXPATHLEN CCHMAXPATH
194 #define EPERM EINVAL
195 #define ENOTDIR EBADPOS
196 #define S_ISDIR(s) ((s) & S_IFDIR)
197 #endif
199 #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
201 #ifndef STDERR_FILENO
202 #define STDIN_FILENO 0 /* ANSI C #defines */
203 #define STDOUT_FILENO 1
204 #define STDERR_FILENO 2
205 #endif
207 #ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */
208 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
209 #endif
210 #endif
212 #ifdef macintosh
213 #include <stdio.h>
214 #include "xp_mcom.h"
215 #define O_ACCMODE 3 /* Mask for file access modes */
216 #define EFTYPE 2000
217 PR_BEGIN_EXTERN_C
218 int mkstemp(const char *path);
219 PR_END_EXTERN_C
220 #endif /* MACINTOSH */
222 #if !defined(_WINDOWS) && !defined(macintosh)
223 #include <sys/stat.h>
224 #include <errno.h>
225 #endif
227 /* define EFTYPE since most don't */
228 #ifndef EFTYPE
229 #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
230 #endif
232 #define RET_ERROR -1 /* Return values. */
233 #define RET_SUCCESS 0
234 #define RET_SPECIAL 1
236 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
238 #ifndef __sgi
239 typedef uint32 pgno_t;
240 #endif
242 #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
243 typedef uint16 indx_t;
244 #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
245 typedef uint32 recno_t;
247 /* Key/data structure -- a Data-Base Thang. */
248 typedef struct {
249 void *data; /* data */
250 size_t size; /* data length */
251 } DBT;
253 /* Routine flags. */
254 #define R_CURSOR 1 /* del, put, seq */
255 #define __R_UNUSED 2 /* UNUSED */
256 #define R_FIRST 3 /* seq */
257 #define R_IAFTER 4 /* put (RECNO) */
258 #define R_IBEFORE 5 /* put (RECNO) */
259 #define R_LAST 6 /* seq (BTREE, RECNO) */
260 #define R_NEXT 7 /* seq */
261 #define R_NOOVERWRITE 8 /* put */
262 #define R_PREV 9 /* seq (BTREE, RECNO) */
263 #define R_SETCURSOR 10 /* put (RECNO) */
264 #define R_RECNOSYNC 11 /* sync (RECNO) */
266 typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
268 typedef enum { LockOutDatabase, UnlockDatabase } DBLockFlagEnum;
271 * !!!
272 * The following flags are included in the dbopen(3) call as part of the
273 * open(2) flags. In order to avoid conflicts with the open flags, start
274 * at the top of the 16 or 32-bit number space and work our way down. If
275 * the open flags were significantly expanded in the future, it could be
276 * a problem. Wish I'd left another flags word in the dbopen call.
278 * !!!
279 * None of this stuff is implemented yet. The only reason that it's here
280 * is so that the access methods can skip copying the key/data pair when
281 * the DB_LOCK flag isn't set.
283 #if UINT_MAX > 65535
284 #define DB_LOCK 0x20000000 /* Do locking. */
285 #define DB_SHMEM 0x40000000 /* Use shared memory. */
286 #define DB_TXN 0x80000000 /* Do transactions. */
287 #else
288 #define DB_LOCK 0x2000 /* Do locking. */
289 #define DB_SHMEM 0x4000 /* Use shared memory. */
290 #define DB_TXN 0x8000 /* Do transactions. */
291 #endif
293 /* Access method description structure. */
294 typedef struct __db {
295 DBTYPE type; /* Underlying db type. */
296 int (*close) (struct __db *);
297 int (*del) (const struct __db *, const DBT *, uint);
298 int (*get) (const struct __db *, const DBT *, DBT *, uint);
299 int (*put) (const struct __db *, DBT *, const DBT *, uint);
300 int (*seq) (const struct __db *, DBT *, DBT *, uint);
301 int (*sync) (const struct __db *, uint);
302 void *internal; /* Access method private. */
303 int (*fd) (const struct __db *);
304 } DB;
306 #define BTREEMAGIC 0x053162
307 #define BTREEVERSION 3
309 /* Structure used to pass parameters to the btree routines. */
310 typedef struct {
311 #define R_DUP 0x01 /* duplicate keys */
312 uint32 flags;
313 uint cachesize; /* bytes to cache */
314 int maxkeypage; /* maximum keys per page */
315 int minkeypage; /* minimum keys per page */
316 uint psize; /* page size */
317 int (*compare) /* comparison function */
318 (const DBT *, const DBT *);
319 size_t (*prefix) /* prefix function */
320 (const DBT *, const DBT *);
321 int lorder; /* byte order */
322 } BTREEINFO;
324 #define HASHMAGIC 0x061561
325 #define HASHVERSION 2
327 /* Structure used to pass parameters to the hashing routines. */
328 typedef struct {
329 uint bsize; /* bucket size */
330 uint ffactor; /* fill factor */
331 uint nelem; /* number of elements */
332 uint cachesize; /* bytes to cache */
333 uint32 /* hash function */
334 (*hash) (const void *, size_t);
335 int lorder; /* byte order */
336 } HASHINFO;
338 /* Structure used to pass parameters to the record routines. */
339 typedef struct {
340 #define R_FIXEDLEN 0x01 /* fixed-length records */
341 #define R_NOKEY 0x02 /* key not required */
342 #define R_SNAPSHOT 0x04 /* snapshot the input */
343 uint32 flags;
344 uint cachesize; /* bytes to cache */
345 uint psize; /* page size */
346 int lorder; /* byte order */
347 size_t reclen; /* record length (fixed-length records) */
348 uint8 bval; /* delimiting byte (variable-length records */
349 char *bfname; /* btree file name */
350 } RECNOINFO;
352 #ifdef __DBINTERFACE_PRIVATE
354 * Little endian <==> big endian 32-bit swap macros.
355 * M_32_SWAP swap a memory location
356 * P_32_SWAP swap a referenced memory location
357 * P_32_COPY swap from one location to another
359 #define M_32_SWAP(a) { \
360 uint32 _tmp = a; \
361 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
362 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
363 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
364 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
366 #define P_32_SWAP(a) { \
367 uint32 _tmp = *(uint32 *)a; \
368 ((char *)a)[0] = ((char *)&_tmp)[3]; \
369 ((char *)a)[1] = ((char *)&_tmp)[2]; \
370 ((char *)a)[2] = ((char *)&_tmp)[1]; \
371 ((char *)a)[3] = ((char *)&_tmp)[0]; \
373 #define P_32_COPY(a, b) { \
374 ((char *)&(b))[0] = ((char *)&(a))[3]; \
375 ((char *)&(b))[1] = ((char *)&(a))[2]; \
376 ((char *)&(b))[2] = ((char *)&(a))[1]; \
377 ((char *)&(b))[3] = ((char *)&(a))[0]; \
381 * Little endian <==> big endian 16-bit swap macros.
382 * M_16_SWAP swap a memory location
383 * P_16_SWAP swap a referenced memory location
384 * P_16_COPY swap from one location to another
386 #define M_16_SWAP(a) { \
387 uint16 _tmp = a; \
388 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
389 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
391 #define P_16_SWAP(a) { \
392 uint16 _tmp = *(uint16 *)a; \
393 ((char *)a)[0] = ((char *)&_tmp)[1]; \
394 ((char *)a)[1] = ((char *)&_tmp)[0]; \
396 #define P_16_COPY(a, b) { \
397 ((char *)&(b))[0] = ((char *)&(a))[1]; \
398 ((char *)&(b))[1] = ((char *)&(a))[0]; \
400 #endif
402 PR_BEGIN_EXTERN_C
403 #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
404 extern DB *
405 #else
406 PR_EXTERN(DB *)
407 #endif
408 dbopen (const char *, int, int, DBTYPE, const void *);
410 /* set or unset a global lock flag to disable the
411 * opening of any DBM file
413 void dbSetOrClearDBLock(DBLockFlagEnum type);
415 #ifdef __DBINTERFACE_PRIVATE
416 DB *__bt_open (const char *, int, int, const BTREEINFO *, int);
417 DB *__hash_open (const char *, int, int, const HASHINFO *, int);
418 DB *__rec_open (const char *, int, int, const RECNOINFO *, int);
419 void __dbpanic (DB *dbp);
420 #endif
422 PR_END_EXTERN_C
424 #endif /* !_DB_H_ */