Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / include / platform.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2012 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @author Nils Durner
21  * @author Christian Grothoff
22  *
23  * @file
24  * Plaform specific includes and defines.
25  *
26  * This file should never be included by installed
27  * header files (those starting with "gnunet_").
28  */
29 #ifndef PLATFORM_H
30 #define PLATFORM_H
31
32 #ifndef HAVE_USED_CONFIG_H
33 #define HAVE_USED_CONFIG_H
34 #if HAVE_CONFIG_H
35 #include "gnunet_config.h"
36 #endif
37 #endif
38
39 #ifdef WINDOWS
40 #define BREAKPOINT asm("int $3;");
41 #define GNUNET_SIGCHLD 17
42 #else
43 #define BREAKPOINT
44 #define GNUNET_SIGCHLD SIGCHLD
45 #endif
46
47 #ifdef HAVE_SYS_TYPES_H
48 #include <sys/types.h>
49 #endif
50
51 /**
52  * These may be expensive, but good for debugging...
53  */
54 #define ALLOW_EXTRA_CHECKS GNUNET_YES
55
56 /**
57  * For strptime (glibc2 needs this).
58  */
59 #ifndef _XOPEN_SOURCE
60 #define _XOPEN_SOURCE 499
61 #endif
62
63 #ifndef _REENTRANT
64 #define _REENTRANT
65 #endif
66
67 /* configuration options */
68
69 #define VERBOSE_STATS 0
70
71 #ifdef CYGWIN
72 #include <sys/reent.h>
73 #endif
74
75 #ifdef _MSC_VER
76 #ifndef FD_SETSIZE
77 #define FD_SETSIZE 1024
78 #endif
79 #include <Winsock2.h>
80 #include <ws2tcpip.h>
81 #else
82 #ifndef MINGW
83 #include <netdb.h>
84 #include <sys/socket.h>
85 #include <sys/un.h>
86 #if HAVE_NETINET_IN_H
87 #include <netinet/in.h>
88 #endif
89 #if HAVE_NETINET_IN_SYSTM_H
90 #include <netinet/in_systm.h>
91 #endif
92 #if HAVE_NETINET_IP_H
93 #include <netinet/ip.h>         /* superset of previous */
94 #endif
95 #include <arpa/inet.h>
96 #include <netinet/tcp.h>
97 #include <pwd.h>
98 #include <sys/ioctl.h>
99 #include <sys/wait.h>
100 #include <grp.h>
101 #else
102 #include "winproc.h"
103 #endif
104 #endif
105
106 #include <string.h>
107 #include <stdio.h>
108 #include <stdlib.h>
109 #include <stdint.h>
110 #include <stdarg.h>
111 #include <stdbool.h>
112 #include <errno.h>
113 #include <signal.h>
114 #include <libgen.h>
115 #ifdef WINDOWS
116 #include <malloc.h>             /* for alloca(), on other OSes it's in stdlib.h */
117 #endif
118 #ifdef HAVE_MALLOC_H
119 #include <malloc.h>             /* for mallinfo on GNU */
120 #endif
121 #ifndef _MSC_VER
122 #include <unistd.h>             /* KLB_FIX */
123 #endif
124 #include <sys/stat.h>
125 #include <sys/types.h>
126 #ifndef _MSC_VER
127 #include <dirent.h>             /* KLB_FIX */
128 #endif
129 #include <fcntl.h>
130 #include <math.h>
131 #if HAVE_SYS_PARAM_H
132 #include <sys/param.h>
133 #endif
134 #if TIME_WITH_SYS_TIME
135 #include <sys/time.h>
136 #include <time.h>
137 #else
138 #if HAVE_SYS_TIME_H
139 #include <sys/time.h>
140 #else
141 #include <time.h>
142 #endif
143 #endif
144
145 #ifdef SOMEBSD
146 #include <net/if.h>
147 #endif
148 #ifdef FREEBSD
149 #include <semaphore.h>
150 #endif
151 #ifdef DARWIN
152 #include <dlfcn.h>
153 #include <semaphore.h>
154 #include <net/if.h>
155 #endif
156 #if defined(LINUX) || defined(GNU)
157 #include <net/if.h>
158 #endif
159 #ifdef SOLARIS
160 #include <sys/sockio.h>
161 #include <sys/filio.h>
162 #include <sys/loadavg.h>
163 #include <semaphore.h>
164 #endif
165 #if HAVE_UCRED_H
166 #include <ucred.h>
167 #endif
168 #if HAVE_SYS_UCRED_H
169 #include <sys/ucred.h>
170 #endif
171 #ifdef CYGWIN
172 #include <windows.h>
173 #include <cygwin/if.h>
174 #endif
175 #if HAVE_IFADDRS_H
176 #include <ifaddrs.h>
177 #endif
178 #include <errno.h>
179 #include <limits.h>
180
181 #if HAVE_VFORK_H
182 #include <vfork.h>
183 #endif
184
185 #include <ctype.h>
186 #if HAVE_SYS_RESOURCE_H
187 #include <sys/resource.h>
188 #endif
189
190 #if HAVE_ENDIAN_H
191 #include <endian.h>
192 #endif
193 #if HAVE_SYS_ENDIAN_H
194 #include <sys/endian.h>
195 #endif
196
197 #include "plibc.h"
198
199 #include <locale.h>
200 #ifndef FRAMEWORK_BUILD
201 #include "gettext.h"
202 /**
203  * GNU gettext support macro.
204  */
205 #define _(String) dgettext("gnunet",String)
206 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
207 #else
208 #include "libintlemu.h"
209 #define _(String) dgettext("org.gnunet.gnunet",String)
210 #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
211 #endif
212
213 #ifdef CYGWIN
214 #define SIOCGIFCONF     _IOW('s', 100, struct ifconf)   /* get if list */
215 #define SIOCGIFFLAGS    _IOW('s', 101, struct ifreq)    /* Get if flags */
216 #define SIOCGIFADDR     _IOW('s', 102, struct ifreq)    /* Get if addr */
217 #endif
218
219 #ifndef MINGW
220 #include <sys/mman.h>
221 #endif
222
223 #ifdef FREEBSD
224 #define __BYTE_ORDER BYTE_ORDER
225 #define __BIG_ENDIAN BIG_ENDIAN
226 #endif
227
228 #ifdef DARWIN
229 #define __BYTE_ORDER BYTE_ORDER
230 #define __BIG_ENDIAN BIG_ENDIAN
231  /* not available on darwin, override configure */
232 #undef HAVE_STAT64
233 #undef HAVE_MREMAP
234 #endif
235
236
237 #if !HAVE_ATOLL
238 long long
239 atoll (const char *nptr);
240 #endif
241
242 #if ENABLE_NLS
243 #include "langinfo.h"
244 #endif
245
246 #ifndef SIZE_MAX
247 #define SIZE_MAX ((size_t)(-1))
248 #endif
249
250 #ifndef O_LARGEFILE
251 #define O_LARGEFILE 0
252 #endif
253
254 /**
255  * AI_NUMERICSERV not defined in windows.  Then we just do without.
256  */
257 #ifndef AI_NUMERICSERV
258 #define AI_NUMERICSERV 0
259 #endif
260
261
262 #if defined(__sparc__)
263 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; })
264 #else
265 #define MAKE_UNALIGNED(val) val
266 #endif
267
268 #if WINDOWS
269 #define FDTYPE HANDLE
270 #define SOCKTYPE SOCKET
271 #else
272 #define FDTYPE int
273 #define SOCKTYPE int
274 #endif
275
276 /**
277  * The termination signal
278  */
279 #define GNUNET_TERM_SIG SIGTERM
280
281 #endif