c44f67f677eb457cc63c70ce1c7eae646ce6b530
[oweals/gnunet.git] / src / include / platform.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2012 Christian Grothoff (and other contributing authors)
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 2, 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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/platform.h
23  * @brief plaform specific includes and defines
24  * @author Nils Durner
25  * @author Christian Grothoff
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 #define ALLOW_EXTRA_CHECKS GNUNET_YES
52
53 /**
54  * For strptime (glibc2 needs this).
55  */
56 #ifndef _XOPEN_SOURCE
57 #define _XOPEN_SOURCE
58 #endif
59
60 #ifndef _REENTRANT
61 #define _REENTRANT
62 #endif
63
64 /* configuration options */
65
66 #define VERBOSE_STATS 0
67
68 #ifdef CYGWIN
69 #include <sys/reent.h>
70 #endif
71
72 #ifdef _MSC_VER
73 #ifndef FD_SETSIZE
74 #define FD_SETSIZE 1024
75 #endif
76 #include <Winsock2.h>
77 #include <ws2tcpip.h>
78 #else
79 #ifndef MINGW
80 #include <netdb.h>
81 #include <sys/socket.h>
82 #include <sys/un.h>
83 #if HAVE_NETINET_IN_H
84 #include <netinet/in.h>
85 #endif
86 #if HAVE_NETINET_IN_SYSTM_H
87 #include <netinet/in_systm.h>
88 #endif
89 #include <netinet/ip.h>         /* superset of previous */
90 #include <arpa/inet.h>
91 #include <netinet/tcp.h>
92 #include <pwd.h>
93 #include <sys/ioctl.h>
94 #include <sys/wait.h>
95 #include <grp.h>
96 #else
97 #include "winproc.h"
98 #endif
99 #endif
100
101 #include <string.h>
102 #include <stdio.h>
103 #include <stdlib.h>
104 #include <stdint.h>
105 #include <stdarg.h>
106 #include <errno.h>
107 #include <signal.h>
108 #include <libgen.h>
109 #ifdef WINDOWS
110 #include <malloc.h>             /* for alloca(), on other OSes it's in stdlib.h */
111 #endif
112 #ifdef HAVE_MALLOC_H
113 #include <malloc.h>             /* for mallinfo on GNU */
114 #endif
115 #ifndef _MSC_VER
116 #include <unistd.h>             /* KLB_FIX */
117 #endif
118 #include <sys/stat.h>
119 #include <sys/types.h>
120 #ifndef _MSC_VER
121 #include <dirent.h>             /* KLB_FIX */
122 #endif
123 #include <fcntl.h>
124 #include <math.h>
125 #if HAVE_SYS_PARAM_H
126 #include <sys/param.h>
127 #endif
128 #if TIME_WITH_SYS_TIME
129 #include <sys/time.h>
130 #include <time.h>
131 #else
132 #if HAVE_SYS_TIME_H
133 #include <sys/time.h>
134 #else
135 #include <time.h>
136 #endif
137 #endif
138
139 #ifdef SOMEBSD
140 #include <net/if.h>
141 #endif
142 #ifdef FREEBSD
143 #include <semaphore.h>
144 #endif
145 #ifdef DARWIN
146 #include <dlfcn.h>
147 #include <semaphore.h>
148 #include <net/if.h>
149 #endif
150 #if defined(LINUX) || defined(GNU)
151 #include <net/if.h>
152 #endif
153 #ifdef SOLARIS
154 #include <sys/sockio.h>
155 #include <sys/filio.h>
156 #include <sys/loadavg.h>
157 #include <semaphore.h>
158 #endif
159 #if HAVE_UCRED_H
160 #include <ucred.h>
161 #endif
162 #ifdef CYGWIN
163 #include <windows.h>
164 #include <cygwin/if.h>
165 #endif
166 #if HAVE_IFADDRS_H
167 #include <ifaddrs.h>
168 #endif
169 #include <errno.h>
170 #include <limits.h>
171
172 #if HAVE_VFORK_H
173 #include <vfork.h>
174 #endif
175
176 #include <ctype.h>
177 #if HAVE_SYS_RESOURCE_H
178 #include <sys/resource.h>
179 #endif
180
181 #if HAVE_ENDIAN_H
182 #include <endian.h>
183 #endif
184 #if HAVE_SYS_ENDIAN_H
185 #include <sys/endian.h>
186 #endif
187
188 #include "plibc.h"
189
190 #include <locale.h>
191 #ifndef FRAMEWORK_BUILD
192 #include "gettext.h"
193 /**
194  * GNU gettext support macro.
195  */
196 #define _(String) dgettext("gnunet",String)
197 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
198 #else
199 #include "libintlemu.h"
200 #define _(String) dgettext("org.gnunet.gnunet",String)
201 #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
202 #endif
203
204 #ifdef CYGWIN
205 #define SIOCGIFCONF     _IOW('s', 100, struct ifconf)   /* get if list */
206 #define SIOCGIFFLAGS    _IOW('s', 101, struct ifreq)    /* Get if flags */
207 #define SIOCGIFADDR     _IOW('s', 102, struct ifreq)    /* Get if addr */
208 #endif
209
210 #ifndef MINGW
211 #include <sys/mman.h>
212 #endif
213
214 #ifdef FREEBSD
215 #define __BYTE_ORDER BYTE_ORDER
216 #define __BIG_ENDIAN BIG_ENDIAN
217 #endif
218
219 #ifdef DARWIN
220 #define __BYTE_ORDER BYTE_ORDER
221 #define __BIG_ENDIAN BIG_ENDIAN
222  /* not available on darwin, override configure */
223 #undef HAVE_STAT64
224 #undef HAVE_MREMAP
225 #endif
226
227
228 #if !HAVE_ATOLL
229 long long
230 atoll (const char *nptr);
231 #endif
232
233 #if ENABLE_NLS
234 #include "langinfo.h"
235 #endif
236
237 #ifndef SIZE_MAX
238 #define SIZE_MAX ((size_t)(-1))
239 #endif
240
241 #ifndef O_LARGEFILE
242 #define O_LARGEFILE 0
243 #endif
244
245 /**
246  * AI_NUMERICSERV not defined in windows.  Then we just do without.
247  */
248 #ifndef AI_NUMERICSERV
249 #define AI_NUMERICSERV 0
250 #endif
251
252
253 #if defined(__sparc__)
254 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; })
255 #else
256 #define MAKE_UNALIGNED(val) val
257 #endif
258
259 #if WINDOWS
260 #define FDTYPE HANDLE
261 #define SOCKTYPE SOCKET
262 #else
263 #define FDTYPE int
264 #define SOCKTYPE int
265 #endif
266
267 #endif