libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

le_architecture.h
Go to the documentation of this file.
1 /*
2  This file is part of libextractor.
3  Copyright (C) 2002, 2003, 2004, 2009, 2012 Vidyut Samanta and Christian Grothoff
4 
5  libextractor is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published
7  by the Free Software Foundation; either version 3, or (at your
8  option) any later version.
9 
10  libextractor is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with libextractor; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19  */
20 /**
21  * @file common/le_architecture.h
22  * @brief support routines and defines to deal with architecture-specific issues
23  */
24 #ifndef LE_ARCHITECTURE_H
25 #define LE_ARCHITECTURE_H
26 
27 #if WINDOWS
28 #include <sys/param.h> /* #define BYTE_ORDER */
29 #endif
30 
31 /* This is copied directly from GNUnet headers */
32 
33 #ifndef __BYTE_ORDER
34 #ifdef _BYTE_ORDER
35 #define __BYTE_ORDER _BYTE_ORDER
36 #else
37 #ifdef BYTE_ORDER
38 #define __BYTE_ORDER BYTE_ORDER
39 #endif
40 #endif
41 #endif
42 #ifndef __BIG_ENDIAN
43 #ifdef _BIG_ENDIAN
44 #define __BIG_ENDIAN _BIG_ENDIAN
45 #else
46 #ifdef BIG_ENDIAN
47 #define __BIG_ENDIAN BIG_ENDIAN
48 #endif
49 #endif
50 #endif
51 #ifndef __LITTLE_ENDIAN
52 #ifdef _LITTLE_ENDIAN
53 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
54 #else
55 #ifdef LITTLE_ENDIAN
56 #define __LITTLE_ENDIAN LITTLE_ENDIAN
57 #endif
58 #endif
59 #endif
60 
61 /**
62  * Endian operations
63  */
64 
65 #if __BYTE_ORDER == __LITTLE_ENDIAN
66 #define LE_htobe16(x) __bswap_16 (x)
67 #define LE_htole16(x) (x)
68 #define LE_be16toh(x) __bswap_16 (x)
69 #define LE_le16toh(x) (x)
70 
71 #define LE_htobe32(x) __bswap_32 (x)
72 #define LE_htole32(x) (x)
73 #define LE_be32toh(x) __bswap_32 (x)
74 #define LE_le32toh(x) (x)
75 
76 #define LE_htobe64(x) __bswap_64 (x)
77 #define LE_htole64(x) (x)
78 #define LE_be64toh(x) __bswap_64 (x)
79 #define LE_le64toh(x) (x)
80 #endif
81 #if __BYTE_ORDER == __BIG_ENDIAN
82 #define LE_htobe16(x) (x)
83 #define LE_htole16(x) __bswap_16 (x)
84 #define LE_be16toh(x) (x)
85 #define LE_le16toh(x) __bswap_16 (x)
86 
87 #define LE_htobe32(x) (x)
88 #define LE_htole32(x) __bswap_32 (x)
89 #define LE_be32toh(x) (x)
90 #define LE_le32toh(x) __bswap_32 (x)
91 
92 #define LE_htobe64(x) (x)
93 #define LE_htole64(x) __bswap_64 (x)
94 #define LE_be64toh(x) (x)
95 #define LE_le64toh(x) __bswap_64 (x)
96 #endif
97 
98 
99 /**
100  * gcc-ism to get packed structs.
101  */
102 #define LE_PACKED __attribute__((packed))
103 
104 
105 #if MINGW
106 #if __GNUC__ > 3
107 /**
108  * gcc 4.x-ism to pack structures even on W32 (to be used before structs)
109  */
110 #define LE_NETWORK_STRUCT_BEGIN \
111  _Pragma ("pack(push)") \
112  _Pragma ("pack(1)")
113 
114 /**
115  * gcc 4.x-ism to pack structures even on W32 (to be used after structs)
116  */
117 #define LE_NETWORK_STRUCT_END _Pragma ("pack(pop)")
118 #else
119 #error gcc 4.x or higher required on W32 systems
120 #endif
121 #else
122 /**
123  * Good luck, LE_PACKED should suffice, but this won't work on W32
124  */
125 #define LE_NETWORK_STRUCT_BEGIN
126 
127 /**
128  * Good luck, LE_PACKED should suffice, but this won't work on W32
129  */
130 #define LE_NETWORK_STRUCT_END
131 #endif
132 
133 
134 #endif