GNUnet  0.11.x
platform.h
Go to the documentation of this file.
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 
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 #ifdef __clang__
49 #undef HAVE_STATIC_ASSERT
50 #endif
51 
55 #define ALLOW_EXTRA_CHECKS GNUNET_YES
56 
60 #ifndef _XOPEN_SOURCE
61 #define _XOPEN_SOURCE 499
62 #endif
63 
64 #ifndef _REENTRANT
65 #define _REENTRANT
66 #endif
67 
68 /* configuration options */
69 
70 #define VERBOSE_STATS 0
71 
72 #include <netdb.h>
73 #include <sys/socket.h>
74 #include <sys/un.h>
75 #if HAVE_NETINET_IN_H
76 #include <netinet/in.h>
77 #endif
78 #if HAVE_NETINET_IN_SYSTM_H
79 #include <netinet/in_systm.h>
80 #endif
81 #if HAVE_NETINET_IP_H
82 #include <netinet/ip.h> /* superset of previous */
83 #endif
84 #include <arpa/inet.h>
85 #include <netinet/tcp.h>
86 #include <pwd.h>
87 #include <sys/ioctl.h>
88 #include <sys/wait.h>
89 #include <grp.h>
90 
91 #include <string.h>
92 #include <stdio.h>
93 #include <stdlib.h>
94 #include <stdint.h>
95 #include <stdarg.h>
96 #include <stdbool.h>
97 #include <errno.h>
98 #include <signal.h>
99 #include <libgen.h>
100 #ifdef HAVE_MALLOC_H
101 #include <malloc.h> /* for mallinfo on GNU */
102 #endif
103 #include <unistd.h> /* KLB_FIX */
104 #include <sys/stat.h>
105 #include <sys/types.h>
106 #include <dirent.h> /* KLB_FIX */
107 #include <fcntl.h>
108 #include <math.h>
109 #if HAVE_SYS_PARAM_H
110 #include <sys/param.h>
111 #endif
112 #if HAVE_SYS_TIME_H
113 #include <sys/time.h>
114 #endif
115 #include <time.h>
116 #ifdef BSD
117 #include <net/if.h>
118 #endif
119 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
120 #include <semaphore.h>
121 #endif
122 #ifdef DARWIN
123 #include <dlfcn.h>
124 #include <semaphore.h>
125 #include <net/if.h>
126 #endif
127 #if defined(__linux__) || defined(GNU)
128 #include <net/if.h>
129 #endif
130 #ifdef SOLARIS
131 #include <sys/sockio.h>
132 #include <sys/filio.h>
133 #include <sys/loadavg.h>
134 #include <semaphore.h>
135 #endif
136 #if HAVE_UCRED_H
137 #include <ucred.h>
138 #endif
139 #if HAVE_SYS_UCRED_H
140 #include <sys/ucred.h>
141 #endif
142 #if HAVE_IFADDRS_H
143 #include <ifaddrs.h>
144 #endif
145 #include <errno.h>
146 #include <limits.h>
147 
148 #if HAVE_VFORK_H
149 #include <vfork.h>
150 #endif
151 
152 #include <ctype.h>
153 #if HAVE_SYS_RESOURCE_H
154 #include <sys/resource.h>
155 #endif
156 
157 #if HAVE_ENDIAN_H
158 #include <endian.h>
159 #endif
160 #if HAVE_SYS_ENDIAN_H
161 #include <sys/endian.h>
162 #endif
163 
164 #define DIR_SEPARATOR '/'
165 #define DIR_SEPARATOR_STR "/"
166 #define PATH_SEPARATOR ':'
167 #define PATH_SEPARATOR_STR ":"
168 #define NEWLINE "\n"
169 
170 #include "compat.h"
171 
172 #include <locale.h>
173 #include "gettext.h"
177 #define _(String) dgettext (PACKAGE, String)
178 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
179 
180 #include <sys/mman.h>
181 
182 /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */
183 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
184 #define __BYTE_ORDER BYTE_ORDER
185 #define __BIG_ENDIAN BIG_ENDIAN
186 #endif
187 
188 #ifdef DARWIN
189 #define __BYTE_ORDER BYTE_ORDER
190 #define __BIG_ENDIAN BIG_ENDIAN
191 /* not available on darwin, override configure */
192 #undef HAVE_STAT64
193 #undef HAVE_MREMAP
194 #endif
195 
196 #if ! HAVE_ATOLL
197 long long
198 atoll (const char *nptr);
199 
200 #endif
201 
202 #if ENABLE_NLS
203 #include "langinfo.h"
204 #endif
205 
206 #ifndef SIZE_MAX
207 #define SIZE_MAX ((size_t) (-1))
208 #endif
209 
210 #ifndef O_LARGEFILE
211 #define O_LARGEFILE 0
212 #endif
213 
217 #ifndef AI_NUMERICSERV
218 #define AI_NUMERICSERV 0
219 #endif
220 
221 
222 #if defined(__sparc__)
223 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
224  sizeof((val))); \
225  __tmp; })
226 #else
227 #define MAKE_UNALIGNED(val) val
228 #endif
229 
233 #define GNUNET_TERM_SIG SIGTERM
234 
235 
236 #ifndef PATH_MAX
240 #define PATH_MAX 4096
241 #endif
242 
243 #if HAVE_THREAD_LOCAL_GCC
244 #define GNUNET_THREAD_LOCAL __thread
245 #else
246 #define GNUNET_THREAD_LOCAL
247 #endif
248 
249 
250 /* LSB-style exit status codes */
251 #ifndef EXIT_INVALIDARGUMENT
252 #define EXIT_INVALIDARGUMENT 2
253 #endif
254 
255 #ifndef EXIT_NOTIMPLEMENTED
256 #define EXIT_NOTIMPLEMENTED 3
257 #endif
258 
259 #ifndef EXIT_NOPERMISSION
260 #define EXIT_NOPERMISSION 4
261 #endif
262 
263 #ifndef EXIT_NOTINSTALLED
264 #define EXIT_NOTINSTALLED 5
265 #endif
266 
267 #ifndef EXIT_NOTCONFIGURED
268 #define EXIT_NOTCONFIGURED 6
269 #endif
270 
271 #ifndef EXIT_NOTRUNNING
272 #define EXIT_NOTRUNNING 7
273 #endif
274 
278 #if __has_attribute (__nonstring__)
279 # define __nonstring __attribute__((__nonstring__))
280 #else
281 # define __nonstring
282 #endif
283 
284 #endif
long long atoll(const char *nptr)