1N/A/*-
1N/A * See the file LICENSE for redistribution information.
1N/A *
1N/A * Copyright (c) 1996, 1997, 1998
1N/A * Sleepycat Software. All rights reserved.
1N/A */
1N/A/*
1N/A * Copyright (c) 1990, 1993, 1994
1N/A * The Regents of the University of California. All rights reserved.
1N/A *
1N/A * Redistribution and use in source and binary forms, with or without
1N/A * modification, are permitted provided that the following conditions
1N/A * are met:
1N/A * 1. Redistributions of source code must retain the above copyright
1N/A * notice, this list of conditions and the following disclaimer.
1N/A * 2. Redistributions in binary form must reproduce the above copyright
1N/A * notice, this list of conditions and the following disclaimer in the
1N/A * documentation and/or other materials provided with the distribution.
1N/A * 3. All advertising materials mentioning features or use of this software
1N/A * must display the following acknowledgement:
1N/A * This product includes software developed by the University of
1N/A * California, Berkeley and its contributors.
1N/A * 4. Neither the name of the University nor the names of its contributors
1N/A * may be used to endorse or promote products derived from this software
1N/A * without specific prior written permission.
1N/A *
1N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1N/A * SUCH DAMAGE.
1N/A *
1N/A * @(#)db_swap.h 10.5 (Sleepycat) 4/10/98
1N/A */
1N/A
1N/A#ifndef _DB_SWAP_H_
1N/A#define _DB_SWAP_H_
1N/A
1N/A/*
1N/A * Little endian <==> big endian 32-bit swap macros.
1N/A * M_32_SWAP swap a memory location
1N/A * P_32_COPY copy potentially unaligned 4 byte quantities
1N/A * P_32_SWAP swap a referenced memory location
1N/A */
1N/A#define M_32_SWAP(a) { \
1N/A u_int32_t _tmp; \
1N/A _tmp = a; \
1N/A ((u_int8_t *)&a)[0] = ((u_int8_t *)&_tmp)[3]; \
1N/A ((u_int8_t *)&a)[1] = ((u_int8_t *)&_tmp)[2]; \
1N/A ((u_int8_t *)&a)[2] = ((u_int8_t *)&_tmp)[1]; \
1N/A ((u_int8_t *)&a)[3] = ((u_int8_t *)&_tmp)[0]; \
1N/A}
1N/A#define P_32_COPY(a, b) { \
1N/A ((u_int8_t *)b)[0] = ((u_int8_t *)a)[0]; \
1N/A ((u_int8_t *)b)[1] = ((u_int8_t *)a)[1]; \
1N/A ((u_int8_t *)b)[2] = ((u_int8_t *)a)[2]; \
1N/A ((u_int8_t *)b)[3] = ((u_int8_t *)a)[3]; \
1N/A}
1N/A#define P_32_SWAP(a) { \
1N/A u_int32_t _tmp; \
1N/A P_32_COPY(a, &_tmp); \
1N/A ((u_int8_t *)a)[0] = ((u_int8_t *)&_tmp)[3]; \
1N/A ((u_int8_t *)a)[1] = ((u_int8_t *)&_tmp)[2]; \
1N/A ((u_int8_t *)a)[2] = ((u_int8_t *)&_tmp)[1]; \
1N/A ((u_int8_t *)a)[3] = ((u_int8_t *)&_tmp)[0]; \
1N/A}
1N/A
1N/A/*
1N/A * Little endian <==> big endian 16-bit swap macros.
1N/A * M_16_SWAP swap a memory location
1N/A * P_16_COPY copy potentially unaligned 2 byte quantities
1N/A * P_16_SWAP swap a referenced memory location
1N/A */
1N/A#define M_16_SWAP(a) { \
1N/A u_int16_t _tmp; \
1N/A _tmp = (u_int16_t)a; \
1N/A ((u_int8_t *)&a)[0] = ((u_int8_t *)&_tmp)[1]; \
1N/A ((u_int8_t *)&a)[1] = ((u_int8_t *)&_tmp)[0]; \
1N/A}
1N/A#define P_16_COPY(a, b) { \
1N/A ((u_int8_t *)b)[0] = ((u_int8_t *)a)[0]; \
1N/A ((u_int8_t *)b)[1] = ((u_int8_t *)a)[1]; \
1N/A}
1N/A#define P_16_SWAP(a) { \
1N/A u_int16_t _tmp; \
1N/A P_16_COPY(a, &_tmp); \
1N/A ((u_int8_t *)a)[0] = ((u_int8_t *)&_tmp)[1]; \
1N/A ((u_int8_t *)a)[1] = ((u_int8_t *)&_tmp)[0]; \
1N/A}
1N/A
1N/A#define SWAP32(p) { \
1N/A P_32_SWAP(p); \
1N/A (p) += sizeof(u_int32_t); \
1N/A}
1N/A#define SWAP16(p) { \
1N/A P_16_SWAP(p); \
1N/A (p) += sizeof(u_int16_t); \
1N/A}
1N/A#endif /* !_DB_SWAP_H_ */