platform.h (6363B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2012 GNUnet e.V. 4 Copyright (C) 2025 Taler Systems SA 5 6 GNUnet is free software: you can redistribute it and/or modify it 7 under the terms of the GNU Affero General Public License as published 8 by the Free Software Foundation, either version 3 of the License, 9 or (at your option) any later version. 10 11 GNUnet is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 19 SPDX-License-Identifier: AGPL3.0-or-later 20 */ 21 22 /** 23 * @author Nils Durner 24 * @author Christian Grothoff 25 * 26 * @file gnunet/src/include/platform.h 27 * Platform specific includes and defines. 28 * 29 * This file should never be included by installed 30 * header files (those starting with "gnunet_"). 31 * 32 * Every `#if HAVE_..._H' guard below needs a matching entry in the 33 * `check_headers' list in the top-level meson.build. An unprobed guard 34 * is not a conservative default: the macro stays undefined, the guard 35 * evaluates to 0, and the header is silently never included. 36 */ 37 #ifndef PLATFORM_H 38 #define PLATFORM_H 39 40 #ifndef HAVE_USED_CONFIG_H 41 #define HAVE_USED_CONFIG_H 42 #if HAVE_CONFIG_H 43 #include "paivana_config.h" 44 #endif 45 #endif 46 47 #define BREAKPOINT 48 #define GNUNET_SIGCHLD SIGCHLD 49 50 #ifdef HAVE_SYS_TYPES_H 51 #include <sys/types.h> 52 #endif 53 #include <inttypes.h> 54 55 #ifdef __clang__ 56 #undef HAVE_STATIC_ASSERT 57 #endif 58 59 /** 60 * These may be expensive, but good for debugging... 61 */ 62 #define ALLOW_EXTRA_CHECKS GNUNET_YES 63 64 /* A feature test macro only has an effect when it is defined before the 65 first libc header is pulled in, and by this point <inttypes.h> (and 66 hence <features.h>) has already been included. _XOPEN_SOURCE and 67 _REENTRANT used to be set here and were therefore inert; they are 68 gone rather than moved, because paivana uses no XSI-only function 69 and defining _XOPEN_SOURCE for real would *narrow* the visible 70 namespace rather than widen it. Add a feature test macro at the top 71 of this file, above every #include, if one is ever needed. */ 72 73 /* configuration options */ 74 75 #define VERBOSE_STATS 0 76 77 #include <netdb.h> 78 #include <sys/socket.h> 79 #include <sys/un.h> 80 #if HAVE_NETINET_IN_H 81 #include <netinet/in.h> 82 #endif 83 #if HAVE_NETINET_IN_SYSTM_H 84 #include <netinet/in_systm.h> 85 #endif 86 #if HAVE_NETINET_IP_H 87 #include <netinet/ip.h> /* superset of previous */ 88 #endif 89 #include <arpa/inet.h> 90 #include <netinet/tcp.h> 91 #include <pwd.h> 92 #include <sys/ioctl.h> 93 #include <sys/wait.h> 94 #include <grp.h> 95 96 #include <string.h> 97 #include <stdio.h> 98 #include <stdlib.h> 99 #include <stdint.h> 100 #include <stdarg.h> 101 #include <stdbool.h> 102 #include <errno.h> 103 #include <signal.h> 104 #include <libgen.h> 105 #ifdef HAVE_MALLOC_H 106 #include <malloc.h> /* for mallinfo on GNU */ 107 #endif 108 #include <unistd.h> /* KLB_FIX */ 109 #include <sys/stat.h> 110 #include <sys/types.h> 111 #include <dirent.h> /* KLB_FIX */ 112 #include <fcntl.h> 113 #include <math.h> 114 #if HAVE_SYS_PARAM_H 115 #include <sys/param.h> 116 #endif 117 #if HAVE_SYS_TIME_H 118 #include <sys/time.h> 119 #endif 120 #include <time.h> 121 #ifdef BSD 122 #include <net/if.h> 123 #endif 124 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) 125 #include <semaphore.h> 126 #endif 127 #ifdef DARWIN 128 #include <dlfcn.h> 129 #include <semaphore.h> 130 #include <net/if.h> 131 #include <xlocale.h> 132 #endif 133 #if defined(__linux__) || defined(GNU) 134 #include <net/if.h> 135 #endif 136 #ifdef SOLARIS 137 #include <sys/sockio.h> 138 #include <sys/filio.h> 139 #include <sys/loadavg.h> 140 #include <semaphore.h> 141 #endif 142 #if HAVE_UCRED_H 143 #include <ucred.h> 144 #endif 145 #if HAVE_SYS_UCRED_H 146 #include <sys/ucred.h> 147 #endif 148 #if HAVE_IFADDRS_H 149 #include <ifaddrs.h> 150 #endif 151 #include <errno.h> 152 #include <limits.h> 153 154 #if HAVE_VFORK_H 155 #include <vfork.h> 156 #endif 157 158 #include <ctype.h> 159 #if HAVE_SYS_RESOURCE_H 160 #include <sys/resource.h> 161 #endif 162 163 #if HAVE_ENDIAN_H 164 #include <endian.h> 165 #endif 166 #if HAVE_SYS_ENDIAN_H 167 #include <sys/endian.h> 168 #endif 169 170 #define DIR_SEPARATOR '/' 171 #define DIR_SEPARATOR_STR "/" 172 #define PATH_SEPARATOR ':' 173 #define PATH_SEPARATOR_STR ":" 174 #define NEWLINE "\n" 175 176 #include <locale.h> 177 #include <sys/mman.h> 178 179 /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */ 180 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) 181 #define __BYTE_ORDER BYTE_ORDER 182 #define __BIG_ENDIAN BIG_ENDIAN 183 #endif 184 185 #ifdef DARWIN 186 #define __BYTE_ORDER BYTE_ORDER 187 #define __BIG_ENDIAN BIG_ENDIAN 188 /* not available on darwin, override configure */ 189 #undef HAVE_STAT64 190 #undef HAVE_MREMAP 191 #endif 192 193 #if ! HAVE_ATOLL 194 long long 195 atoll (const char *nptr); 196 197 #endif 198 199 #if ENABLE_NLS 200 #include <langinfo.h> 201 #endif 202 203 #ifndef SIZE_MAX 204 #define SIZE_MAX ((size_t) (-1)) 205 #endif 206 207 #ifndef O_LARGEFILE 208 #define O_LARGEFILE 0 209 #endif 210 211 /** 212 * AI_NUMERICSERV not defined in windows. Then we just do without. 213 */ 214 #ifndef AI_NUMERICSERV 215 #define AI_NUMERICSERV 0 216 #endif 217 218 219 #if defined(__sparc__) 220 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \ 221 sizeof((val))); \ 222 __tmp; }) 223 #else 224 #define MAKE_UNALIGNED(val) val 225 #endif 226 227 /** 228 * The termination signal 229 */ 230 #define GNUNET_TERM_SIG SIGTERM 231 232 233 #ifndef PATH_MAX 234 /** 235 * Assumed maximum path length. 236 */ 237 #define PATH_MAX 4096 238 #endif 239 240 #if HAVE_THREAD_LOCAL_GCC 241 #define GNUNET_THREAD_LOCAL __thread 242 #else 243 #define GNUNET_THREAD_LOCAL 244 #endif 245 246 247 /* LSB-style exit status codes */ 248 #ifndef EXIT_INVALIDARGUMENT 249 #define EXIT_INVALIDARGUMENT 2 250 #endif 251 252 #ifndef EXIT_NOTIMPLEMENTED 253 #define EXIT_NOTIMPLEMENTED 3 254 #endif 255 256 #ifndef EXIT_NOPERMISSION 257 #define EXIT_NOPERMISSION 4 258 #endif 259 260 #ifndef EXIT_NOTINSTALLED 261 #define EXIT_NOTINSTALLED 5 262 #endif 263 264 #ifndef EXIT_NOTCONFIGURED 265 #define EXIT_NOTCONFIGURED 6 266 #endif 267 268 #ifndef EXIT_NOTRUNNING 269 #define EXIT_NOTRUNNING 7 270 #endif 271 272 #ifndef EXIT_NO_RESTART 273 #define EXIT_NO_RESTART 9 274 #endif 275 276 /** 277 * clang et al do not have such an attribute 278 */ 279 #if __has_attribute (__nonstring__) 280 # define __nonstring __attribute__((__nonstring__)) 281 #else 282 # define __nonstring 283 #endif 284 285 #endif