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