platform.h (6434B)
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 39 #if (GNUNET_EXTRA_LOGGING >= 1) 40 #define VERBOSE(cmd) cmd 41 #else 42 #define VERBOSE(cmd) do { break; } while (0) 43 #endif 44 45 /* Include the features available for GNU source */ 46 #define _GNU_SOURCE 47 48 /* Do not use shortcuts for gcrypt mpi */ 49 #define GCRYPT_NO_MPI_MACROS 1 50 51 /* Do not use deprecated functions from gcrypt */ 52 #define GCRYPT_NO_DEPRECATED 1 53 54 /* Ignore MHD deprecations for now as we want to be compatible 55 to "ancient" MHD releases. */ 56 #define MHD_NO_DEPRECATION 1 57 58 /* Enable additional sanity checks that may result in a moderate 59 loss of performance but could be helpful to spot bugs. This 60 option should be enabled unless we are running benchmarks and/or 61 really need the last bit of performance. So even in production, 62 the default should be 'on' unless it was established that this 63 is needed for performance reasons. */ 64 #define ENABLE_SANITY_CHECKS 1 65 66 67 #include <netdb.h> 68 #include <sys/socket.h> 69 #include <sys/un.h> 70 #if HAVE_NETINET_IN_H 71 #include <netinet/in.h> 72 #endif 73 #if HAVE_NETINET_IN_SYSTM_H 74 #include <netinet/in_systm.h> 75 #endif 76 #if HAVE_NETINET_IP_H 77 #include <netinet/ip.h> /* superset of previous */ 78 #endif 79 #include <arpa/inet.h> 80 #include <netinet/tcp.h> 81 #include <pwd.h> 82 #include <sys/ioctl.h> 83 #include <sys/wait.h> 84 #include <grp.h> 85 86 #include <string.h> 87 #include <stdio.h> 88 #include <stdlib.h> 89 #include <stdint.h> 90 #include <stdarg.h> 91 #include <stdbool.h> 92 #include <errno.h> 93 #include <signal.h> 94 #include <libgen.h> 95 #ifdef HAVE_MALLOC_H 96 #include <malloc.h> /* for mallinfo on GNU */ 97 #endif 98 #include <unistd.h> /* KLB_FIX */ 99 #include <sys/stat.h> 100 #include <sys/types.h> 101 #include <dirent.h> /* KLB_FIX */ 102 #include <fcntl.h> 103 #include <math.h> 104 #if HAVE_SYS_PARAM_H 105 #include <sys/param.h> 106 #endif 107 #if HAVE_SYS_TIME_H 108 #include <sys/time.h> 109 #endif 110 #include <time.h> 111 #ifdef BSD 112 #include <net/if.h> 113 #endif 114 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) 115 #include <semaphore.h> 116 #endif 117 #ifdef DARWIN 118 #include <dlfcn.h> 119 #include <semaphore.h> 120 #include <net/if.h> 121 #endif 122 #if defined(__linux__) || defined(GNU) 123 #include <net/if.h> 124 #endif 125 #ifdef SOLARIS 126 #include <sys/sockio.h> 127 #include <sys/filio.h> 128 #include <sys/loadavg.h> 129 #include <semaphore.h> 130 #endif 131 #if HAVE_UCRED_H 132 #include <ucred.h> 133 #endif 134 #if HAVE_SYS_UCRED_H 135 #include <sys/ucred.h> 136 #endif 137 #if HAVE_IFADDRS_H 138 #include <ifaddrs.h> 139 #endif 140 #include <errno.h> 141 #include <limits.h> 142 143 #if HAVE_VFORK_H 144 #include <vfork.h> 145 #endif 146 147 #include <ctype.h> 148 #if HAVE_SYS_RESOURCE_H 149 #include <sys/resource.h> 150 #endif 151 152 #if HAVE_ENDIAN_H 153 #include <endian.h> 154 #endif 155 #if HAVE_SYS_ENDIAN_H 156 #include <sys/endian.h> 157 #endif 158 159 #define DIR_SEPARATOR '/' 160 #define DIR_SEPARATOR_STR "/" 161 #define PATH_SEPARATOR ':' 162 #define PATH_SEPARATOR_STR ":" 163 #define NEWLINE "\n" 164 165 166 #include <locale.h> 167 #include "gettext.h" 168 /** 169 * GNU gettext support macro. 170 */ 171 #define _(String) dgettext (PACKAGE, String) 172 173 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 #if defined(__sparc__) 210 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \ 211 sizeof((val))); \ 212 __tmp; }) 213 #else 214 #define MAKE_UNALIGNED(val) val 215 #endif 216 217 218 #ifndef PATH_MAX 219 /** 220 * Assumed maximum path length. 221 */ 222 #define PATH_MAX 4096 223 #endif 224 225 #if HAVE_THREAD_LOCAL_GCC 226 #define TALER_THREAD_LOCAL __thread 227 #else 228 #define TALER_THREAD_LOCAL 229 #endif 230 231 232 /* LSB-style exit status codes */ 233 #ifndef EXIT_INVALIDARGUMENT 234 /** 235 * Command-line arguments are invalid. 236 * Restarting useless. 237 */ 238 #define EXIT_INVALIDARGUMENT 2 239 #endif 240 241 #ifndef EXIT_NOTIMPLEMENTED 242 /** 243 * The requested operation is not implemented. 244 * Restarting useless. 245 */ 246 #define EXIT_NOTIMPLEMENTED 3 247 #endif 248 249 #ifndef EXIT_NOPERMISSION 250 /** 251 * Permissions needed to run are not available. 252 * Restarting useless. 253 */ 254 #define EXIT_NOPERMISSION 4 255 #endif 256 257 #ifndef EXIT_NOTINSTALLED 258 /** 259 * Key resources are not installed. 260 * Restarting useless. 261 */ 262 #define EXIT_NOTINSTALLED 5 263 #endif 264 265 #ifndef EXIT_NOTCONFIGURED 266 /** 267 * Key configuration settings are missing or invalid. 268 * Restarting useless. 269 */ 270 #define EXIT_NOTCONFIGURED 6 271 #endif 272 273 #ifndef EXIT_NOTRUNNING 274 #define EXIT_NOTRUNNING 7 275 #endif 276 277 278 #ifndef EXIT_NO_RESTART 279 /** 280 * Exit code from 'main' if we do not want to be restarted, 281 * except by manual intervention (hard failure). 282 */ 283 #define EXIT_NO_RESTART 9 284 #endif 285 286 287 /** 288 * clang et al do not have such an attribute 289 */ 290 #if __has_attribute (__nonstring__) 291 # define __nonstring __attribute__((__nonstring__)) 292 #else 293 # define __nonstring 294 #endif 295 296 297 #endif /* PLATFORM_H_ */ 298 299 /* end of platform.h */