RECLAIM/OIDC: code cleanup
[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      SPDX-License-Identifier: AGPL3.0-or-later
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 <stdbool.h>
114 #include <errno.h>
115 #include <signal.h>
116 #include <libgen.h>
117 #ifdef WINDOWS
118 #include <malloc.h>             /* for alloca(), on other OSes it's in stdlib.h */
119 #endif
120 #ifdef HAVE_MALLOC_H
121 #include <malloc.h>             /* for mallinfo on GNU */
122 #endif
123 #ifndef _MSC_VER
124 #include <unistd.h>             /* KLB_FIX */
125 #endif
126 #include <sys/stat.h>
127 #include <sys/types.h>
128 #ifndef _MSC_VER
129 #include <dirent.h>             /* KLB_FIX */
130 #endif
131 #include <fcntl.h>
132 #include <math.h>
133 #if HAVE_SYS_PARAM_H
134 #include <sys/param.h>
135 #endif
136 #if TIME_WITH_SYS_TIME
137 #include <sys/time.h>
138 #include <time.h>
139 #else
140 #if HAVE_SYS_TIME_H
141 #include <sys/time.h>
142 #else
143 #include <time.h>
144 #endif
145 #endif
146
147 #ifdef SOMEBSD
148 #include <net/if.h>
149 #endif
150 #ifdef FREEBSD
151 #include <semaphore.h>
152 #endif
153 #ifdef DARWIN
154 #include <dlfcn.h>
155 #include <semaphore.h>
156 #include <net/if.h>
157 #endif
158 #if defined(LINUX) || defined(GNU)
159 #include <net/if.h>
160 #endif
161 #ifdef SOLARIS
162 #include <sys/sockio.h>
163 #include <sys/filio.h>
164 #include <sys/loadavg.h>
165 #include <semaphore.h>
166 #endif
167 #if HAVE_UCRED_H
168 #include <ucred.h>
169 #endif
170 #if HAVE_SYS_UCRED_H
171 #include <sys/ucred.h>
172 #endif
173 #ifdef CYGWIN
174 #include <windows.h>
175 #include <cygwin/if.h>
176 #endif
177 #if HAVE_IFADDRS_H
178 #include <ifaddrs.h>
179 #endif
180 #include <errno.h>
181 #include <limits.h>
182
183 #if HAVE_VFORK_H
184 #include <vfork.h>
185 #endif
186
187 #include <ctype.h>
188 #if HAVE_SYS_RESOURCE_H
189 #include <sys/resource.h>
190 #endif
191
192 #if HAVE_ENDIAN_H
193 #include <endian.h>
194 #endif
195 #if HAVE_SYS_ENDIAN_H
196 #include <sys/endian.h>
197 #endif
198
199 #include "plibc.h"
200 #include "compat.h"
201
202 #include <locale.h>
203 #ifndef FRAMEWORK_BUILD
204 #include "gettext.h"
205 /**
206  * GNU gettext support macro.
207  */
208 #define _(String) dgettext("gnunet",String)
209 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
210 #else
211 #include "libintlemu.h"
212 #define _(String) dgettext("org.gnunet.gnunet",String)
213 #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
214 #endif
215
216 #ifdef CYGWIN
217 #define SIOCGIFCONF     _IOW('s', 100, struct ifconf)   /* get if list */
218 #define SIOCGIFFLAGS    _IOW('s', 101, struct ifreq)    /* Get if flags */
219 #define SIOCGIFADDR     _IOW('s', 102, struct ifreq)    /* Get if addr */
220 #endif
221
222 #ifndef MINGW
223 #include <sys/mman.h>
224 #endif
225
226 #ifdef FREEBSD
227 #define __BYTE_ORDER BYTE_ORDER
228 #define __BIG_ENDIAN BIG_ENDIAN
229 #endif
230
231 #ifdef DARWIN
232 #define __BYTE_ORDER BYTE_ORDER
233 #define __BIG_ENDIAN BIG_ENDIAN
234  /* not available on darwin, override configure */
235 #undef HAVE_STAT64
236 #undef HAVE_MREMAP
237 #endif
238
239
240 #if !HAVE_ATOLL
241 long long
242 atoll (const char *nptr);
243 #endif
244
245 #if ENABLE_NLS
246 #include "langinfo.h"
247 #endif
248
249 #ifndef SIZE_MAX
250 #define SIZE_MAX ((size_t)(-1))
251 #endif
252
253 #ifndef O_LARGEFILE
254 #define O_LARGEFILE 0
255 #endif
256
257 /**
258  * AI_NUMERICSERV not defined in windows.  Then we just do without.
259  */
260 #ifndef AI_NUMERICSERV
261 #define AI_NUMERICSERV 0
262 #endif
263
264
265 #if defined(__sparc__)
266 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; })
267 #else
268 #define MAKE_UNALIGNED(val) val
269 #endif
270
271 #if WINDOWS
272 #define FDTYPE HANDLE
273 #define SOCKTYPE SOCKET
274 #else
275 #define FDTYPE int
276 #define SOCKTYPE int
277 #endif
278
279 /**
280  * The termination signal
281  */
282 #define GNUNET_TERM_SIG SIGTERM
283
284
285 #ifndef PATH_MAX
286 /**
287  * Assumed maximum path length.
288  */
289 #define PATH_MAX 4096
290 #endif
291
292
293
294 #endif