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 #if ! HAVE_ATOLL
203 long long
204 atoll (const char *nptr);
205 
206 #endif
207 
208 #if ENABLE_NLS
209 #include "langinfo.h"
210 #endif
211 
212 #ifndef SIZE_MAX
213 #define SIZE_MAX ((size_t) (-1))
214 #endif
215 
216 #ifndef O_LARGEFILE
217 #define O_LARGEFILE 0
218 #endif
219 
223 #ifndef AI_NUMERICSERV
224 #define AI_NUMERICSERV 0
225 #endif
226 
227 
228 #if defined(__sparc__)
229 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
230  sizeof((val))); \
231  __tmp; })
232 #else
233 #define MAKE_UNALIGNED(val) val
234 #endif
235 
239 #define GNUNET_TERM_SIG SIGTERM
240 
241 
242 #ifndef PATH_MAX
243 
246 #define PATH_MAX 4096
247 #endif
248 
249 #if HAVE_THREAD_LOCAL_GCC
250 #define GNUNET_THREAD_LOCAL __thread
251 #else
252 #define GNUNET_THREAD_LOCAL
253 #endif
254 
258 #if __has_attribute (__nonstring__)
259 # define __nonstring __attribute__((__nonstring__))
260 #else
261 # define __nonstring
262 #endif
263 
264 #endif
long long atoll(const char *nptr)