| 1 |
/* |
| 2 |
This file is part of libmicrohttpd |
| 3 |
Copyright (C) 2015-2022 Karlson2k (Evgeny Grin) |
| 4 |
|
| 5 |
This library is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU Lesser General Public |
| 7 |
License as published by the Free Software Foundation; either |
| 8 |
version 2.1 of the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This library is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
Lesser General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public |
| 16 |
License along with this library. |
| 17 |
If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
/** |
| 21 |
* @file microhttpd/mhd_byteorder.h |
| 22 |
* @brief macro definitions for host byte order |
| 23 |
* @author Karlson2k (Evgeny Grin) |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef MHD_BYTEORDER_H |
| 27 |
#define MHD_BYTEORDER_H |
| 28 |
|
| 29 |
#include "mhd_options.h" |
| 30 |
|
| 31 |
#include <stdint.h> |
| 32 |
|
| 33 |
#ifdef HAVE_ENDIAN_H |
| 34 |
#include <endian.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifdef HAVE_SYS_PARAM_H |
| 38 |
#include <sys/param.h> |
| 39 |
#endif |
| 40 |
|
| 41 |
#ifdef HAVE_MACHINE_ENDIAN_H |
| 42 |
#include <machine/endian.h> |
| 43 |
#endif |
| 44 |
|
| 45 |
#ifdef HAVE_SYS_ENDIAN_H |
| 46 |
#include <sys/endian.h> |
| 47 |
#endif |
| 48 |
|
| 49 |
#ifdef HAVE_SYS_TYPES_H |
| 50 |
#include <sys/types.h> |
| 51 |
#endif |
| 52 |
|
| 53 |
#ifdef HAVE_SYS_BYTEORDER_H |
| 54 |
#include <sys/byteorder.h> |
| 55 |
#endif |
| 56 |
|
| 57 |
#ifdef HAVE_SYS_MACHINE_H |
| 58 |
#include <sys/machine.h> |
| 59 |
#endif |
| 60 |
|
| 61 |
#ifdef HAVE_MACHINE_PARAM_H |
| 62 |
#include <machine/param.h> |
| 63 |
#endif |
| 64 |
|
| 65 |
#ifdef HAVE_SYS_ISA_DEFS_H |
| 66 |
#include <sys/isa_defs.h> |
| 67 |
#endif |
| 68 |
|
| 69 |
#define _MHD_BIG_ENDIAN 1234 |
| 70 |
#define _MHD_LITTLE_ENDIAN 4321 |
| 71 |
#define _MHD_PDP_ENDIAN 2143 |
| 72 |
|
| 73 |
#if defined(__BYTE_ORDER__) |
| 74 |
#if defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 75 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 76 |
#elif defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == \ |
| 77 |
__ORDER_LITTLE_ENDIAN__ |
| 78 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 79 |
#elif defined(__ORDER_PDP_ENDIAN__) && __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ |
| 80 |
#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN |
| 81 |
#endif /* __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ */ |
| 82 |
#elif defined(__BYTE_ORDER) |
| 83 |
#if defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN |
| 84 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 85 |
#elif defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN |
| 86 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 87 |
#elif defined(__PDP_ENDIAN) && __BYTE_ORDER == __PDP_ENDIAN |
| 88 |
#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN |
| 89 |
#endif /* __BYTE_ORDER == __PDP_ENDIAN */ |
| 90 |
#elif defined(BYTE_ORDER) |
| 91 |
#if defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN |
| 92 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 93 |
#elif defined(LITTLE_ENDIAN) && BYTE_ORDER == LITTLE_ENDIAN |
| 94 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 95 |
#elif defined(PDP_ENDIAN) && BYTE_ORDER == PDP_ENDIAN |
| 96 |
#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN |
| 97 |
#endif /* __BYTE_ORDER == _PDP_ENDIAN */ |
| 98 |
#elif defined(_BYTE_ORDER) |
| 99 |
#if defined(_BIG_ENDIAN) && _BYTE_ORDER == _BIG_ENDIAN |
| 100 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 101 |
#elif defined(_LITTLE_ENDIAN) && _BYTE_ORDER == _LITTLE_ENDIAN |
| 102 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 103 |
#elif defined(_PDP_ENDIAN) && _BYTE_ORDER == _PDP_ENDIAN |
| 104 |
#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN |
| 105 |
#endif /* _BYTE_ORDER == _PDP_ENDIAN */ |
| 106 |
#endif /* _BYTE_ORDER */ |
| 107 |
|
| 108 |
#ifndef _MHD_BYTE_ORDER |
| 109 |
/* Byte order specification didn't detected in system headers */ |
| 110 |
/* Try some guessing */ |
| 111 |
|
| 112 |
#if (defined(__BIG_ENDIAN__) && ! defined(__LITTLE_ENDIAN__)) || \ |
| 113 |
(defined(_BIG_ENDIAN) && ! defined(_LITTLE_ENDIAN)) |
| 114 |
/* Seems that we are on big endian platform */ |
| 115 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 116 |
#elif (defined(__LITTLE_ENDIAN__) && ! defined(__BIG_ENDIAN__)) || \ |
| 117 |
(defined(_LITTLE_ENDIAN) && ! defined(_BIG_ENDIAN)) |
| 118 |
/* Seems that we are on little endian platform */ |
| 119 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 120 |
#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \ |
| 121 |
defined(__x86_64) || \ |
| 122 |
defined(_M_X64) || defined(_M_AMD64) || defined(i386) || defined(__i386) || \ |
| 123 |
defined(__i386__) || defined(__i486__) || defined(__i586__) || \ |
| 124 |
defined(__i686__) || \ |
| 125 |
defined(_M_IX86) || defined(_X86_) || defined(__THW_INTEL__) |
| 126 |
/* x86 family is little endian */ |
| 127 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 128 |
#elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ |
| 129 |
defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) |
| 130 |
/* Looks like we are on ARM/MIPS in big endian mode */ |
| 131 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 132 |
#elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \ |
| 133 |
defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) |
| 134 |
/* Looks like we are on ARM/MIPS in little endian mode */ |
| 135 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 136 |
#elif defined(__m68k__) || defined(M68000) || defined(__hppa__) || \ |
| 137 |
defined(__hppa) || \ |
| 138 |
defined(__HPPA__) || defined(__370__) || defined(__THW_370__) || \ |
| 139 |
defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__) |
| 140 |
/* Looks like we are on big endian platform */ |
| 141 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 142 |
#elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \ |
| 143 |
defined(__ia64) || \ |
| 144 |
defined(_M_IA64) || defined(__itanium__) || defined(__bfin__) || \ |
| 145 |
defined(__BFIN__) || defined(bfin) || defined(BFIN) |
| 146 |
/* Looks like we are on little endian platform */ |
| 147 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 148 |
#elif defined(_WIN32) |
| 149 |
/* W32 is always little endian on all platforms */ |
| 150 |
#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN |
| 151 |
#elif defined(WORDS_BIGENDIAN) |
| 152 |
/* Use byte order detected by configure */ |
| 153 |
#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN |
| 154 |
#endif /* _WIN32 */ |
| 155 |
|
| 156 |
#endif /* !_MHD_BYTE_ORDER */ |
| 157 |
|
| 158 |
#ifdef _MHD_BYTE_ORDER |
| 159 |
/* Some safety checks */ |
| 160 |
#if defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN |
| 161 |
#error \ |
| 162 |
Configure detected big endian byte order but headers specify different byte order |
| 163 |
#elif ! defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN |
| 164 |
#error \ |
| 165 |
Configure did not detect big endian byte order but headers specify big endian byte order |
| 166 |
#endif /* !WORDS_BIGENDIAN && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN */ |
| 167 |
#endif /* _MHD_BYTE_ORDER */ |
| 168 |
|
| 169 |
#endif /* !MHD_BYTEORDER_H */ |