GNU libmicrohttpd  0.9.66
mhd_byteorder.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2015 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 
26 #ifndef MHD_BYTEORDER_H
27 #define MHD_BYTEORDER_H
28 
29 #include "mhd_options.h"
30 
31 #include <stdint.h>
32 
33 #if HAVE_ENDIAN_H
34 #include <endian.h>
35 #endif
36 
37 #if HAVE_SYS_PARAM_H
38 #include <sys/param.h>
39 #endif
40 
41 #if HAVE_MACHINE_ENDIAN_H
42 #include <machine/endian.h>
43 #endif
44 
45 #if HAVE_SYS_ENDIAN_H
46 #include <sys/endian.h>
47 #endif
48 
49 #if HAVE_SYS_TYPES_H
50 #include <sys/types.h>
51 #endif
52 
53 #if HAVE_SYS_BYTEORDER_H
54 #include <sys/byteorder.h>
55 #endif
56 
57 #if HAVE_SYS_MACHINE_H
58 #include <sys/machine.h>
59 #endif
60 
61 #if HAVE_MACHINE_PARAM_H
62 #include <machine/param.h>
63 #endif
64 
65 #if 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__ == __ORDER_LITTLE_ENDIAN__
77 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
78 #elif defined(__ORDER_PDP_ENDIAN__) && __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
79 #define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN
80 #endif /* __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ */
81 #elif defined(__BYTE_ORDER)
82 #if defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN
83 #define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
84 #elif defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
85 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
86 #elif defined(__PDP_ENDIAN) && __BYTE_ORDER == __PDP_ENDIAN
87 #define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN
88 #endif /* __BYTE_ORDER == __PDP_ENDIAN */
89 #elif defined (BYTE_ORDER)
90 #if defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
91 #define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
92 #elif defined(LITTLE_ENDIAN) && BYTE_ORDER == LITTLE_ENDIAN
93 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
94 #elif defined(PDP_ENDIAN) && BYTE_ORDER == PDP_ENDIAN
95 #define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN
96 #endif /* __BYTE_ORDER == _PDP_ENDIAN */
97 #elif defined (_BYTE_ORDER)
98 #if defined(_BIG_ENDIAN) && _BYTE_ORDER == _BIG_ENDIAN
99 #define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
100 #elif defined(_LITTLE_ENDIAN) && _BYTE_ORDER == _LITTLE_ENDIAN
101 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
102 #elif defined(_PDP_ENDIAN) && _BYTE_ORDER == _PDP_ENDIAN
103 #define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN
104 #endif /* _BYTE_ORDER == _PDP_ENDIAN */
105 #endif /* _BYTE_ORDER */
106 
107 #ifndef _MHD_BYTE_ORDER
108 /* Byte order specification didn't detected in system headers */
109 /* Try some guessing */
110 
111 #if (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)) || \
112  (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN))
113 /* Seems that we are on big endian platform */
114 #define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
115 #elif (defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
116  (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN))
117 /* Seems that we are on little endian platform */
118 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
119 #elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \
120  defined(_M_X64) || defined(_M_AMD64) || defined(i386) || defined(__i386) || \
121  defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || \
122  defined(_M_IX86) || defined(_X86_) || defined (__THW_INTEL__)
123 /* x86 family is little endian */
124 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
125 #elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
126  defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
127 /* Looks like we are on ARM/MIPS in big endian mode */
128 #define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
129 #elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
130  defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
131 /* Looks like we are on ARM/MIPS in little endian mode */
132 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
133 #elif defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || \
134  defined(__HPPA__) || defined(__370__) || defined(__THW_370__) || \
135  defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__)
136 /* Looks like we are on big endian platform */
137 #define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
138 #elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(__ia64) || \
139  defined(_M_IA64) || defined(__itanium__) || defined(__bfin__) || \
140  defined(__BFIN__) || defined(bfin) || defined(BFIN)
141 /* Looks like we are on little endian platform */
142 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
143 #elif defined(_WIN32)
144 /* W32 is always little endian on all platforms */
145 #define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
146 #elif defined(WORDS_BIGENDIAN)
147 /* Use byte order detected by configure */
148 #define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
149 #endif /* _WIN32 */
150 
151 #endif /* !_MHD_BYTE_ORDER */
152 
153 #ifdef _MHD_BYTE_ORDER
154 /* Some safety checks */
155 #if defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN
156 #error Configure detected big endian byte order but headers specify different byte order
157 #elif !defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
158 #error Configure did not detect big endian byte order but headers specify big endian byte order
159 #endif /* !WORDS_BIGENDIAN && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN */
160 #endif /* _MHD_BYTE_ORDER */
161 
162 #endif /* !MHD_BYTEORDER_H */
additional automatic macros for MHD_config.h