platform.h (5678B)
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 #ifndef PLATFORM_H 33 #define PLATFORM_H 34 35 #ifndef HAVE_USED_CONFIG_H 36 #define HAVE_USED_CONFIG_H 37 #if HAVE_CONFIG_H 38 #include "paivana_config.h" 39 #endif 40 #endif 41 42 #define BREAKPOINT 43 #define GNUNET_SIGCHLD SIGCHLD 44 45 #ifdef HAVE_SYS_TYPES_H 46 #include <sys/types.h> 47 #endif 48 #include <inttypes.h> 49 50 #ifdef __clang__ 51 #undef HAVE_STATIC_ASSERT 52 #endif 53 54 /** 55 * These may be expensive, but good for debugging... 56 */ 57 #define ALLOW_EXTRA_CHECKS GNUNET_YES 58 59 /** 60 * For strptime (glibc2 needs this). 61 */ 62 #ifndef _XOPEN_SOURCE 63 #define _XOPEN_SOURCE 499 64 #endif 65 66 #ifndef _REENTRANT 67 #define _REENTRANT 68 #endif 69 70 /* configuration options */ 71 72 #define VERBOSE_STATS 0 73 74 #include <netdb.h> 75 #include <sys/socket.h> 76 #include <sys/un.h> 77 #if HAVE_NETINET_IN_H 78 #include <netinet/in.h> 79 #endif 80 #if HAVE_NETINET_IN_SYSTM_H 81 #include <netinet/in_systm.h> 82 #endif 83 #if HAVE_NETINET_IP_H 84 #include <netinet/ip.h> /* superset of previous */ 85 #endif 86 #include <arpa/inet.h> 87 #include <netinet/tcp.h> 88 #include <pwd.h> 89 #include <sys/ioctl.h> 90 #include <sys/wait.h> 91 #include <grp.h> 92 93 #include <string.h> 94 #include <stdio.h> 95 #include <stdlib.h> 96 #include <stdint.h> 97 #include <stdarg.h> 98 #include <stdbool.h> 99 #include <errno.h> 100 #include <signal.h> 101 #include <libgen.h> 102 #ifdef HAVE_MALLOC_H 103 #include <malloc.h> /* for mallinfo on GNU */ 104 #endif 105 #include <unistd.h> /* KLB_FIX */ 106 #include <sys/stat.h> 107 #include <sys/types.h> 108 #include <dirent.h> /* KLB_FIX */ 109 #include <fcntl.h> 110 #include <math.h> 111 #if HAVE_SYS_PARAM_H 112 #include <sys/param.h> 113 #endif 114 #if HAVE_SYS_TIME_H 115 #include <sys/time.h> 116 #endif 117 #include <time.h> 118 #ifdef BSD 119 #include <net/if.h> 120 #endif 121 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) 122 #include <semaphore.h> 123 #endif 124 #ifdef DARWIN 125 #include <dlfcn.h> 126 #include <semaphore.h> 127 #include <net/if.h> 128 #include <xlocale.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 <locale.h> 174 #include <sys/mman.h> 175 176 /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */ 177 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) 178 #define __BYTE_ORDER BYTE_ORDER 179 #define __BIG_ENDIAN BIG_ENDIAN 180 #endif 181 182 #ifdef DARWIN 183 #define __BYTE_ORDER BYTE_ORDER 184 #define __BIG_ENDIAN BIG_ENDIAN 185 /* not available on darwin, override configure */ 186 #undef HAVE_STAT64 187 #undef HAVE_MREMAP 188 #endif 189 190 #if ! HAVE_ATOLL 191 long long 192 atoll (const char *nptr); 193 194 #endif 195 196 #if ENABLE_NLS 197 #include "langinfo.h" 198 #endif 199 200 #ifndef SIZE_MAX 201 #define SIZE_MAX ((size_t) (-1)) 202 #endif 203 204 #ifndef O_LARGEFILE 205 #define O_LARGEFILE 0 206 #endif 207 208 /** 209 * AI_NUMERICSERV not defined in windows. Then we just do without. 210 */ 211 #ifndef AI_NUMERICSERV 212 #define AI_NUMERICSERV 0 213 #endif 214 215 216 #if defined(__sparc__) 217 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \ 218 sizeof((val))); \ 219 __tmp; }) 220 #else 221 #define MAKE_UNALIGNED(val) val 222 #endif 223 224 /** 225 * The termination signal 226 */ 227 #define GNUNET_TERM_SIG SIGTERM 228 229 230 #ifndef PATH_MAX 231 /** 232 * Assumed maximum path length. 233 */ 234 #define PATH_MAX 4096 235 #endif 236 237 #if HAVE_THREAD_LOCAL_GCC 238 #define GNUNET_THREAD_LOCAL __thread 239 #else 240 #define GNUNET_THREAD_LOCAL 241 #endif 242 243 244 /* LSB-style exit status codes */ 245 #ifndef EXIT_INVALIDARGUMENT 246 #define EXIT_INVALIDARGUMENT 2 247 #endif 248 249 #ifndef EXIT_NOTIMPLEMENTED 250 #define EXIT_NOTIMPLEMENTED 3 251 #endif 252 253 #ifndef EXIT_NOPERMISSION 254 #define EXIT_NOPERMISSION 4 255 #endif 256 257 #ifndef EXIT_NOTINSTALLED 258 #define EXIT_NOTINSTALLED 5 259 #endif 260 261 #ifndef EXIT_NOTCONFIGURED 262 #define EXIT_NOTCONFIGURED 6 263 #endif 264 265 #ifndef EXIT_NOTRUNNING 266 #define EXIT_NOTRUNNING 7 267 #endif 268 269 #ifndef EXIT_NO_RESTART 270 #define EXIT_NO_RESTART 9 271 #endif 272 273 /** 274 * clang et al do not have such an attribute 275 */ 276 #if __has_attribute (__nonstring__) 277 # define __nonstring __attribute__((__nonstring__)) 278 #else 279 # define __nonstring 280 #endif 281 282 #endif