976c9eac7a19dddee009c6276922a2dc85a76975
[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 #define BREAKPOINT
42 #define GNUNET_SIGCHLD SIGCHLD
43
44 #ifdef HAVE_SYS_TYPES_H
45 #include <sys/types.h>
46 #endif
47
48 /**
49  * These may be expensive, but good for debugging...
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 499
58 #endif
59
60 #ifndef _REENTRANT
61 #define _REENTRANT
62 #endif
63
64 /* configuration options */
65
66 #define VERBOSE_STATS 0
67
68 #include <netdb.h>
69 #include <sys/socket.h>
70 #include <sys/un.h>
71 #if HAVE_NETINET_IN_H
72 #include <netinet/in.h>
73 #endif
74 #if HAVE_NETINET_IN_SYSTM_H
75 #include <netinet/in_systm.h>
76 #endif
77 #if HAVE_NETINET_IP_H
78 #include <netinet/ip.h>         /* superset of previous */
79 #endif
80 #include <arpa/inet.h>
81 #include <netinet/tcp.h>
82 #include <pwd.h>
83 #include <sys/ioctl.h>
84 #include <sys/wait.h>
85 #include <grp.h>
86
87 #include <string.h>
88 #include <stdio.h>
89 #include <stdlib.h>
90 #include <stdint.h>
91 #include <stdarg.h>
92 #include <stdbool.h>
93 #include <errno.h>
94 #include <signal.h>
95 #include <libgen.h>
96 #ifdef HAVE_MALLOC_H
97 #include <malloc.h>             /* for mallinfo on GNU */
98 #endif
99 #include <unistd.h>             /* KLB_FIX */
100 #include <sys/stat.h>
101 #include <sys/types.h>
102 #include <dirent.h>             /* KLB_FIX */
103 #include <fcntl.h>
104 #include <math.h>
105 #if HAVE_SYS_PARAM_H
106 #include <sys/param.h>
107 #endif
108 #if TIME_WITH_SYS_TIME
109 #include <sys/time.h>
110 #include <time.h>
111 #else
112 #if HAVE_SYS_TIME_H
113 #include <sys/time.h>
114 #else
115 #include <time.h>
116 #endif
117 #endif
118 #ifdef BSD
119 #include <net/if.h>
120 #endif
121 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
122 #include <semaphore.h>
123 #endif
124 #ifdef DARWIN
125 #include <dlfcn.h>
126 #include <semaphore.h>
127 #include <net/if.h>
128 #endif
129 #if defined(LINUX) || defined(GNU)
130 #include <net/if.h>
131 #endif
132 #ifdef SOLARIS
133 #include <sys/sockio.h>
134 #include <sys/filio.h>
135 #include <sys/loadavg.h>
136 #include <semaphore.h>
137 #endif
138 #if HAVE_UCRED_H
139 #include <ucred.h>
140 #endif
141 #if HAVE_SYS_UCRED_H
142 #include <sys/ucred.h>
143 #endif
144 #if HAVE_IFADDRS_H
145 #include <ifaddrs.h>
146 #endif
147 #include <errno.h>
148 #include <limits.h>
149
150 #if HAVE_VFORK_H
151 #include <vfork.h>
152 #endif
153
154 #include <ctype.h>
155 #if HAVE_SYS_RESOURCE_H
156 #include <sys/resource.h>
157 #endif
158
159 #if HAVE_ENDIAN_H
160 #include <endian.h>
161 #endif
162 #if HAVE_SYS_ENDIAN_H
163 #include <sys/endian.h>
164 #endif
165
166 #define DIR_SEPARATOR '/'
167 #define DIR_SEPARATOR_STR "/"
168 #define PATH_SEPARATOR ':'
169 #define PATH_SEPARATOR_STR ":"
170 #define NEWLINE "\n"
171
172 #include "compat.h"
173
174 #include <locale.h>
175 #ifndef FRAMEWORK_BUILD
176 #include "gettext.h"
177 /**
178  * GNU gettext support macro.
179  */
180 #define _(String) dgettext (PACKAGE, String)
181 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
182 #else
183 #include "libintlemu.h"
184 #define _(String) dgettext ("org.gnunet.gnunet", String)
185 #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
186 #endif
187
188 #include <sys/mman.h>
189
190 /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD  */
191 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
192 #define __BYTE_ORDER BYTE_ORDER
193 #define __BIG_ENDIAN BIG_ENDIAN
194 #endif
195
196 #ifdef DARWIN
197 #define __BYTE_ORDER BYTE_ORDER
198 #define __BIG_ENDIAN BIG_ENDIAN
199 /* not available on darwin, override configure */
200 #undef HAVE_STAT64
201 #undef HAVE_MREMAP
202 #endif
203
204
205 #if ! HAVE_ATOLL
206 long long
207 atoll (const char *nptr);
208
209 #endif
210
211 #if ENABLE_NLS
212 #include "langinfo.h"
213 #endif
214
215 #ifndef SIZE_MAX
216 #define SIZE_MAX ((size_t) (-1))
217 #endif
218
219 #ifndef O_LARGEFILE
220 #define O_LARGEFILE 0
221 #endif
222
223 /**
224  * AI_NUMERICSERV not defined in windows.  Then we just do without.
225  */
226 #ifndef AI_NUMERICSERV
227 #define AI_NUMERICSERV 0
228 #endif
229
230
231 #if defined(__sparc__)
232 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
233                                                                  sizeof((val))); \
234                                __tmp; })
235 #else
236 #define MAKE_UNALIGNED(val) val
237 #endif
238
239 /**
240  * The termination signal
241  */
242 #define GNUNET_TERM_SIG SIGTERM
243
244
245 #ifndef PATH_MAX
246 /**
247  * Assumed maximum path length.
248  */
249 #define PATH_MAX 4096
250 #endif
251
252 #if HAVE_THREAD_LOCAL_GCC
253 #define GNUNET_THREAD_LOCAL __thread
254 #else
255 #define GNUNET_THREAD_LOCAL
256 #endif
257
258 /**
259  * clang et al do not have such an attribute
260  */
261 #if __has_attribute (__nonstring__)
262 # define __nonstring                    __attribute__((__nonstring__))
263 #else
264 # define __nonstring
265 #endif
266
267 #endif