"Fossies" - the Fresh Open Source Software Archive 
Member "libtimidity-0.2.7/src/timi_endian.h" (23 Aug 2019, 7240 Bytes) of package /linux/privat/libtimidity-0.2.7.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* libTiMidity is licensed under the terms of the GNU Lesser General
2 * Public License: see COPYING for details.
3 *
4 * Note that the included TiMidity source, based on timidity-0.2i, was
5 * originally licensed under the GPL, but the author extended it so it
6 * can also be used separately under the GNU LGPL or the Perl Artistic
7 * License: see the notice by Tuukka Toivonen as it appears on the web
8 * at http://ieee.uwaterloo.ca/sca/www.cgs.fi/tt/timidity/ .
9 */
10
11 /* timi_endian.h -- endianness detection
12 * Copyright (C) 2007-2016 O.Sezer <sezero@users.sourceforge.net>
13 *
14 * This library is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation; either version 2.1 of the License, or (at
17 * your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this library; if not, write to the Free Software Foundation,
26 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29 #ifndef TIMI_ENDIAN_H
30 #define TIMI_ENDIAN_H
31
32 /* try the system headers first: with BSD and derivatives,
33 * sys/types.h can pull in the correct header and defs. */
34 #if !defined __VBCC__
35 #include <sys/types.h>
36 #endif
37
38 #if !defined(BYTE_ORDER) /* include more if it didn't work */
39
40 # if defined(__linux__) || defined(__linux)
41 # include <endian.h>
42 # elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
43 defined(__FreeBSD_kernel__) /* Debian GNU/kFreeBSD */ || \
44 (defined(__APPLE__) && defined(__MACH__)) /* Mac OS X */ || \
45 defined(__DragonFly__)
46 # include <machine/endian.h>
47 # elif defined(__sun) || defined(__svr4__)
48 # include <sys/byteorder.h>
49 # elif defined(_AIX)
50 # include <sys/machine.h>
51 # elif defined(sgi)
52 # include <sys/endian.h>
53 # elif defined(__MINGW32__)
54 # include <sys/param.h>
55 # elif defined(__DJGPP__)
56 # include <machine/endian.h>
57 # elif defined(__EMX__)
58 # include <machine/endian.h>
59 # elif defined(__OS2__) && defined(__WATCOMC__)
60 # include <machine/endian.h>
61 # elif defined(__MORPHOS__)
62 # include <machine/endian.h>
63 # elif defined(__amigaos__) && defined(__NEWLIB__)
64 # include <machine/endian.h>
65 # elif defined(__amigaos__) && defined(__CLIB2__)
66 # include <unistd.h>
67 # endif
68
69 #endif /* endian includes */
70
71
72 /* alternative macro names: */
73 #if defined(__BYTE_ORDER) && !defined(BYTE_ORDER)
74 #define BYTE_ORDER __BYTE_ORDER
75 #endif
76 #if defined(__LITTLE_ENDIAN) && !defined(LITTLE_ENDIAN)
77 #define LITTLE_ENDIAN __LITTLE_ENDIAN
78 #endif
79 #if defined(__BIG_ENDIAN) && !defined(BIG_ENDIAN)
80 #define BIG_ENDIAN __BIG_ENDIAN
81 #endif
82
83 /* new gcc and clang versions pre-define the following: */
84 #if defined(__BYTE_ORDER__) && !defined(BYTE_ORDER)
85 #define BYTE_ORDER __BYTE_ORDER__
86 #endif
87 #if defined(__ORDER_LITTLE_ENDIAN__) && !defined(LITTLE_ENDIAN)
88 #define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
89 #endif
90 #if defined(__ORDER_BIG_ENDIAN__) && !defined(BIG_ENDIAN)
91 #define BIG_ENDIAN __ORDER_BIG_ENDIAN__
92 #endif
93
94 #if !defined(PDP_ENDIAN)
95 #if defined(__ORDER_PDP_ENDIAN__)
96 #define PDP_ENDIAN __ORDER_PDP_ENDIAN__
97 #elif defined(__PDP_ENDIAN)
98 #define PDP_ENDIAN __PDP_ENDIAN
99 #else
100 #define PDP_ENDIAN 3412
101 #endif
102 #endif /* NUXI endian -- unsupported */
103
104 #if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
105
106 # if (BYTE_ORDER != LITTLE_ENDIAN) && (BYTE_ORDER != BIG_ENDIAN)
107 # error "Unsupported endianness."
108 # endif
109
110 #else /* one of the definitions is mising. */
111
112 # undef BYTE_ORDER
113 # undef LITTLE_ENDIAN
114 # undef BIG_ENDIAN
115 # define LITTLE_ENDIAN 1234
116 # define BIG_ENDIAN 4321
117
118 #endif /* byte order defs */
119
120
121 #if !defined(BYTE_ORDER) /* good assumptions: */
122
123 /* try the compiler-predefined endianness macros.
124 * Ref.: https://sf.net/p/predef/wiki/Endianness/
125 */
126 # if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
127 # define BYTE_ORDER BIG_ENDIAN
128
129 # elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
130 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
131 # define BYTE_ORDER BIG_ENDIAN
132
133 # elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
134 # define BYTE_ORDER LITTLE_ENDIAN
135
136 # elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
137 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
138 # define BYTE_ORDER LITTLE_ENDIAN
139
140 /* assumptions based on OS and/or architecture macros. Some refs:
141 * predef/other/endian.h from the boost library
142 * http://labs.hoffmanlabs.com/node/544
143 * https://blogs.msdn.com/larryosterman/archive/2005/06/07/426334.aspx
144 */
145 # elif defined(__i386) || defined(__i386__) || defined(__386__) || defined(_M_IX86) || defined(__I386__)
146 # define BYTE_ORDER LITTLE_ENDIAN /* any x86 */
147
148 # elif defined(__amd64) || defined(__x86_64__) || defined(_M_X64)
149 # define BYTE_ORDER LITTLE_ENDIAN /* any x64 */
150
151 # elif defined(__mc68000__) || defined(__M68K__) || defined(__m68k__) || defined(__MC68K__)
152 # define BYTE_ORDER BIG_ENDIAN /* Motorola 68k */
153
154 # elif defined(__sun) || defined(__svr4__) /* solaris */
155 # if defined(_LITTLE_ENDIAN) /* x86 */
156 # define BYTE_ORDER LITTLE_ENDIAN
157 # elif defined(_BIG_ENDIAN) /* sparc */
158 # define BYTE_ORDER BIG_ENDIAN
159 # endif
160
161 # elif defined(__hppa) || defined(__hppa__)
162 # define BYTE_ORDER BIG_ENDIAN /* PARISC */
163
164 # elif defined(__sparc) || defined(__sparc__)
165 # define BYTE_ORDER BIG_ENDIAN /* SPARC -- cf. boost/predef/other/endian.h */
166
167 # elif defined(__DJGPP__) || defined(__MSDOS__) || defined(__DOS__) || defined(_DOS)
168 # define BYTE_ORDER LITTLE_ENDIAN /* DOS */
169
170 # elif defined(__OS2__) || defined(__EMX__)
171 # define BYTE_ORDER LITTLE_ENDIAN /* OS2 */
172
173 # elif defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__NT__) || defined(_Windows)
174 # define BYTE_ORDER LITTLE_ENDIAN /* Windows */
175
176 # endif
177
178 #endif /* good assumptions */
179
180
181 #if !defined(BYTE_ORDER) /* [un]safe assumptions: */
182
183 /* assumptions based on OS and/or architecture macros.
184 * proceed carefully: many of these are bi-endian CPUs.
185 */
186 # if defined(__ppc__) || defined(__powerpc__) || defined(__POWERPC__) || defined(__PPC__)
187 # define BYTE_ORDER BIG_ENDIAN
188
189 # elif defined(__alpha__) || defined(__alpha)
190 # define BYTE_ORDER LITTLE_ENDIAN
191
192 # elif defined(__mips__) || defined(__MIPS__)
193 # define BYTE_ORDER BIG_ENDIAN
194
195 # endif
196
197 # if defined(BYTE_ORDER) && 0 /* change to 1 to for warnings */
198 # if (BYTE_ORDER == LITTLE_ENDIAN)
199 # warning "Using LIL endian as a SAFE default."
200 # else /*(BYTE_ORDER == BIG_ENDIAN)*/
201 # warning "Using BIG endian as a SAFE default."
202 # endif
203 # endif
204
205 #endif /* [un]safe assumptions */
206
207
208 #if !defined(BYTE_ORDER)
209 # error Could not determine BYTE_ORDER
210 #endif
211
212 /* for autotools compatibility */
213 #if (BYTE_ORDER == BIG_ENDIAN) && !defined(WORDS_BIGENDIAN)
214 # define WORDS_BIGENDIAN 1
215 #endif
216 #if (BYTE_ORDER != BIG_ENDIAN) && defined(WORDS_BIGENDIAN)
217 #error WORDS_BIGENDIAN defined for non-BIG_ENDIAN
218 #endif
219
220 #endif /* TIMI_ENDIAN_H */