anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

platform.h (6056B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2014, 2015, 2016, 2021 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis 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 Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   Anastasis; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 
     17 /**
     18  * @file anastasis/src/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 
     24 #ifndef PLATFORM_H_
     25 #define PLATFORM_H_
     26 
     27 /* Include our configuration header */
     28 #ifndef HAVE_USED_CONFIG_H
     29 #define HAVE_USED_CONFIG_H
     30 #ifdef HAVE_CONFIG_H
     31 #include "anastasis_config.h"
     32 #endif
     33 #endif
     34 
     35 
     36 #if (GNUNET_EXTRA_LOGGING >= 1)
     37 #define VERBOSE(cmd) cmd
     38 #else
     39 #define VERBOSE(cmd) do { break; } while (0)
     40 #endif
     41 
     42 
     43 /* LSB-style exit status codes */
     44 #ifndef EXIT_INVALIDARGUMENT
     45 #define EXIT_INVALIDARGUMENT 2
     46 #endif
     47 
     48 #ifndef EXIT_NOTIMPLEMENTED
     49 #define EXIT_NOTIMPLEMENTED 3
     50 #endif
     51 
     52 #ifndef EXIT_NOPERMISSION
     53 #define EXIT_NOPERMISSION 4
     54 #endif
     55 
     56 #ifndef EXIT_NOTINSTALLED
     57 #define EXIT_NOTINSTALLED 5
     58 #endif
     59 
     60 #ifndef EXIT_NOTCONFIGURED
     61 #define EXIT_NOTCONFIGURED 6
     62 #endif
     63 
     64 #ifndef EXIT_NOTRUNNING
     65 #define EXIT_NOTRUNNING 7
     66 #endif
     67 
     68 #ifndef EXIT_NO_RESTART
     69 /**
     70  * Exit code from 'main' if we do not want to be restarted,
     71  * except by manual intervention (hard failure).
     72  */
     73 #define EXIT_NO_RESTART 9
     74 #endif
     75 
     76 
     77 /* Include the features available for GNU source */
     78 #define _GNU_SOURCE
     79 
     80 
     81 #ifdef HAVE_SYS_TYPES_H
     82 #include <sys/types.h>
     83 #endif
     84 
     85 #ifdef __clang__
     86 #undef HAVE_STATIC_ASSERT
     87 #endif
     88 
     89 /**
     90  * These may be expensive, but good for debugging...
     91  */
     92 #define ALLOW_EXTRA_CHECKS GNUNET_YES
     93 
     94 /**
     95  * For strptime (glibc2 needs this).
     96  */
     97 #ifndef _XOPEN_SOURCE
     98 #define _XOPEN_SOURCE 499
     99 #endif
    100 
    101 #ifndef _REENTRANT
    102 #define _REENTRANT
    103 #endif
    104 
    105 /* configuration options */
    106 
    107 #define VERBOSE_STATS 0
    108 
    109 #include <netdb.h>
    110 #include <sys/socket.h>
    111 #include <sys/un.h>
    112 #if HAVE_NETINET_IN_H
    113 #include <netinet/in.h>
    114 #endif
    115 #if HAVE_NETINET_IN_SYSTM_H
    116 #include <netinet/in_systm.h>
    117 #endif
    118 #if HAVE_NETINET_IP_H
    119 #include <netinet/ip.h>         /* superset of previous */
    120 #endif
    121 #include <arpa/inet.h>
    122 #include <netinet/tcp.h>
    123 #include <pwd.h>
    124 #include <sys/ioctl.h>
    125 #include <sys/wait.h>
    126 #include <grp.h>
    127 
    128 #include <string.h>
    129 #include <stdio.h>
    130 #include <stdlib.h>
    131 #include <stdint.h>
    132 #include <stdarg.h>
    133 #include <stdbool.h>
    134 #include <errno.h>
    135 #include <signal.h>
    136 #include <libgen.h>
    137 #ifdef HAVE_MALLOC_H
    138 #include <malloc.h>             /* for mallinfo on GNU */
    139 #endif
    140 #include <unistd.h>             /* KLB_FIX */
    141 #include <sys/stat.h>
    142 #include <sys/types.h>
    143 #include <dirent.h>             /* KLB_FIX */
    144 #include <fcntl.h>
    145 #include <math.h>
    146 #if HAVE_SYS_PARAM_H
    147 #include <sys/param.h>
    148 #endif
    149 #if HAVE_SYS_TIME_H
    150 #include <sys/time.h>
    151 #endif
    152 #include <time.h>
    153 #ifdef BSD
    154 #include <net/if.h>
    155 #endif
    156 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
    157 #include <semaphore.h>
    158 #endif
    159 #ifdef DARWIN
    160 #include <dlfcn.h>
    161 #include <semaphore.h>
    162 #include <net/if.h>
    163 #endif
    164 #if defined(__linux__) || defined(GNU)
    165 #include <net/if.h>
    166 #endif
    167 #ifdef SOLARIS
    168 #include <sys/sockio.h>
    169 #include <sys/filio.h>
    170 #include <sys/loadavg.h>
    171 #include <semaphore.h>
    172 #endif
    173 #if HAVE_UCRED_H
    174 #include <ucred.h>
    175 #endif
    176 #if HAVE_SYS_UCRED_H
    177 #include <sys/ucred.h>
    178 #endif
    179 #if HAVE_IFADDRS_H
    180 #include <ifaddrs.h>
    181 #endif
    182 #include <errno.h>
    183 #include <limits.h>
    184 
    185 #if HAVE_VFORK_H
    186 #include <vfork.h>
    187 #endif
    188 
    189 #include <ctype.h>
    190 #if HAVE_SYS_RESOURCE_H
    191 #include <sys/resource.h>
    192 #endif
    193 
    194 #if HAVE_ENDIAN_H
    195 #include <endian.h>
    196 #endif
    197 #if HAVE_SYS_ENDIAN_H
    198 #include <sys/endian.h>
    199 #endif
    200 
    201 #define DIR_SEPARATOR '/'
    202 #define DIR_SEPARATOR_STR "/"
    203 #define PATH_SEPARATOR ':'
    204 #define PATH_SEPARATOR_STR ":"
    205 #define NEWLINE "\n"
    206 
    207 #include <locale.h>
    208 #include "gettext.h"
    209 /**
    210  * GNU gettext support macro.
    211  */
    212 #define _(String) dgettext (PACKAGE, String)
    213 #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
    214 
    215 #include <sys/mman.h>
    216 
    217 /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD  */
    218 #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
    219 #define __BYTE_ORDER BYTE_ORDER
    220 #define __BIG_ENDIAN BIG_ENDIAN
    221 #endif
    222 
    223 #ifdef DARWIN
    224 #define __BYTE_ORDER BYTE_ORDER
    225 #define __BIG_ENDIAN BIG_ENDIAN
    226 /* not available on darwin, override configure */
    227 #undef HAVE_STAT64
    228 #undef HAVE_MREMAP
    229 #endif
    230 
    231 #if ! HAVE_ATOLL
    232 long long
    233 atoll (const char *nptr);
    234 
    235 #endif
    236 
    237 #if ENABLE_NLS
    238 #include "langinfo.h"
    239 #endif
    240 
    241 #ifndef SIZE_MAX
    242 #define SIZE_MAX ((size_t) (-1))
    243 #endif
    244 
    245 #ifndef O_LARGEFILE
    246 #define O_LARGEFILE 0
    247 #endif
    248 
    249 /**
    250  * AI_NUMERICSERV not defined in windows.  Then we just do without.
    251  */
    252 #ifndef AI_NUMERICSERV
    253 #define AI_NUMERICSERV 0
    254 #endif
    255 
    256 
    257 #if defined(__sparc__)
    258 #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
    259                                                                  sizeof((val))); \
    260                                __tmp; })
    261 #else
    262 #define MAKE_UNALIGNED(val) val
    263 #endif
    264 
    265 /**
    266  * The termination signal
    267  */
    268 #define GNUNET_TERM_SIG SIGTERM
    269 
    270 
    271 #ifndef PATH_MAX
    272 /**
    273  * Assumed maximum path length.
    274  */
    275 #define PATH_MAX 4096
    276 #endif
    277 
    278 #if HAVE_THREAD_LOCAL_GCC
    279 #define ANASTASIS_THREAD_LOCAL __thread
    280 #else
    281 #define ANASTASIS_THREAD_LOCAL
    282 #endif
    283 
    284 
    285 /* Do not use shortcuts for gcrypt mpi */
    286 #define GCRYPT_NO_MPI_MACROS 1
    287 
    288 /* Do not use deprecated functions from gcrypt */
    289 #define GCRYPT_NO_DEPRECATED 1
    290 
    291 /* Ignore MHD deprecations for now as we want to be compatible
    292    to "ancient" MHD releases. */
    293 #define MHD_NO_DEPRECATION 1
    294 
    295 #endif  /* PLATFORM_H_ */
    296 
    297 /* end of platform.h */