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