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 #ifndef FRAMEWORK_BUILD
174 #include "gettext.h"
178 #define _(String) dgettext (PACKAGE, String)
179 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
180 #else
181 #include "libintlemu.h"
182 #define _(String) dgettext ("org.gnunet.gnunet", String)
183 #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
184 #endif
185 
186 #include <sys/mman.h>
187 
188 /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */
189 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
190 #define __BYTE_ORDER BYTE_ORDER
191 #define __BIG_ENDIAN BIG_ENDIAN
192 #endif
193 
194 #ifdef DARWIN
195 #define __BYTE_ORDER BYTE_ORDER
196 #define __BIG_ENDIAN BIG_ENDIAN
197 /* not available on darwin, override configure */
198 #undef HAVE_STAT64
199 #undef HAVE_MREMAP
200 #endif
201 
202 
203 #if ! HAVE_ATOLL
204 long long
205 atoll (const char *nptr);
206 
207 #endif
208 
209 #if ENABLE_NLS
210 #include "langinfo.h"
211 #endif
212 
213 #ifndef SIZE_MAX
214 #define SIZE_MAX ((size_t) (-1))
215 #endif
216 
217 #ifndef O_LARGEFILE
218 #define O_LARGEFILE 0
219 #endif
220 
224 #ifndef AI_NUMERICSERV
225 #define AI_NUMERICSERV 0
226 #endif
227 
228 
229 #if defined(__sparc__)
230 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
231  sizeof((val))); \
232  __tmp; })
233 #else
234 #define MAKE_UNALIGNED(val) val
235 #endif
236 
240 #define GNUNET_TERM_SIG SIGTERM
241 
242 
243 #ifndef PATH_MAX
244 
247 #define PATH_MAX 4096
248 #endif
249 
250 #if HAVE_THREAD_LOCAL_GCC
251 #define GNUNET_THREAD_LOCAL __thread
252 #else
253 #define GNUNET_THREAD_LOCAL
254 #endif
255 
259 #if __has_attribute (__nonstring__)
260 # define __nonstring __attribute__((__nonstring__))
261 #else
262 # define __nonstring
263 #endif
264 
265 #endif
long long atoll(const char *nptr)