/usr/include/licq/byteorder.h is in licq-dev 1.6.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | /*
* Copyright (C) 2008-2010 Anders Olofsson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This header attempts to find endian for the local system and define byte
* swap functions.
* As far as possible it uses system headers as these should know best.
* System headers may also give us native byte swap functions.
*
* Known limitations:
* Middle endian (BYTE_ORDER == PDP_ENDIAN) systems are not handled
*
* The following will be set by this header:
* - Either IS_LITTLE_ENDIAN or IS_BIG_ENDIAN set depending on endian type
* - Byte swap functions defined as: BSWAP_16, BSWAP_32 and BSWAP_64
* - Conversion functions to/from big endian: BE_16, BE_32, BE_64
* - Conversion functions to/from little endian: LE_16, LE_32, LE_64
*/
#ifndef LICQ_BYTEORDER_H
#define LICQ_BYTEORDER_H
#include <stdint.h>
// GNU header for endian and byteswap
// (stdint.h gives us __GLIBC__ to check for)
# ifdef __GLIBC__
# include <endian.h>
# include <byteswap.h>
// GNU defines endian by setting __BYTE_ORDER to __BIG_ENDIAN or __LITTLE_ENDIAN
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define IS_LITTLE_ENDIAN
# endif
# if __BYTE_ORDER == __BIG_ENDIAN
# define IS_BIG_ENDIAN
# endif
// GNU defines bswap functions: bswap_16, bswap_32, bswap_64
# define BSWAP_16(x) bswap_16(x)
# define BSWAP_32(x) bswap_32(x)
# define BSWAP_64(x) bswap_64(x)
// Mac OS X has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC)
#elif defined(__APPLE__) && defined(__MACH__)
# ifdef __BIG_ENDIAN__
# define IS_BIG_ENDIAN
# endif
# ifdef __LITTLE_ENDIAN__
# define IS_LITTLE_ENDIAN
# endif
// BSD header for endian and byte swap
// Compiler gives us __*BSD__ variables to check for
#elif defined(__FreeBSD__) || defined(__NetBSD__)
# include <sys/endian.h>
// BSD defines endian by setting _BYTE_ORDER to _BIG_ENDIAN or _LITTLE_ENDIAN
# if _BYTE_ORDER == _LITTLE_ENDIAN
# define IS_LITTLE_ENDIAN
# endif
# if _BYTE_ORDER == _BIG_ENDIAN
# define IS_BIG_ENDIAN
# endif
// BSD defines bswap functions: bswap16, bswap32, bswap64
# define BSWAP_16(x) bswap16(x)
# define BSWAP_32(x) bswap32(x)
# define BSWAP_64(x) bswap64(x)
// BSD defines conversion functions: be16toh, be32toh, be64toh, le16toh, le32toh, le64toh
# define BE_16(x) be16toh(x)
# define BE_32(x) be32toh(x)
# define BE_64(x) be64toh(x)
# define LE_16(x) le16toh(x)
# define LE_32(x) le32toh(x)
# define LE_64(x) le64toh(x)
// OpenBSD differs from the other BSD systems
#elif defined(__OpenBSD__)
# include <machine/endian.h>
// BSD defines endian by setting _BYTE_ORDER to _BIG_ENDIAN or _LITTLE_ENDIAN
# if _BYTE_ORDER == _LITTLE_ENDIAN
# define IS_LITTLE_ENDIAN
# endif
# if _BYTE_ORDER == _BIG_ENDIAN
# define IS_BIG_ENDIAN
# endif
// OpenBSD defines bswap functions: swap16, swap32, swap64
# define BSWAP_16(x) swap16(x)
# define BSWAP_32(x) swap32(x)
# define BSWAP_64(x) swap64(x)
// OpenBSD defines conversion functions: betoh16, betoh32, betoh64, letoh16, letoh32, letoh64
# define BE_16(x) betoh16(x)
# define BE_32(x) betoh32(x)
# define BE_64(x) betoh64(x)
# define LE_16(x) letoh16(x)
# define LE_32(x) letoh32(x)
# define LE_64(x) letoh64(x)
// Solaris header for endian and byte swap
#elif defined(__sun) || defined(sun)
# include <sys/byteorder.h>
// Solaris defines endian by setting _LITTLE_ENDIAN or _BIG_ENDIAN
# ifdef _BIG_ENDIAN
# define IS_BIG_ENDIAN
# endif
# ifdef _LITTLE_ENDIAN
# define IS_LITTLE_ENDIAN
# endif
// Solaris 10 defines bswap functions: BSWAP_16, BSWAP_32, BSWAP_64
// Solaris 10 defines conversion functions: BE_16, BE_32, BE_64, LE_16, LE_32, LE_64
// No system specific headers to get endian from, let boost guess from platform type
#else
# include <boost/detail/endian.hpp>
# ifdef BOOST_BIG_ENDIAN
# define IS_BIG_ENDIAN
# endif
# ifdef BOOST_LITTLE_ENDIAN
# define IS_LITTLE_ENDIAN
# endif
#endif
// Make sure we got some kind of endian (but not both)
#if defined(IS_BIG_ENDIAN) == defined(IS_LITTLE_ENDIAN)
# error "Failed to get endian type for this system"
#endif
// Define bswap functions if we didn't get any from the system headers
#ifndef BSWAP_16
# define BSWAP_16(x) ( \
((uint16_t)(x) & 0x00ffU) << 8 | \
((uint16_t)(x) & 0xff00U) >> 8)
#endif
#ifndef BSWAP_32
# define BSWAP_32(x) ( \
((uint32_t)(x) & 0x000000ffU) << 24 | \
((uint32_t)(x) & 0x0000ff00U) << 8 | \
((uint32_t)(x) & 0x00ff0000U) >> 8 | \
((uint32_t)(x) & 0xff000000U) >> 24)
#endif
#ifndef BSWAP_64
# define BSWAP_64(x) ( \
((uint64_t)(x) & 0x00000000000000ffULL) << 56 | \
((uint64_t)(x) & 0x000000000000ff00ULL) << 40 | \
((uint64_t)(x) & 0x0000000000ff0000ULL) << 24 | \
((uint64_t)(x) & 0x00000000ff000000ULL) << 8 | \
((uint64_t)(x) & 0x000000ff00000000ULL) >> 8 | \
((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24 | \
((uint64_t)(x) & 0x00ff000000000000ULL) >> 40 | \
((uint64_t)(x) & 0xff00000000000000ULL) >> 56)
#endif
// Define conversion functions if we didn't get any from the system headers
#ifndef BE_16
// Big endian system, swap when converting to/from little endian
# if defined IS_BIG_ENDIAN
# define BE_16(x) (x)
# define BE_32(x) (x)
# define BE_64(x) (x)
# define LE_16(x) BSWAP_16(x)
# define LE_32(x) BSWAP_32(x)
# define LE_64(x) BSWAP_64(x)
// Little endian system, swap when converting to/from big endian
# elif defined IS_LITTLE_ENDIAN
# define BE_16(x) BSWAP_16(x)
# define BE_32(x) BSWAP_32(x)
# define BE_64(x) BSWAP_64(x)
# define LE_16(x) (x)
# define LE_32(x) (x)
# define LE_64(x) (x)
# endif
#endif
#endif
|