global reindent, now with uncrustify hook enabled
[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
119 #ifdef SOMEBSD
120 #include <net/if.h>
121 #endif
122 #ifdef FREEBSD
123 #include <semaphore.h>
124 #endif
125 #ifdef DARWIN
126 #include <dlfcn.h>
127 #include <semaphore.h>
128 #include <net/if.h>
129 #endif
130 #if defined(LINUX) || defined(GNU)
131 #include <net/if.h>
132 #endif
133 #ifdef SOLARIS
134 #include <sys/sockio.h>
135 #include <sys/filio.h>
136 #include <sys/loadavg.h>
137 #include <semaphore.h>
138 #endif
139 #if HAVE_UCRED_H
140 #include <ucred.h>
141 #endif
142 #if HAVE_SYS_UCRED_H
143 #include <sys/ucred.h>
144 #endif
145 #if HAVE_IFADDRS_H
146 #include <ifaddrs.h>
147 #endif
148 #include <errno.h>
149 #include <limits.h>
150
151 #if HAVE_VFORK_H
152 #include <vfork.h>
153 #endif
154
155 #include <ctype.h>
156 #if HAVE_SYS_RESOURCE_H
157 #include <sys/resource.h>
158 #endif
159
160 #if HAVE_ENDIAN_H
161 #include <endian.h>
162 #endif
163 #if HAVE_SYS_ENDIAN_H
164 #include <sys/endian.h>
165 #endif
166
167 #define DIR_SEPARATOR '/'
168 #define DIR_SEPARATOR_STR "/"
169 #define PATH_SEPARATOR ':'
170 #define PATH_SEPARATOR_STR ":"
171 #define NEWLINE "\n"
172
173 #include "compat.h"
174
175 #include <locale.h>
176 #ifndef FRAMEWORK_BUILD
177 #include "gettext.h"
178 /**
179  * GNU gettext support macro.
180  */
181 #define _(String) dgettext (PACKAGE, String)
182 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
183 #else
184 #include "libintlemu.h"
185 #define _(String) dgettext ("org.gnunet.gnunet", String)
186 #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
187 #endif
188
189 #include <sys/mman.h>
190
191 #ifdef FREEBSD
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 #endif
209
210 #if ENABLE_NLS
211 #include "langinfo.h"
212 #endif
213
214 #ifndef SIZE_MAX
215 #define SIZE_MAX ((size_t) (-1))
216 #endif
217
218 #ifndef O_LARGEFILE
219 #define O_LARGEFILE 0
220 #endif
221
222 /**
223  * AI_NUMERICSERV not defined in windows.  Then we just do without.
224  */
225 #ifndef AI_NUMERICSERV
226 #define AI_NUMERICSERV 0
227 #endif
228
229
230 #if defined(__sparc__)
231 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
232                                                                  sizeof((val))); \
233                                __tmp; })
234 #else
235 #define MAKE_UNALIGNED(val) val
236 #endif
237
238 #define FDTYPE int
239 #define SOCKTYPE int
240
241 /**
242  * The termination signal
243  */
244 #define GNUNET_TERM_SIG SIGTERM
245
246
247 #ifndef PATH_MAX
248 /**
249  * Assumed maximum path length.
250  */
251 #define PATH_MAX 4096
252 #endif
253
254 #if HAVE_THREAD_LOCAL_GCC
255 #define GNUNET_THREAD_LOCAL __thread
256 #else
257 #define GNUNET_THREAD_LOCAL
258 #endif
259
260 /**
261  * clang et al do not have such an attribute
262  */
263 #if __has_attribute (__nonstring__)
264 # define __nonstring                    __attribute__((__nonstring__))
265 #else
266 # define __nonstring
267 #endif
268
269 #endif