17c478bd9Sstevel@tonic-gate /* 2159d09a2SMark Phalan * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate #ifndef _KRB5_DB2_MISC_H 77c478bd9Sstevel@tonic-gate #define _KRB5_DB2_MISC_H 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate 107c478bd9Sstevel@tonic-gate #ifdef __cplusplus 117c478bd9Sstevel@tonic-gate extern "C" { 127c478bd9Sstevel@tonic-gate #endif 137c478bd9Sstevel@tonic-gate 147c478bd9Sstevel@tonic-gate /* 157c478bd9Sstevel@tonic-gate * Copyright (c) 1991, 1993 167c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 177c478bd9Sstevel@tonic-gate * 187c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 197c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 207c478bd9Sstevel@tonic-gate * are met: 217c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 227c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 237c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 247c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 257c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 267c478bd9Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 277c478bd9Sstevel@tonic-gate * must display the following acknowledgement: 287c478bd9Sstevel@tonic-gate * This product includes software developed by the University of 297c478bd9Sstevel@tonic-gate * California, Berkeley and its contributors. 307c478bd9Sstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors 317c478bd9Sstevel@tonic-gate * may be used to endorse or promote products derived from this software 327c478bd9Sstevel@tonic-gate * without specific prior written permission. 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 357c478bd9Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 367c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 377c478bd9Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 387c478bd9Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 397c478bd9Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 407c478bd9Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 417c478bd9Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 427c478bd9Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 437c478bd9Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 447c478bd9Sstevel@tonic-gate * SUCH DAMAGE. 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * @(#)compat.h 8.13 (Berkeley) 2/21/94 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #ifndef _DB_INT_H_ 507c478bd9Sstevel@tonic-gate #define _DB_INT_H_ 517c478bd9Sstevel@tonic-gate 52159d09a2SMark Phalan #include "db.h" 537c478bd9Sstevel@tonic-gate 5456a424ccSmp /* deal with autoconf-based stuff */ 557c478bd9Sstevel@tonic-gate 5656a424ccSmp #define DB_LITTLE_ENDIAN 1234 5756a424ccSmp #define DB_BIG_ENDIAN 4321 5856a424ccSmp 5956a424ccSmp #include <stdlib.h> 6056a424ccSmp #ifdef HAVE_ENDIAN_H 6156a424ccSmp # include <endian.h> 6256a424ccSmp #endif 6356a424ccSmp #ifdef HAVE_MACHINE_ENDIAN_H 6456a424ccSmp # include <machine/endian.h> 6556a424ccSmp #endif 6656a424ccSmp #ifdef HAVE_SYS_PARAM_H 6756a424ccSmp # include <sys/param.h> 687c478bd9Sstevel@tonic-gate #endif 697c478bd9Sstevel@tonic-gate 7056a424ccSmp /* SUNW14resync: 7156a424ccSmp The following code is disabled as it correctly determines the 7256a424ccSmp endianness of the system. This would break backward compatability 7356a424ccSmp for x86 as prior to this resync all architectures are treated 7456a424ccSmp similarily - as big endian. See definition of "WORDS_BIGENDIAN" in 7556a424ccSmp db-config.h. 7656a424ccSmp */ 77*55fea89dSDan Cross #if 0 7856a424ccSmp /* Handle both BIG and LITTLE defined and BYTE_ORDER matches one, or 7956a424ccSmp just one defined; both with and without leading underscores. 8056a424ccSmp 8156a424ccSmp Ignore "PDP endian" machines, this code doesn't support them 8256a424ccSmp anyways. */ 8356a424ccSmp #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER) 8456a424ccSmp # ifdef __LITTLE_ENDIAN__ 8556a424ccSmp # define LITTLE_ENDIAN __LITTLE_ENDIAN__ 8656a424ccSmp # endif 8756a424ccSmp # ifdef __BIG_ENDIAN__ 8856a424ccSmp # define BIG_ENDIAN __BIG_ENDIAN__ 8956a424ccSmp # endif 9056a424ccSmp #endif 9156a424ccSmp #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER) 9256a424ccSmp # ifdef _LITTLE_ENDIAN 9356a424ccSmp # define LITTLE_ENDIAN _LITTLE_ENDIAN 9456a424ccSmp # endif 9556a424ccSmp # ifdef _BIG_ENDIAN 9656a424ccSmp # define BIG_ENDIAN _BIG_ENDIAN 9756a424ccSmp # endif 9856a424ccSmp # ifdef _BYTE_ORDER 9956a424ccSmp # define BYTE_ORDER _BYTE_ORDER 10056a424ccSmp # endif 10156a424ccSmp #endif 10256a424ccSmp #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && !defined(BYTE_ORDER) 10356a424ccSmp # ifdef __LITTLE_ENDIAN 10456a424ccSmp # define LITTLE_ENDIAN __LITTLE_ENDIAN 10556a424ccSmp # endif 10656a424ccSmp # ifdef __BIG_ENDIAN 10756a424ccSmp # define BIG_ENDIAN __BIG_ENDIAN 10856a424ccSmp # endif 10956a424ccSmp # ifdef __BYTE_ORDER 11056a424ccSmp # define BYTE_ORDER __BYTE_ORDER 11156a424ccSmp # endif 11256a424ccSmp #endif 11356a424ccSmp 11456a424ccSmp #if defined(_MIPSEL) && !defined(LITTLE_ENDIAN) 11556a424ccSmp # define LITTLE_ENDIAN 11656a424ccSmp #endif 11756a424ccSmp #if defined(_MIPSEB) && !defined(BIG_ENDIAN) 11856a424ccSmp # define BIG_ENDIAN 11956a424ccSmp #endif 12056a424ccSmp 12156a424ccSmp #if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) && defined(BYTE_ORDER) 12256a424ccSmp # if LITTLE_ENDIAN == BYTE_ORDER 12356a424ccSmp # define DB_BYTE_ORDER DB_LITTLE_ENDIAN 12456a424ccSmp # elif BIG_ENDIAN == BYTE_ORDER 12556a424ccSmp # define DB_BYTE_ORDER DB_BIG_ENDIAN 12656a424ccSmp # else 12756a424ccSmp # error "LITTLE_ENDIAN and BIG_ENDIAN defined, but can't determine byte order" 12856a424ccSmp # endif 12956a424ccSmp #elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) 13056a424ccSmp # define DB_BYTE_ORDER DB_LITTLE_ENDIAN 13156a424ccSmp #elif defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) 13256a424ccSmp # define DB_BYTE_ORDER DB_BIG_ENDIAN 13356a424ccSmp #else 13456a424ccSmp # error "can't determine byte order from included system headers" 1357c478bd9Sstevel@tonic-gate #endif 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate #endif 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate #ifdef WORDS_BIGENDIAN 1417c478bd9Sstevel@tonic-gate #define DB_BYTE_ORDER DB_BIG_ENDIAN 1427c478bd9Sstevel@tonic-gate #else 1437c478bd9Sstevel@tonic-gate #define DB_BYTE_ORDER DB_LITTLE_ENDIAN 1447c478bd9Sstevel@tonic-gate #endif 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* end autoconf-based stuff */ 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* include necessary system header files */ 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate #ifdef HAVE_UNISTD_H 1517c478bd9Sstevel@tonic-gate #include <unistd.h> 1527c478bd9Sstevel@tonic-gate #endif 1537c478bd9Sstevel@tonic-gate #include <limits.h> 1547c478bd9Sstevel@tonic-gate #include <fcntl.h> 1557c478bd9Sstevel@tonic-gate #include <stdio.h> 1567c478bd9Sstevel@tonic-gate #include <errno.h> 15756a424ccSmp #ifdef HAVE_STDINT_H 15856a424ccSmp #include <stdint.h> 15956a424ccSmp #endif 16056a424ccSmp #ifdef HAVE_INTTYPES_H 16156a424ccSmp /* Tru64 5.1: int8_t is defined here, and stdint.h doesn't exist. */ 16256a424ccSmp #include <inttypes.h> 16356a424ccSmp #endif 1647c478bd9Sstevel@tonic-gate #include <sys/types.h> 1657c478bd9Sstevel@tonic-gate #include <sys/stat.h> 1667c478bd9Sstevel@tonic-gate #include <sys/param.h> 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* types and constants used for database structure */ 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ 1717c478bd9Sstevel@tonic-gate typedef u_int32_t db_pgno_t; 1727c478bd9Sstevel@tonic-gate #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ 1737c478bd9Sstevel@tonic-gate typedef u_int16_t indx_t; 1747c478bd9Sstevel@tonic-gate #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ 1757c478bd9Sstevel@tonic-gate typedef u_int32_t recno_t; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * Little endian <==> big endian 32-bit swap macros. 1797c478bd9Sstevel@tonic-gate * M_32_SWAP swap a memory location 1807c478bd9Sstevel@tonic-gate * P_32_SWAP swap a referenced memory location 1817c478bd9Sstevel@tonic-gate * P_32_COPY swap from one location to another 1827c478bd9Sstevel@tonic-gate */ 1837c478bd9Sstevel@tonic-gate #define M_32_SWAP(a) { \ 1847c478bd9Sstevel@tonic-gate u_int32_t _tmp = a; \ 1857c478bd9Sstevel@tonic-gate ((char *)&a)[0] = ((char *)&_tmp)[3]; \ 1867c478bd9Sstevel@tonic-gate ((char *)&a)[1] = ((char *)&_tmp)[2]; \ 1877c478bd9Sstevel@tonic-gate ((char *)&a)[2] = ((char *)&_tmp)[1]; \ 1887c478bd9Sstevel@tonic-gate ((char *)&a)[3] = ((char *)&_tmp)[0]; \ 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate #define P_32_SWAP(a) { \ 1917c478bd9Sstevel@tonic-gate u_int32_t _tmp = *(u_int32_t *)a; \ 1927c478bd9Sstevel@tonic-gate ((char *)a)[0] = ((char *)&_tmp)[3]; \ 1937c478bd9Sstevel@tonic-gate ((char *)a)[1] = ((char *)&_tmp)[2]; \ 1947c478bd9Sstevel@tonic-gate ((char *)a)[2] = ((char *)&_tmp)[1]; \ 1957c478bd9Sstevel@tonic-gate ((char *)a)[3] = ((char *)&_tmp)[0]; \ 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate #define P_32_COPY(a, b) { \ 1987c478bd9Sstevel@tonic-gate ((char *)&(b))[0] = ((char *)&(a))[3]; \ 1997c478bd9Sstevel@tonic-gate ((char *)&(b))[1] = ((char *)&(a))[2]; \ 2007c478bd9Sstevel@tonic-gate ((char *)&(b))[2] = ((char *)&(a))[1]; \ 2017c478bd9Sstevel@tonic-gate ((char *)&(b))[3] = ((char *)&(a))[0]; \ 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* 2057c478bd9Sstevel@tonic-gate * Little endian <==> big endian 16-bit swap macros. 2067c478bd9Sstevel@tonic-gate * M_16_SWAP swap a memory location 2077c478bd9Sstevel@tonic-gate * P_16_SWAP swap a referenced memory location 2087c478bd9Sstevel@tonic-gate * P_16_COPY swap from one location to another 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate #define M_16_SWAP(a) { \ 2117c478bd9Sstevel@tonic-gate u_int16_t _tmp = a; \ 2127c478bd9Sstevel@tonic-gate ((char *)&a)[0] = ((char *)&_tmp)[1]; \ 2137c478bd9Sstevel@tonic-gate ((char *)&a)[1] = ((char *)&_tmp)[0]; \ 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate #define P_16_SWAP(a) { \ 2167c478bd9Sstevel@tonic-gate u_int16_t _tmp = *(u_int16_t *)a; \ 2177c478bd9Sstevel@tonic-gate ((char *)a)[0] = ((char *)&_tmp)[1]; \ 2187c478bd9Sstevel@tonic-gate ((char *)a)[1] = ((char *)&_tmp)[0]; \ 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate #define P_16_COPY(a, b) { \ 2217c478bd9Sstevel@tonic-gate ((char *)&(b))[0] = ((char *)&(a))[1]; \ 2227c478bd9Sstevel@tonic-gate ((char *)&(b))[1] = ((char *)&(a))[0]; \ 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate /* open functions for each database type, used in dbopen() */ 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate #define __bt_open __kdb2_bt_open 2287c478bd9Sstevel@tonic-gate #define __hash_open __kdb2_hash_open 2297c478bd9Sstevel@tonic-gate #define __rec_open __kdb2_rec_open 2307c478bd9Sstevel@tonic-gate #define __dbpanic __kdb2_dbpanic 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int)); 2337c478bd9Sstevel@tonic-gate DB *__hash_open __P((const char *, int, int, const HASHINFO *, int)); 2347c478bd9Sstevel@tonic-gate DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int)); 2357c478bd9Sstevel@tonic-gate void __dbpanic __P((DB *dbp)); 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* 2387c478bd9Sstevel@tonic-gate * There is no portable way to figure out the maximum value of a file 2397c478bd9Sstevel@tonic-gate * offset, so we put it here. 2407c478bd9Sstevel@tonic-gate */ 2417c478bd9Sstevel@tonic-gate #ifdef OFF_T_MAX 2427c478bd9Sstevel@tonic-gate #define DB_OFF_T_MAX OFF_T_MAX 2437c478bd9Sstevel@tonic-gate #else 2447c478bd9Sstevel@tonic-gate #define DB_OFF_T_MAX LONG_MAX 2457c478bd9Sstevel@tonic-gate #endif 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate #ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */ 2487c478bd9Sstevel@tonic-gate #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 2497c478bd9Sstevel@tonic-gate #endif 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * If you can't provide lock values in the open(2) call. Note, this 2537c478bd9Sstevel@tonic-gate * allows races to happen. 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate #ifndef O_EXLOCK /* 4.4BSD extension. */ 2567c478bd9Sstevel@tonic-gate #define O_EXLOCK 0 2577c478bd9Sstevel@tonic-gate #endif 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate #ifndef O_SHLOCK /* 4.4BSD extension. */ 2607c478bd9Sstevel@tonic-gate #define O_SHLOCK 0 2617c478bd9Sstevel@tonic-gate #endif 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate #ifndef EFTYPE 2647c478bd9Sstevel@tonic-gate #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */ 2657c478bd9Sstevel@tonic-gate #endif 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate #ifndef STDERR_FILENO 2687c478bd9Sstevel@tonic-gate #define STDIN_FILENO 0 /* ANSI C #defines */ 2697c478bd9Sstevel@tonic-gate #define STDOUT_FILENO 1 2707c478bd9Sstevel@tonic-gate #define STDERR_FILENO 2 2717c478bd9Sstevel@tonic-gate #endif 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate #ifndef SEEK_END 2747c478bd9Sstevel@tonic-gate #define SEEK_SET 0 /* POSIX 1003.1 seek values */ 2757c478bd9Sstevel@tonic-gate #define SEEK_CUR 1 2767c478bd9Sstevel@tonic-gate #define SEEK_END 2 2777c478bd9Sstevel@tonic-gate #endif 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate #ifndef NULL /* ANSI C #defines NULL everywhere. */ 2807c478bd9Sstevel@tonic-gate #define NULL 0 2817c478bd9Sstevel@tonic-gate #endif 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate #ifndef MAX /* Usually found in <sys/param.h>. */ 2847c478bd9Sstevel@tonic-gate #define MAX(_a,_b) ((_a)<(_b)?(_b):(_a)) 2857c478bd9Sstevel@tonic-gate #endif 2867c478bd9Sstevel@tonic-gate #ifndef MIN /* Usually found in <sys/param.h>. */ 2877c478bd9Sstevel@tonic-gate #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b)) 2887c478bd9Sstevel@tonic-gate #endif 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate #ifndef S_ISDIR /* POSIX 1003.1 file type tests. */ 2917c478bd9Sstevel@tonic-gate #define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */ 2927c478bd9Sstevel@tonic-gate #define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */ 2937c478bd9Sstevel@tonic-gate #define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */ 2947c478bd9Sstevel@tonic-gate #define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */ 2957c478bd9Sstevel@tonic-gate #define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */ 2967c478bd9Sstevel@tonic-gate #endif 2977c478bd9Sstevel@tonic-gate #ifndef S_ISLNK /* BSD POSIX 1003.1 extensions */ 2987c478bd9Sstevel@tonic-gate #define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */ 2997c478bd9Sstevel@tonic-gate #define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */ 3007c478bd9Sstevel@tonic-gate #endif 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate #ifndef O_BINARY 3037c478bd9Sstevel@tonic-gate #define O_BINARY 0 /* Needed for Win32 compiles */ 3047c478bd9Sstevel@tonic-gate #endif 3057c478bd9Sstevel@tonic-gate #endif /* _DB_INT_H_ */ 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate #ifdef __cplusplus 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate #endif 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate #endif /* !_KRB5_DB2_MISC_H */ 312