Simplify endianness and fix for unaligned reads (bug #3867)
[asterisk/asterisk.git] / include / asterisk / endian.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Asterisk internal frame definitions.
5  * 
6  * Copyright (C) 1999 - 2005, Digium, Inc.
7  *
8  * Mark Spencer <markster@digium.com>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU Lesser General Public License.  Other components of
12  * Asterisk are distributed under The GNU General Public License
13  * only.
14  */
15
16 #ifndef _ASTERISK_ENDIAN_H
17 #define _ASTERISK_ENDIAN_H
18
19 /*
20  * Autodetect system endianess
21  */
22
23 #if defined( __OpenBSD__ )
24 #  include <machine/types.h>
25 #  include <sys/endian.h>
26 #elif defined( __FreeBSD__ ) || defined( __NetBSD__ )
27 #  include <sys/types.h>
28 #  include <sys/endian.h>
29 #elif defined( BSD ) && ( BSD >= 199103 ) || defined(__APPLE__)
30 #  include <machine/endian.h>
31 #elif defined ( SOLARIS )
32 #  include <solaris-compat/compat.h>
33 #elif defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
34 #  include <endian.h>
35 #if !defined(__APPLE__)
36 #  include <byteswap.h>
37 #endif
38 #elif defined( linux )
39 #  include <endian.h>
40 #endif
41
42 #ifndef BYTE_ORDER
43 #define BYTE_ORDER __BYTE_ORDER
44 #endif
45
46 #ifndef __BYTE_ORDER
47 #error Endianess needs to be defined
48 #endif
49 #endif /* _ASTERISK_ENDIAN_H */
50