platform.h (6537B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014 Chrisitan Grothoff (and other contributing authors) 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 /** 18 * @file include/platform.h 19 * @brief This file contains the includes and definitions which are used by the 20 * rest of the modules 21 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 22 */ 23 #ifndef PLATFORM_H_ 24 #define PLATFORM_H_ 25 26 /* Include our configuration header */ 27 #ifndef HAVE_USED_CONFIG_H 28 #define HAVE_USED_CONFIG_H 29 #ifdef HAVE_CONFIG_H 30 #include "taler_config.h" 31 #endif 32 #endif 33 34 /* For the exchange build, we do NOT want gettext, even 35 if it is available! */ 36 #undef ENABLE_NLS 37 38 #if HAVE_THREAD_LOCAL_GCC 39 #define TALER_THREAD_LOCAL __thread 40 #else 41 #define TALER_THREAD_LOCAL 42 #endif 43 44 45 #if (GNUNET_EXTRA_LOGGING >= 1) 46 #define VERBOSE(cmd) cmd 47 #else 48 #define VERBOSE(cmd) do { break; } while (0) 49 #endif 50 51 /* Include the features available for GNU source */ 52 #define _GNU_SOURCE 53 54 /* Do not use shortcuts for gcrypt mpi */ 55 #define GCRYPT_NO_MPI_MACROS 1 56 57 /* Do not use deprecated functions from gcrypt */ 58 #define GCRYPT_NO_DEPRECATED 1 59 60 /* Ignore MHD deprecations for now as we want to be compatible 61 to "ancient" MHD releases. */ 62 #define MHD_NO_DEPRECATION 1 63 64 /* Enable additional sanity checks that may result in a moderate 65 loss of performance but could be helpful to spot bugs. This 66 option should be enabled unless we are running benchmarks and/or 67 really need the last bit of performance. So even in production, 68 the default should be 'on' unless it was established that this 69 is needed for performance reasons. */ 70 #define ENABLE_SANITY_CHECKS 1 71 72 73 #include <netdb.h> 74 #include <sys/socket.h> 75 #include <sys/un.h> 76 #if HAVE_NETINET_IN_H 77 #include <netinet/in.h> 78 #endif 79 #if HAVE_NETINET_IN_SYSTM_H 80 #include <netinet/in_systm.h> 81 #endif 82 #if HAVE_NETINET_IP_H 83 #include <netinet/ip.h> /* superset of previous */ 84 #endif 85 #include <arpa/inet.h> 86 #include <netinet/tcp.h> 87 #include <pwd.h> 88 #include <sys/ioctl.h> 89 #include <sys/wait.h> 90 #include <grp.h> 91 92 #include <string.h> 93 #include <stdio.h> 94 #include <stdlib.h> 95 #include <stdint.h> 96 #include <stdarg.h> 97 #include <stdbool.h> 98 #include <errno.h> 99 #include <signal.h> 100 #include <libgen.h> 101 #ifdef HAVE_MALLOC_H 102 #include <malloc.h> /* for mallinfo on GNU */ 103 #endif 104 #include <unistd.h> /* KLB_FIX */ 105 #include <sys/stat.h> 106 #include <sys/types.h> 107 #include <dirent.h> /* KLB_FIX */ 108 #include <fcntl.h> 109 #include <math.h> 110 #if HAVE_SYS_PARAM_H 111 #include <sys/param.h> 112 #endif 113 #if HAVE_SYS_TIME_H 114 #include <sys/time.h> 115 #endif 116 #include <time.h> 117 #ifdef BSD 118 #include <net/if.h> 119 #endif 120 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) 121 #include <semaphore.h> 122 #endif 123 #ifdef DARWIN 124 #include <dlfcn.h> 125 #include <semaphore.h> 126 #include <net/if.h> 127 #endif 128 #if defined(__linux__) || defined(GNU) 129 #include <net/if.h> 130 #endif 131 #ifdef SOLARIS 132 #include <sys/sockio.h> 133 #include <sys/filio.h> 134 #include <sys/loadavg.h> 135 #include <semaphore.h> 136 #endif 137 #if HAVE_UCRED_H 138 #include <ucred.h> 139 #endif 140 #if HAVE_SYS_UCRED_H 141 #include <sys/ucred.h> 142 #endif 143 #if HAVE_IFADDRS_H 144 #include <ifaddrs.h> 145 #endif 146 #include <errno.h> 147 #include <limits.h> 148 149 #if HAVE_VFORK_H 150 #include <vfork.h> 151 #endif 152 153 #include <ctype.h> 154 #if HAVE_SYS_RESOURCE_H 155 #include <sys/resource.h> 156 #endif 157 158 #if HAVE_ENDIAN_H 159 #include <endian.h> 160 #endif 161 #if HAVE_SYS_ENDIAN_H 162 #include <sys/endian.h> 163 #endif 164 165 #define DIR_SEPARATOR '/' 166 #define DIR_SEPARATOR_STR "/" 167 #define PATH_SEPARATOR ':' 168 #define PATH_SEPARATOR_STR ":" 169 #define NEWLINE "\n" 170 171 172 #include <locale.h> 173 #include "gettext.h" 174 /** 175 * GNU gettext support macro. 176 */ 177 #define _(String) dgettext (PACKAGE, String) 178 179 180 #include <sys/mman.h> 181 182 /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */ 183 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) 184 #define __BYTE_ORDER BYTE_ORDER 185 #define __BIG_ENDIAN BIG_ENDIAN 186 #endif 187 188 #ifdef DARWIN 189 #define __BYTE_ORDER BYTE_ORDER 190 #define __BIG_ENDIAN BIG_ENDIAN 191 /* not available on darwin, override configure */ 192 #undef HAVE_STAT64 193 #undef HAVE_MREMAP 194 #endif 195 196 #if ! HAVE_ATOLL 197 long long 198 atoll (const char *nptr); 199 200 #endif 201 202 #if ENABLE_NLS 203 #include "langinfo.h" 204 #endif 205 206 #ifndef SIZE_MAX 207 #define SIZE_MAX ((size_t) (-1)) 208 #endif 209 210 #ifndef O_LARGEFILE 211 #define O_LARGEFILE 0 212 #endif 213 214 215 #if defined(__sparc__) 216 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \ 217 sizeof((val))); \ 218 __tmp; }) 219 #else 220 #define MAKE_UNALIGNED(val) val 221 #endif 222 223 224 #ifndef PATH_MAX 225 /** 226 * Assumed maximum path length. 227 */ 228 #define PATH_MAX 4096 229 #endif 230 231 #if HAVE_THREAD_LOCAL_GCC 232 #define TALER_THREAD_LOCAL __thread 233 #else 234 #define TALER_THREAD_LOCAL 235 #endif 236 237 238 /* LSB-style exit status codes */ 239 #ifndef EXIT_INVALIDARGUMENT 240 /** 241 * Command-line arguments are invalid. 242 * Restarting useless. 243 */ 244 #define EXIT_INVALIDARGUMENT 2 245 #endif 246 247 #ifndef EXIT_NOTIMPLEMENTED 248 /** 249 * The requested operation is not implemented. 250 * Restarting useless. 251 */ 252 #define EXIT_NOTIMPLEMENTED 3 253 #endif 254 255 #ifndef EXIT_NOPERMISSION 256 /** 257 * Permissions needed to run are not available. 258 * Restarting useless. 259 */ 260 #define EXIT_NOPERMISSION 4 261 #endif 262 263 #ifndef EXIT_NOTINSTALLED 264 /** 265 * Key resources are not installed. 266 * Restarting useless. 267 */ 268 #define EXIT_NOTINSTALLED 5 269 #endif 270 271 #ifndef EXIT_NOTCONFIGURED 272 /** 273 * Key configuration settings are missing or invalid. 274 * Restarting useless. 275 */ 276 #define EXIT_NOTCONFIGURED 6 277 #endif 278 279 #ifndef EXIT_NOTRUNNING 280 #define EXIT_NOTRUNNING 7 281 #endif 282 283 284 #ifndef EXIT_NO_RESTART 285 /** 286 * Exit code from 'main' if we do not want to be restarted, 287 * except by manual intervention (hard failure). 288 */ 289 #define EXIT_NO_RESTART 9 290 #endif 291 292 293 /** 294 * clang et al do not have such an attribute 295 */ 296 #if __has_attribute (__nonstring__) 297 # define __nonstring __attribute__((__nonstring__)) 298 #else 299 # define __nonstring 300 #endif 301 302 303 #endif /* PLATFORM_H_ */ 304 305 /* end of platform.h */