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