14960Swillf /* 2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 34960Swillf * Use is subject to license terms. 44960Swillf */ 54960Swillf 64960Swillf #ifndef _KRB5_DB2_MISC_H 74960Swillf #define _KRB5_DB2_MISC_H 84960Swillf 94960Swillf 104960Swillf #ifdef __cplusplus 114960Swillf extern "C" { 124960Swillf #endif 134960Swillf 144960Swillf /* 154960Swillf * Copyright (c) 1991, 1993 164960Swillf * The Regents of the University of California. All rights reserved. 174960Swillf * 184960Swillf * Redistribution and use in source and binary forms, with or without 194960Swillf * modification, are permitted provided that the following conditions 204960Swillf * are met: 214960Swillf * 1. Redistributions of source code must retain the above copyright 224960Swillf * notice, this list of conditions and the following disclaimer. 234960Swillf * 2. Redistributions in binary form must reproduce the above copyright 244960Swillf * notice, this list of conditions and the following disclaimer in the 254960Swillf * documentation and/or other materials provided with the distribution. 264960Swillf * 3. All advertising materials mentioning features or use of this software 274960Swillf * must display the following acknowledgement: 284960Swillf * This product includes software developed by the University of 294960Swillf * California, Berkeley and its contributors. 304960Swillf * 4. Neither the name of the University nor the names of its contributors 314960Swillf * may be used to endorse or promote products derived from this software 324960Swillf * without specific prior written permission. 334960Swillf * 344960Swillf * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 354960Swillf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 364960Swillf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 374960Swillf * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 384960Swillf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 394960Swillf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 404960Swillf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 414960Swillf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 424960Swillf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 434960Swillf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 444960Swillf * SUCH DAMAGE. 454960Swillf * 464960Swillf * @(#)compat.h 8.13 (Berkeley) 2/21/94 474960Swillf */ 484960Swillf 494960Swillf #ifndef _DB_INT_H_ 504960Swillf #define _DB_INT_H_ 514960Swillf 52*7934SMark.Phalan@Sun.COM #include "db.h" 534960Swillf 544960Swillf /* deal with autoconf-based stuff */ 554960Swillf 564960Swillf #define DB_LITTLE_ENDIAN 1234 574960Swillf #define DB_BIG_ENDIAN 4321 584960Swillf 594960Swillf #include <stdlib.h> 604960Swillf #ifdef HAVE_ENDIAN_H 614960Swillf # include <endian.h> 624960Swillf #endif 634960Swillf #ifdef HAVE_MACHINE_ENDIAN_H 644960Swillf # include <machine/endian.h> 654960Swillf #endif 664960Swillf #ifdef HAVE_SYS_PARAM_H 674960Swillf # include <sys/param.h> 684960Swillf #endif 694960Swillf 704960Swillf /* SUNW14resync: 714960Swillf The following code is disabled as it correctly determines the 724960Swillf endianness of the system. This would break backward compatability 734960Swillf for x86 as prior to this resync all architectures are treated 744960Swillf similarily - as big endian. See definition of "WORDS_BIGENDIAN" in 754960Swillf db-config.h. 764960Swillf */ 774960Swillf #if 0 784960Swillf /* Handle both BIG and LITTLE defined and BYTE_ORDER matches one, or 794960Swillf just one defined; both with and without leading underscores. 804960Swillf 814960Swillf Ignore "PDP endian" machines, this code doesn't support them 824960Swillf anyways. */ 834960Swillf #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER) 844960Swillf # ifdef __LITTLE_ENDIAN__ 854960Swillf # define LITTLE_ENDIAN __LITTLE_ENDIAN__ 864960Swillf # endif 874960Swillf # ifdef __BIG_ENDIAN__ 884960Swillf # define BIG_ENDIAN __BIG_ENDIAN__ 894960Swillf # endif 904960Swillf #endif 914960Swillf #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER) 924960Swillf # ifdef _LITTLE_ENDIAN 934960Swillf # define LITTLE_ENDIAN _LITTLE_ENDIAN 944960Swillf # endif 954960Swillf # ifdef _BIG_ENDIAN 964960Swillf # define BIG_ENDIAN _BIG_ENDIAN 974960Swillf # endif 984960Swillf # ifdef _BYTE_ORDER 994960Swillf # define BYTE_ORDER _BYTE_ORDER 1004960Swillf # endif 1014960Swillf #endif 1024960Swillf #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER) 1034960Swillf # ifdef __LITTLE_ENDIAN 1044960Swillf # define LITTLE_ENDIAN __LITTLE_ENDIAN 1054960Swillf # endif 1064960Swillf # ifdef __BIG_ENDIAN 1074960Swillf # define BIG_ENDIAN __BIG_ENDIAN 1084960Swillf # endif 1094960Swillf # ifdef __BYTE_ORDER 1104960Swillf # define BYTE_ORDER __BYTE_ORDER 1114960Swillf # endif 1124960Swillf #endif 1134960Swillf 1144960Swillf #if defined(_MIPSEL) && !defined(LITTLE_ENDIAN) 1154960Swillf # define LITTLE_ENDIAN 1164960Swillf #endif 1174960Swillf #if defined(_MIPSEB) && !defined(BIG_ENDIAN) 1184960Swillf # define BIG_ENDIAN 1194960Swillf #endif 1204960Swillf 1214960Swillf #if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) && defined(BYTE_ORDER) 1224960Swillf # if LITTLE_ENDIAN == BYTE_ORDER 1234960Swillf # define DB_BYTE_ORDER DB_LITTLE_ENDIAN 1244960Swillf # elif BIG_ENDIAN == BYTE_ORDER 1254960Swillf # define DB_BYTE_ORDER DB_BIG_ENDIAN 1264960Swillf # else 1274960Swillf # error "LITTLE_ENDIAN and BIG_ENDIAN defined, but can't determine byte order" 1284960Swillf # endif 1294960Swillf #elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) 1304960Swillf # define DB_BYTE_ORDER DB_LITTLE_ENDIAN 1314960Swillf #elif defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) 1324960Swillf # define DB_BYTE_ORDER DB_BIG_ENDIAN 1334960Swillf #else 1344960Swillf # error "can't determine byte order from included system headers" 1354960Swillf #endif 1364960Swillf 1374960Swillf #endif 1384960Swillf 1394960Swillf 1404960Swillf #ifdef WORDS_BIGENDIAN 1414960Swillf #define DB_BYTE_ORDER DB_BIG_ENDIAN 1424960Swillf #else 1434960Swillf #define DB_BYTE_ORDER DB_LITTLE_ENDIAN 1444960Swillf #endif 1454960Swillf 1464960Swillf /* end autoconf-based stuff */ 1474960Swillf 1484960Swillf /* include necessary system header files */ 1494960Swillf 1504960Swillf #ifdef HAVE_UNISTD_H 1514960Swillf #include <unistd.h> 1524960Swillf #endif 1534960Swillf #include <limits.h> 1544960Swillf #include <fcntl.h> 1554960Swillf #include <stdio.h> 1564960Swillf #include <errno.h> 1574960Swillf #ifdef HAVE_STDINT_H 1584960Swillf #include <stdint.h> 1594960Swillf #endif 1604960Swillf #ifdef HAVE_INTTYPES_H 1614960Swillf /* Tru64 5.1: int8_t is defined here, and stdint.h doesn't exist. */ 1624960Swillf #include <inttypes.h> 1634960Swillf #endif 1644960Swillf #include <sys/types.h> 1654960Swillf #include <sys/stat.h> 1664960Swillf #include <sys/param.h> 1674960Swillf 1684960Swillf /* types and constants used for database structure */ 1694960Swillf 1704960Swillf #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ 1714960Swillf typedef u_int32_t db_pgno_t; 1724960Swillf #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ 1734960Swillf typedef u_int16_t indx_t; 1744960Swillf #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ 1754960Swillf typedef u_int32_t recno_t; 1764960Swillf 1774960Swillf /* 1784960Swillf * Little endian <==> big endian 32-bit swap macros. 1794960Swillf * M_32_SWAP swap a memory location 1804960Swillf * P_32_SWAP swap a referenced memory location 1814960Swillf * P_32_COPY swap from one location to another 1824960Swillf */ 1834960Swillf #define M_32_SWAP(a) { \ 1844960Swillf u_int32_t _tmp = a; \ 1854960Swillf ((char *)&a)[0] = ((char *)&_tmp)[3]; \ 1864960Swillf ((char *)&a)[1] = ((char *)&_tmp)[2]; \ 1874960Swillf ((char *)&a)[2] = ((char *)&_tmp)[1]; \ 1884960Swillf ((char *)&a)[3] = ((char *)&_tmp)[0]; \ 1894960Swillf } 1904960Swillf #define P_32_SWAP(a) { \ 1914960Swillf u_int32_t _tmp = *(u_int32_t *)a; \ 1924960Swillf ((char *)a)[0] = ((char *)&_tmp)[3]; \ 1934960Swillf ((char *)a)[1] = ((char *)&_tmp)[2]; \ 1944960Swillf ((char *)a)[2] = ((char *)&_tmp)[1]; \ 1954960Swillf ((char *)a)[3] = ((char *)&_tmp)[0]; \ 1964960Swillf } 1974960Swillf #define P_32_COPY(a, b) { \ 1984960Swillf ((char *)&(b))[0] = ((char *)&(a))[3]; \ 1994960Swillf ((char *)&(b))[1] = ((char *)&(a))[2]; \ 2004960Swillf ((char *)&(b))[2] = ((char *)&(a))[1]; \ 2014960Swillf ((char *)&(b))[3] = ((char *)&(a))[0]; \ 2024960Swillf } 2034960Swillf 2044960Swillf /* 2054960Swillf * Little endian <==> big endian 16-bit swap macros. 2064960Swillf * M_16_SWAP swap a memory location 2074960Swillf * P_16_SWAP swap a referenced memory location 2084960Swillf * P_16_COPY swap from one location to another 2094960Swillf */ 2104960Swillf #define M_16_SWAP(a) { \ 2114960Swillf u_int16_t _tmp = a; \ 2124960Swillf ((char *)&a)[0] = ((char *)&_tmp)[1]; \ 2134960Swillf ((char *)&a)[1] = ((char *)&_tmp)[0]; \ 2144960Swillf } 2154960Swillf #define P_16_SWAP(a) { \ 2164960Swillf u_int16_t _tmp = *(u_int16_t *)a; \ 2174960Swillf ((char *)a)[0] = ((char *)&_tmp)[1]; \ 2184960Swillf ((char *)a)[1] = ((char *)&_tmp)[0]; \ 2194960Swillf } 2204960Swillf #define P_16_COPY(a, b) { \ 2214960Swillf ((char *)&(b))[0] = ((char *)&(a))[1]; \ 2224960Swillf ((char *)&(b))[1] = ((char *)&(a))[0]; \ 2234960Swillf } 2244960Swillf 2254960Swillf /* open functions for each database type, used in dbopen() */ 2264960Swillf 2274960Swillf #define __bt_open __kdb2_bt_open 2284960Swillf #define __hash_open __kdb2_hash_open 2294960Swillf #define __rec_open __kdb2_rec_open 2304960Swillf #define __dbpanic __kdb2_dbpanic 2314960Swillf 2324960Swillf DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int)); 2334960Swillf DB *__hash_open __P((const char *, int, int, const HASHINFO *, int)); 2344960Swillf DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int)); 2354960Swillf void __dbpanic __P((DB *dbp)); 2364960Swillf 2374960Swillf /* 2384960Swillf * There is no portable way to figure out the maximum value of a file 2394960Swillf * offset, so we put it here. 2404960Swillf */ 2414960Swillf #ifdef OFF_T_MAX 2424960Swillf #define DB_OFF_T_MAX OFF_T_MAX 2434960Swillf #else 2444960Swillf #define DB_OFF_T_MAX LONG_MAX 2454960Swillf #endif 2464960Swillf 2474960Swillf #ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */ 2484960Swillf #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 2494960Swillf #endif 2504960Swillf 2514960Swillf /* 2524960Swillf * If you can't provide lock values in the open(2) call. Note, this 2534960Swillf * allows races to happen. 2544960Swillf */ 2554960Swillf #ifndef O_EXLOCK /* 4.4BSD extension. */ 2564960Swillf #define O_EXLOCK 0 2574960Swillf #endif 2584960Swillf 2594960Swillf #ifndef O_SHLOCK /* 4.4BSD extension. */ 2604960Swillf #define O_SHLOCK 0 2614960Swillf #endif 2624960Swillf 2634960Swillf #ifndef EFTYPE 2644960Swillf #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */ 2654960Swillf #endif 2664960Swillf 2674960Swillf #ifndef STDERR_FILENO 2684960Swillf #define STDIN_FILENO 0 /* ANSI C #defines */ 2694960Swillf #define STDOUT_FILENO 1 2704960Swillf #define STDERR_FILENO 2 2714960Swillf #endif 2724960Swillf 2734960Swillf #ifndef SEEK_END 2744960Swillf #define SEEK_SET 0 /* POSIX 1003.1 seek values */ 2754960Swillf #define SEEK_CUR 1 2764960Swillf #define SEEK_END 2 2774960Swillf #endif 2784960Swillf 2794960Swillf #ifndef NULL /* ANSI C #defines NULL everywhere. */ 2804960Swillf #define NULL 0 2814960Swillf #endif 2824960Swillf 2834960Swillf #ifndef MAX /* Usually found in <sys/param.h>. */ 2844960Swillf #define MAX(_a,_b) ((_a)<(_b)?(_b):(_a)) 2854960Swillf #endif 2864960Swillf #ifndef MIN /* Usually found in <sys/param.h>. */ 2874960Swillf #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b)) 2884960Swillf #endif 2894960Swillf 2904960Swillf #ifndef S_ISDIR /* POSIX 1003.1 file type tests. */ 2914960Swillf #define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */ 2924960Swillf #define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */ 2934960Swillf #define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */ 2944960Swillf #define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */ 2954960Swillf #define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */ 2964960Swillf #endif 2974960Swillf #ifndef S_ISLNK /* BSD POSIX 1003.1 extensions */ 2984960Swillf #define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */ 2994960Swillf #define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */ 3004960Swillf #endif 3014960Swillf 3024960Swillf #ifndef O_BINARY 3034960Swillf #define O_BINARY 0 /* Needed for Win32 compiles */ 3044960Swillf #endif 3054960Swillf #endif /* _DB_INT_H_ */ 3064960Swillf 3074960Swillf #ifdef __cplusplus 3084960Swillf } 3094960Swillf #endif 3104960Swillf 3114960Swillf #endif /* !_KRB5_DB2_MISC_H */ 312