Path: blob/main/crypto/krb5/src/plugins/kdb/db2/libdb2/include/db-int.h
34927 views
/*-1* Copyright (c) 1991, 1993, 20072* The Regents of the University of California. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. All advertising materials mentioning features or use of this software13* must display the following acknowledgement:14* This product includes software developed by the University of15* California, Berkeley and its contributors.16* 4. Neither the name of the University nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*32* @(#)compat.h 8.13 (Berkeley) 2/21/9433*/3435#ifndef _DB_INT_H_36#define _DB_INT_H_3738#include "config.h"39#include "db.h"4041/* deal with autoconf-based stuff */4243#define DB_LITTLE_ENDIAN 123444#define DB_BIG_ENDIAN 43214546#include <stdlib.h>47#ifdef HAVE_ENDIAN_H48# include <endian.h>49#endif50#ifdef HAVE_MACHINE_ENDIAN_H51# include <machine/endian.h>52#endif53#ifdef HAVE_SYS_PARAM_H54# include <sys/param.h>55#endif56/* Handle both BIG and LITTLE defined and BYTE_ORDER matches one, or57just one defined; both with and without leading underscores.5859Ignore "PDP endian" machines, this code doesn't support them60anyways. */61#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER)62# ifdef __LITTLE_ENDIAN__63# define LITTLE_ENDIAN __LITTLE_ENDIAN__64# endif65# ifdef __BIG_ENDIAN__66# define BIG_ENDIAN __BIG_ENDIAN__67# endif68#endif69#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER)70# ifdef _LITTLE_ENDIAN71# define LITTLE_ENDIAN _LITTLE_ENDIAN72# endif73# ifdef _BIG_ENDIAN74# define BIG_ENDIAN _BIG_ENDIAN75# endif76# ifdef _BYTE_ORDER77# define BYTE_ORDER _BYTE_ORDER78# endif79#endif80#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER)81# ifdef __LITTLE_ENDIAN82# define LITTLE_ENDIAN __LITTLE_ENDIAN83# endif84# ifdef __BIG_ENDIAN85# define BIG_ENDIAN __BIG_ENDIAN86# endif87# ifdef __BYTE_ORDER88# define BYTE_ORDER __BYTE_ORDER89# endif90#endif9192#if defined(_MIPSEL) && !defined(LITTLE_ENDIAN)93# define LITTLE_ENDIAN94#endif95#if defined(_MIPSEB) && !defined(BIG_ENDIAN)96# define BIG_ENDIAN97#endif9899#if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) && defined(BYTE_ORDER)100# if LITTLE_ENDIAN == BYTE_ORDER101# define DB_BYTE_ORDER DB_LITTLE_ENDIAN102# elif BIG_ENDIAN == BYTE_ORDER103# define DB_BYTE_ORDER DB_BIG_ENDIAN104# else105# error "LITTLE_ENDIAN and BIG_ENDIAN defined, but can't determine byte order"106# endif107#elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)108# define DB_BYTE_ORDER DB_LITTLE_ENDIAN109#elif defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)110# define DB_BYTE_ORDER DB_BIG_ENDIAN111#else112# error "can't determine byte order from included system headers"113#endif114115#if 0116#ifdef WORDS_BIGENDIAN117#define DB_BYTE_ORDER DB_BIG_ENDIAN118#else119#define DB_BYTE_ORDER DB_LITTLE_ENDIAN120#endif121#endif122123/* end autoconf-based stuff */124125/* include necessary system header files */126127#ifdef HAVE_UNISTD_H128#include <unistd.h>129#endif130#include <limits.h>131#include <fcntl.h>132#include <stdio.h>133#include <errno.h>134#include <stdint.h>135#include <sys/types.h>136#include <sys/stat.h>137#include <sys/param.h>138139/* types and constants used for database structure */140141#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */142typedef u_int32_t db_pgno_t;143#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */144typedef u_int16_t indx_t;145#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */146typedef u_int32_t recno_t;147148/*149* Little endian <==> big endian 32-bit swap macros.150* M_32_SWAP swap a memory location151* P_32_SWAP swap a referenced memory location152* P_32_COPY swap from one location to another153*/154#define M_32_SWAP(a) { \155u_int32_t _tmp = a; \156((char *)&a)[0] = ((char *)&_tmp)[3]; \157((char *)&a)[1] = ((char *)&_tmp)[2]; \158((char *)&a)[2] = ((char *)&_tmp)[1]; \159((char *)&a)[3] = ((char *)&_tmp)[0]; \160}161#define P_32_SWAP(a) { \162char _tmp[4]; \163_tmp[0] = ((char *)a)[0]; \164_tmp[1] = ((char *)a)[1]; \165_tmp[2] = ((char *)a)[2]; \166_tmp[3] = ((char *)a)[3]; \167((char *)a)[0] = _tmp[3]; \168((char *)a)[1] = _tmp[2]; \169((char *)a)[2] = _tmp[1]; \170((char *)a)[3] = _tmp[0]; \171}172#define P_32_COPY(a, b) { \173((char *)&(b))[0] = ((char *)&(a))[3]; \174((char *)&(b))[1] = ((char *)&(a))[2]; \175((char *)&(b))[2] = ((char *)&(a))[1]; \176((char *)&(b))[3] = ((char *)&(a))[0]; \177}178179/*180* Little endian <==> big endian 16-bit swap macros.181* M_16_SWAP swap a memory location182* P_16_SWAP swap a referenced memory location183* P_16_COPY swap from one location to another184*/185#define M_16_SWAP(a) { \186u_int16_t _tmp = a; \187((char *)&a)[0] = ((char *)&_tmp)[1]; \188((char *)&a)[1] = ((char *)&_tmp)[0]; \189}190#define P_16_SWAP(a) { \191char _tmp[2]; \192_tmp[0] = ((char *)a)[0]; \193_tmp[1] = ((char *)a)[1]; \194((char *)a)[0] = _tmp[1]; \195((char *)a)[1] = _tmp[0]; \196}197#define P_16_COPY(a, b) { \198((char *)&(b))[0] = ((char *)&(a))[1]; \199((char *)&(b))[1] = ((char *)&(a))[0]; \200}201202/* open functions for each database type, used in dbopen() */203204#define __bt_open __kdb2_bt_open205#define __hash_open __kdb2_hash_open206#define __rec_open __kdb2_rec_open207#define __dbpanic __kdb2_dbpanic208209DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));210DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));211DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));212void __dbpanic __P((DB *dbp));213214/*215* There is no portable way to figure out the maximum value of a file216* offset, so we put it here.217*/218#ifdef OFF_T_MAX219#define DB_OFF_T_MAX OFF_T_MAX220#else221#define DB_OFF_T_MAX LONG_MAX222#endif223224#ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */225#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)226#endif227228/*229* If you can't provide lock values in the open(2) call. Note, this230* allows races to happen.231*/232#ifndef O_EXLOCK /* 4.4BSD extension. */233#define O_EXLOCK 0234#endif235236#ifndef O_SHLOCK /* 4.4BSD extension. */237#define O_SHLOCK 0238#endif239240#ifndef EFTYPE241#define EFTYPE EINVAL /* POSIX 1003.1 format errno. */242#endif243244#ifndef STDERR_FILENO245#define STDIN_FILENO 0 /* ANSI C #defines */246#define STDOUT_FILENO 1247#define STDERR_FILENO 2248#endif249250#ifndef SEEK_END251#define SEEK_SET 0 /* POSIX 1003.1 seek values */252#define SEEK_CUR 1253#define SEEK_END 2254#endif255256#ifndef NULL /* ANSI C #defines NULL everywhere. */257#define NULL 0258#endif259260#ifndef MAX /* Usually found in <sys/param.h>. */261#define MAX(_a,_b) ((_a)<(_b)?(_b):(_a))262#endif263#ifndef MIN /* Usually found in <sys/param.h>. */264#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))265#endif266267#ifndef S_ISDIR /* POSIX 1003.1 file type tests. */268#define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */269#define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */270#define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */271#define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */272#define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */273#endif274#ifndef S_ISLNK /* BSD POSIX 1003.1 extensions */275#define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */276#define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */277#endif278279#ifndef O_BINARY280#define O_BINARY 0 /* Needed for Win32 compiles */281#endif282#endif /* _DB_INT_H_ */283284285