libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

microhttpd2_portability.h (32495B)


      1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
      2 /*
      3   This file is part of GNU libmicrohttpd.
      4   Copyright (C) 2024 Evgeny Grin (Karlson2k)
      5 
      6   GNU libmicrohttpd is free software; you can redistribute it and/or
      7   modify it under the terms of the GNU Lesser General Public
      8   License as published by the Free Software Foundation; either
      9   version 2.1 of the License, or (at your option) any later version.
     10 
     11   GNU libmicrohttpd is distributed in the hope that it will be useful,
     12   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14   Lesser General Public License for more details.
     15 
     16   Alternatively, you can redistribute GNU libmicrohttpd and/or
     17   modify it under the terms of the GNU General Public License as
     18   published by the Free Software Foundation; either version 2 of
     19   the License, or (at your option) any later version, together
     20   with the eCos exception, as follows:
     21 
     22     As a special exception, if other files instantiate templates or
     23     use macros or inline functions from this file, or you compile this
     24     file and link it with other works to produce a work based on this
     25     file, this file does not by itself cause the resulting work to be
     26     covered by the GNU General Public License. However the source code
     27     for this file must still be made available in accordance with
     28     section (3) of the GNU General Public License v2.
     29 
     30     This exception does not invalidate any other reasons why a work
     31     based on this file might be covered by the GNU General Public
     32     License.
     33 
     34   You should have received copies of the GNU Lesser General Public
     35   License and the GNU General Public License along with this library;
     36   if not, see <https://www.gnu.org/licenses/>.
     37 */
     38 
     39 #ifndef MICROHTTPD2_PORTABILITY_H
     40 #define MICROHTTPD2_PORTABILITY_H 1
     41 
     42 #ifndef __cplusplus
     43 #  define MHD_STATIC_CAST_(type, value) \
     44           ((type) (value))
     45 #else
     46 #  define MHD_STATIC_CAST_(type, value) \
     47           (static_cast<type>(value))
     48 #endif
     49 
     50 /**
     51  * Constant used to indicate that options array is limited by zero-termination
     52  */
     53 #define MHD_OPTIONS_ARRAY_MAX_SIZE \
     54         MHD_STATIC_CAST_ (size_t,~MHD_STATIC_CAST_(size_t, 0))
     55 
     56 
     57 /* Define MHD_W32DLL when using MHD as W32 .DLL to speed up linker a little */
     58 #ifndef MHD_EXTERN_
     59 #  if !defined(_WIN32) || !defined(MHD_W32LIB)
     60 #    define MHD_EXTERN_ extern
     61 #  else /* defined(_WIN32) && defined(MHD_W32LIB) */
     62 #    define MHD_EXTERN_ extern __declspec(dllimport)
     63 #  endif
     64 #endif
     65 
     66 
     67 /* Compiler macros for internal needs */
     68 
     69 /* Stringify macro parameter literally */
     70 #define MHD_MACRO_STR__(x) #x
     71 /* Stringify macro parameter after expansion */
     72 #define MHD_MACRO_STR_(x) MHD_MACRO_STR__ (x)
     73 
     74 /* Concatenate macro parameters literally */
     75 #define MHD_MACRO_CAT__(a, b) a ## b
     76 /* Concatenate macro parameters after expansion */
     77 #define MHD_MACRO_CAT_(a, b) MHD_MACRO_CAT__ (a,b)
     78 
     79 #ifdef __GNUC__
     80 #  define MHD_GNUC_MINV(major, minor)    \
     81           ((__GNUC__ > (major)) ||           \
     82            ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor + 0))))
     83 #else  /* ! __GNUC__ */
     84 #  define MHD_GNUC_MINV(major, minor) (0)
     85 #endif /* ! __GNUC__ */
     86 
     87 #ifdef __clang__
     88 #  define MHD_CLANG_MINV(major, minor)    \
     89           ((__clang_major__ > (major)) ||           \
     90            ((__clang_major__ == (major)) && (__clang_minor__ >= (minor + 0))))
     91 #else  /* ! __GNUC__ */
     92 #  define MHD_CLANG_MINV(major, minor) (0)
     93 #endif /* ! __GNUC__ */
     94 
     95 #if defined(_MSC_FULL_VER)
     96 #  define MHD_MSC_MINV(version) (_MSC_VER >= (version + 0))
     97 #  if defined(_MSC_FULL_VER) \
     98   && (!defined(__STDC__) || defined(_MSC_EXTENSIONS))
     99 /* Visual C with extensions */
    100 #    define MHD_HAS_MSC_EXTENSION 1
    101 #  endif
    102 #else  /* ! _MSC_FULL_VER */
    103 #  define MHD_MSC_MINV(version) (0)
    104 #endif /* ! _MSC_FULL_VER */
    105 
    106 #if defined(__STDC_VERSION__) && !defined(__cplusplus)
    107 #  define MHD_C_MINV(version)   (__STDC_VERSION__ >= (version))
    108 #else
    109 #  define MHD_C_MINV(version)   (0)
    110 #endif
    111 
    112 #define MHD_C_MINV_99     MHD_C_MINV (199901)
    113 #define MHD_C_MINV_11     MHD_C_MINV (201112)
    114 #define MHD_C_MINV_23     MHD_C_MINV (202311)
    115 
    116 
    117 #ifndef __cplusplus
    118 #  define MHD_CXX_MINV(version) (0)
    119 #elif !defined(_MSC_FULL_VER) || !defined(_MSVC_LANG)
    120 #  define MHD_CXX_MINV(version) ((__cplusplus + 0) >= version)
    121 #else
    122 #  define MHD_CXX_MINV(version) \
    123           ((__cplusplus + 0) >= version) || ((_MSVC_LANG + 0) >= version)
    124 #endif
    125 
    126 /* Use compound literals? */
    127 #if !defined(MHD_NO_COMPOUND_LITERALS)
    128 #  if !defined(MHD_USE_COMPOUND_LITERALS)
    129 #    if MHD_C_MINV_99
    130 #      define MHD_USE_COMPOUND_LITERALS   1
    131 #    elif MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__)
    132 /* This may warn in "pedantic" compilation mode */
    133 #      define MHD_USE_COMPOUND_LITERALS   1
    134 /* Compound literals are an extension */
    135 #      define MHD_USE_COMPOUND_LITERALS_EXT     1
    136 #    elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1800) \
    137   && !defined(__cplusplus)
    138 #      define MHD_USE_COMPOUND_LITERALS   1
    139 /* Compound literals are an extension */
    140 #      define MHD_USE_COMPOUND_LITERALS_EXT     1
    141 #    else
    142 /* Compound literals are not supported */
    143 #      define MHD_NO_COMPOUND_LITERALS    1
    144 #    endif
    145 #  endif /* !MHD_USE_COMPOUND_LITERALS */
    146 #elif defined(MHD_USE_COMPOUND_LITERALS)
    147 #  error MHD_USE_COMPOUND_LITERALS and MHD_NO_COMPOUND_LITERALS are both defined
    148 #endif /* MHD_NO_COMPOUND_LITERALS */
    149 
    150 /* Use compound literals array as function parameter? */
    151 #if defined(MHD_USE_COMPOUND_LITERALS)
    152 #  if !defined(MHD_NO_COMP_LIT_FUNC_PARAMS)
    153 #    if !defined(MHD_USE_COMP_LIT_FUNC_PARAMS)
    154 #      if !defined(__cplusplus)
    155 /* Compound literals are lvalues and their addresses can be taken */
    156 #        define MHD_USE_COMP_LIT_FUNC_PARAMS    1
    157 #      elif defined(__llvm__)
    158 /* clang and LLVM-based compilers treat compound literals as lvalue */
    159 #        define MHD_USE_COMP_LIT_FUNC_PARAMS    1
    160 #      else
    161 /* Compound literals array cannot be used as function parameter */
    162 #        define MHD_NO_COMP_LIT_FUNC_PARAMS     1
    163 #      endif
    164 #    endif
    165 #  elif defined(MHD_USE_COMP_LIT_FUNC_PARAMS)
    166 #    error MHD_USE_COMP_LIT_FUNC_PARAMS and opposite macro are both defined
    167 #  endif
    168 #else  /* ! MHD_USE_COMPOUND_LITERALS */
    169 #  ifndef MHD_NO_COMP_LIT_FUNC_PARAMS
    170 /* Compound literals array cannot be used as function parameter */
    171 #    define MHD_NO_COMP_LIT_FUNC_PARAMS 1
    172 #  endif
    173 #  ifdef MHD_USE_COMP_LIT_FUNC_PARAMS
    174 #    undef MHD_USE_COMP_LIT_FUNC_PARAMS
    175 #  endif
    176 #endif /* ! MHD_USE_COMPOUND_LITERALS */
    177 
    178 /* Use designated initializers? */
    179 #if !defined(MHD_NO_DESIGNATED_INIT)
    180 #  if !defined(MHD_USE_DESIGNATED_INIT)
    181 #    if MHD_C_MINV_99
    182 #      define MHD_USE_DESIGNATED_INIT   1
    183 #    elif defined(__cplusplus) && defined(__cpp_designated_initializers)
    184 #      define MHD_USE_DESIGNATED_INIT   1
    185 #    elif (MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__) \
    186   && !defined(__cplusplus)) \
    187   || (defined(__GNUG__) && MHD_GNUC_MINV (4, 7))
    188 /* This may warn in "pedantic" compilation mode */
    189 #      define MHD_USE_DESIGNATED_INIT   1
    190 /* Designated initializers are an extension */
    191 #      define MHD_USE_DESIGNATED_INIT_EXT       1
    192 #    elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1800)
    193 #      define MHD_USE_DESIGNATED_INIT   1
    194 /* Designated initializers are an extension */
    195 #      define MHD_USE_DESIGNATED_INIT_EXT       1
    196 #    else
    197 /* Designated initializers are not supported */
    198 #      define MHD_NO_DESIGNATED_INIT    1
    199 #    endif
    200 #  endif /* !MHD_USE_DESIGNATED_INIT */
    201 #elif defined(MHD_USE_DESIGNATED_INIT)
    202 #  error MHD_USE_DESIGNATED_INIT and MHD_NO_DESIGNATED_INIT are both defined
    203 #endif /* MHD_NO_DESIGNATED_INIT */
    204 
    205 /* Use nested designated initializers? */
    206 #if defined(MHD_USE_DESIGNATED_INIT) && !defined(__cplusplus)
    207 #  ifdef MHD_NO_DESIG_NEST_INIT
    208 #    undef MHD_NO_DESIG_NEST_INIT
    209 #  endif
    210 #  ifndef MHD_USE_DESIG_NEST_INIT
    211 #    define MHD_USE_DESIG_NEST_INIT     1
    212 #  endif
    213 #else  /* ! MHD_USE_DESIGNATED_INIT || __cplusplus */
    214 #  ifdef MHD_USE_DESIG_NEST_INIT
    215 #    undef MHD_USE_DESIG_NEST_INIT
    216 #  endif
    217 #  ifndef MHD_NO_DESIG_NEST_INIT
    218 /* Designated nested initializers are not supported */
    219 #    define MHD_NO_DESIG_NEST_INIT      1
    220 #  endif
    221 #endif /* ! MHD_USE_DESIGNATED_INIT || __cplusplus */
    222 
    223 /* Use C++ initializer lists? */
    224 #if !defined(MHD_NO_CPP_INIT_LIST)
    225 #  if !defined(MHD_USE_CPP_INIT_LIST)
    226 #    if defined(__cplusplus) && defined(__cpp_initializer_lists)
    227 #      define MHD_USE_CPP_INIT_LIST     1
    228 #    else
    229 #      define MHD_NO_CPP_INIT_LIST      1
    230 #    endif
    231 #  endif
    232 #elif defined(MHD_USE_CPP_INIT_LIST)
    233 #  error MHD_USE_CPP_INIT_LIST and MHD_NO_CPP_INIT_LIST are both defined
    234 #endif
    235 
    236 /* Use variadic arguments macros? */
    237 #if !defined(MHD_NO_VARARG_MACROS)
    238 #  if !defined(MHD_USE_VARARG_MACROS)
    239 #    if MHD_C_MINV_99
    240 #      define MHD_USE_VARARG_MACROS   1
    241 #    elif MHD_CXX_MINV (201103)
    242 #      define MHD_USE_VARARG_MACROS   1
    243 #    elif MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__)
    244 /* This may warn in "pedantic" compilation mode */
    245 #      define MHD_USE_VARARG_MACROS   1
    246 /* Variable arguments macros are an extension */
    247 #      define MHD_USE_VARARG_MACROS_EXT 1
    248 #    elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1400)
    249 #      define MHD_USE_VARARG_MACROS   1
    250 /* Variable arguments macros are an extension */
    251 #      define MHD_USE_VARARG_MACROS_EXT 1
    252 #    else
    253 /* Variable arguments macros are not supported */
    254 #      define MHD_NO_VARARG_MACROS    1
    255 #    endif
    256 #  endif /* !MHD_USE_VARARG_MACROS */
    257 #elif defined(MHD_USE_VARARG_MACROS)
    258 #  error MHD_USE_VARARG_MACROS and MHD_NO_VARARG_MACROS are both defined
    259 #endif /* MHD_NO_VARARG_MACROS */
    260 
    261 
    262 /* Use variable-length arrays? */
    263 #if !defined(MHD_NO_VLA_TYPES)
    264 #  if !defined(MHD_USE_VLA_TYPES)
    265 #    if MHD_C_MINV_23
    266 #      define MHD_USE_VLA_TYPES 1
    267 #    elif defined(__STDC_NO_VLA__)
    268 #      define MHD_NO_VLA_TYPES  1
    269 #    elif defined(_MSC_VER)
    270 #      define MHD_NO_VLA_TYPES  1
    271 #    elif MHD_C_MINV_99 && \
    272   (defined(__GNUC__) || defined(__clang__) || defined(__llvm__))
    273 #      define MHD_USE_VLA_TYPES 1
    274 #    else
    275 /* Assume 'not supported' */
    276 #      define MHD_NO_VLA_TYPES  1
    277 #    endif
    278 #  endif
    279 #elif defined(MHD_USE_VLA_TYPES)
    280 #  error MHD_USE_VLA_TYPES and MHD_NO_VLA_TYPES are both defined
    281 #endif /* MHD_NO_VARARG_MACROS */
    282 
    283 #if !defined(MHD_INLINE)
    284 #  if defined(inline)
    285 /* Assume that proper value of 'inline' was already defined */
    286 #    define MHD_INLINE inline
    287 #  elif MHD_C_MINV_99
    288 /* C99 (and later) supports 'inline' */
    289 #    define MHD_INLINE inline
    290 #  elif defined(__cplusplus)
    291 /* C++ always supports 'inline' */
    292 #    define MHD_INLINE inline
    293 #  elif MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__)
    294 #    define MHD_INLINE __inline__
    295 #  elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1400)
    296 #    define MHD_INLINE __inline
    297 #  else
    298 #    define MHD_INLINE /* empty */
    299 #  endif
    300 #endif /* MHD_INLINE */
    301 
    302 #if !defined(MHD_RESTRICT)
    303 #  if defined(restrict)
    304 /* Assume that proper value of 'restrict' was already defined */
    305 #    define MHD_RESTRICT restrict
    306 #  elif MHD_C_MINV_99
    307 /* C99 (and later) supports 'restrict' */
    308 #    define MHD_RESTRICT restrict
    309 #  elif (MHD_GNUC_MINV (3, 0) || MHD_CLANG_MINV (3, 0)) \
    310   && !defined(__STRICT_ANSI__)
    311 #    define MHD_RESTRICT __restrict__
    312 #  elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1400)
    313 #    define MHD_RESTRICT __restrict
    314 #  else
    315 #    define MHD_RESTRICT /* empty */
    316 #  endif
    317 #endif /* MHD_INLINE */
    318 
    319 
    320 #if !defined(MHD_NO__PRAGMA)
    321 #  if MHD_GNUC_MINV (4, 6) && !defined(__clang__)
    322 /* '_Pragma()' support was added in GCC 3.0.0
    323       * 'pragma push/pop' support was added in GCC 4.6.0 */
    324 #    define MHD_WARN_PUSH_ _Pragma("GCC diagnostic push")
    325 #    define MHD_WARN_POP_  _Pragma("GCC diagnostic pop")
    326 #    define MHD_WARN_IGNORE_STYLE_GCC   1
    327 #    define MHD_WARN_IGNORE_(warn) \
    328             _Pragma(MHD_MACRO_STR_(GCC diagnostic ignored warn))
    329 #    ifdef MHD_USE_VARARG_MACROS_EXT
    330 #      define MHD_NOWARN_VARIADIC_MACROS_ \
    331               MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wvariadic-macros")
    332 #      define MHD_RESTORE_WARN_VARIADIC_MACROS_ MHD_WARN_POP_
    333 #    endif
    334 #    define MHD_NOWARN_UNUSED_FUNC_ \
    335             MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wunused-function")
    336 #    define MHD_RESTORE_WARN_UNUSED_FUNC_ MHD_WARN_POP_
    337 #    if !MHD_C_MINV_99
    338 #      if MHD_GNUC_MINV (4, 8)
    339 #        define MHD_NOWARN_AGGR_DYN_INIT_ \
    340                 MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wpedantic")
    341 #        define MHD_RESTORE_WARN_AGGR_DYN_INIT_ MHD_WARN_POP_
    342 #      endif
    343 #    endif
    344 #  elif MHD_GNUC_MINV (2, 8) && !defined(__clang__)
    345 #    ifdef MHD_USE_COMPOUND_LITERALS_EXT
    346 #      define MHD_NOWARN_COMPOUND_LITERALS_     __extension__
    347 #      define MHD_RESTORE_WARN_COMPOUND_LITERALS_       /* empty */
    348 #    endif
    349 #  elif MHD_CLANG_MINV (3, 1)
    350 #    define MHD_WARN_PUSH_ _Pragma("clang diagnostic push")
    351 #    define MHD_WARN_POP_  _Pragma("clang diagnostic pop")
    352 #    define MHD_WARN_IGNORE_STYLE_GCC   1
    353 #    define MHD_WARN_IGNORE_(warn) \
    354             _Pragma(MHD_MACRO_STR_(clang diagnostic ignored warn))
    355 #    ifdef MHD_USE_VARARG_MACROS_EXT
    356 #      define MHD_NOWARN_VARIADIC_MACROS_ \
    357               MHD_WARN_PUSH_ \
    358               MHD_WARN_IGNORE_ ("-Wvariadic-macros") \
    359               MHD_WARN_IGNORE_ ("-Wc++98-compat-pedantic")
    360 #      define MHD_RESTORE_WARN_VARIADIC_MACROS_ MHD_WARN_POP_
    361 #    else  /* ! MHD_USE_VARARG_MACROS_EXT */
    362 #      define MHD_NOWARN_VARIADIC_MACROS_ \
    363               MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc++98-compat-pedantic")
    364 #      define MHD_RESTORE_WARN_VARIADIC_MACROS_ MHD_WARN_POP_
    365 #    endif
    366 #    ifdef MHD_USE_CPP_INIT_LIST
    367 #      define MHD_NOWARN_CPP_INIT_LIST_ \
    368               MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc++98-compat")
    369 #      define MHD_RESTORE_WARN_CPP_INIT_LIST_ MHD_WARN_POP_
    370 #    endif
    371 #    ifdef MHD_USE_COMPOUND_LITERALS_EXT
    372 #      define MHD_NOWARN_COMPOUND_LITERALS_ \
    373               MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc99-extensions")
    374 #      define MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_WARN_POP_
    375 #    endif
    376 #    define MHD_NOWARN_UNUSED_FUNC_ \
    377             MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wunused-function")
    378 #    define MHD_RESTORE_WARN_UNUSED_FUNC_ MHD_WARN_POP_
    379 #    if MHD_CLANG_MINV (3, 4)
    380 #      define MHD_NOWARN_AGGR_DYN_INIT_ \
    381               MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc99-extensions")
    382 #      define MHD_RESTORE_WARN_AGGR_DYN_INIT_ MHD_WARN_POP_
    383 #    endif
    384 #  elif MHD_MSC_MINV (1500)
    385 #    define MHD_WARN_PUSH_ __pragma(warning(push))
    386 #    define MHD_WARN_POP_  __pragma(warning(pop))
    387 #    define MHD_WARN_IGNORE_(warn)      __pragma(warning(disable:warn))
    388 #    define MHD_NOWARN_UNUSED_FUNC_ \
    389             MHD_WARN_PUSH_ MHD_WARN_IGNORE_ (4505) MHD_WARN_IGNORE_ (4514)
    390 #    define MHD_RESTORE_WARN_UNUSED_FUNC_ MHD_WARN_POP_
    391 #    if  (!MHD_C_MINV_99) && !defined(__cplusplus)
    392 #      define MHD_NOWARN_AGGR_DYN_INIT_ \
    393               MHD_WARN_PUSH_ MHD_WARN_IGNORE_ (4204)
    394 #      define MHD_RESTORE_WARN_AGGR_DYN_INIT_ MHD_WARN_POP_
    395 #    endif
    396 #  endif
    397 #endif /*!  MHD_NO__PRAGMA */
    398 
    399 #ifndef MHD_NOWARN_EXPRESSION_
    400 #  if MHD_GNUC_MINV (2, 8)
    401 #    define MHD_NOWARN_EXPRESSION_         __extension__
    402 /* Indicate that MHD_NOWARN_EXPRESSION macro is functional */
    403 #    define MHD_HAS_NOWARN_EXPRESSION_    1
    404 #  else
    405 #    define MHD_NOWARN_EXPRESSION_         /* empty */
    406 #  endif
    407 #endif
    408 
    409 #ifndef MHD_WARN_PUSH_
    410 #  define MHD_WARN_PUSH_        /* empty */
    411 #endif
    412 #ifndef MHD_WARN_POP_
    413 #  define MHD_WARN_POP_         /* empty */
    414 #endif
    415 #ifndef MHD_WARN_IGNORE_
    416 #  define MHD_WARN_IGNORE_(ignored)     /* empty */
    417 #endif
    418 #ifndef MHD_NOWARN_VARIADIC_MACROS_
    419 #  define MHD_NOWARN_VARIADIC_MACROS_   /* empty */
    420 #endif
    421 #ifndef MHD_RESTORE_WARN_VARIADIC_MACROS_
    422 #  define MHD_RESTORE_WARN_VARIADIC_MACROS_     /* empty */
    423 #endif
    424 #ifndef MHD_NOWARN_CPP_INIT_LIST_
    425 #  define MHD_NOWARN_CPP_INIT_LIST_     /* empty */
    426 #endif
    427 #ifndef MHD_RESTORE_WARN_CPP_INIT_LIST_
    428 #  define MHD_RESTORE_WARN_CPP_INIT_LIST_       /* empty */
    429 #endif
    430 #ifndef MHD_NOWARN_COMPOUND_LITERALS_
    431 #  define MHD_NOWARN_COMPOUND_LITERALS_ /* empty */
    432 #endif
    433 #ifndef MHD_RESTORE_WARN_COMPOUND_LITERALS_
    434 #  define MHD_RESTORE_WARN_COMPOUND_LITERALS_   /* empty */
    435 #endif
    436 #ifndef MHD_NOWARN_UNUSED_FUNC_
    437 #  define MHD_NOWARN_UNUSED_FUNC_       /* empty */
    438 #else
    439 /* Indicate that MHD_NOWARN_UNUSED_FUNC_ macro is functional */
    440 #  define MHD_HAS_NOWARN_UNUSED_FUNC_   1
    441 #endif
    442 #ifndef MHD_RESTORE_WARN_UNUSED_FUNC_
    443 #  define MHD_RESTORE_WARN_UNUSED_FUNC_ /* empty */
    444 #endif
    445 #ifndef MHD_NOWARN_AGGR_DYN_INIT_
    446 #  define MHD_NOWARN_AGGR_DYN_INIT_ /* empty */
    447 #endif
    448 #ifndef MHD_RESTORE_WARN_AGGR_DYN_INIT_
    449 #  define MHD_RESTORE_WARN_AGGR_DYN_INIT_ /* empty */
    450 #endif
    451 
    452 #ifdef MHD_HAS_NOWARN_UNUSED_FUNC_
    453 /**
    454  * The header static inline function.
    455  * Tries to prevent compiler warnings.
    456  * @warning Must be always followed by #MHD_STATIC_INLINE_END_ after the end of
    457  *          function
    458  */
    459 #  define MHD_STATIC_INLINE_    MHD_NOWARN_UNUSED_FUNC_ static MHD_INLINE
    460 /**
    461  * Mark the end of header static inline function.
    462  */
    463 #  define MHD_STATIC_INLINE_END_        MHD_RESTORE_WARN_UNUSED_FUNC_
    464 #else
    465 /**
    466  * The header static inline function.
    467  * Tries to prevent compiler warnings.
    468  * @warning Must be always followed by #MHD_STATIC_INLINE_END_ after the end of
    469  *          function
    470  */
    471 #  define MHD_STATIC_INLINE_    MHD_NOWARN_EXPRESSION_ static MHD_INLINE
    472 /**
    473  * Mark the end of header static inline function.
    474  */
    475 #  define MHD_STATIC_INLINE_END_        /* empty */
    476 #endif
    477 
    478 /**
    479  * Define MHD_NO_DEPRECATION before including "microhttpd2.h" to disable deprecation messages
    480  */
    481 #ifdef MHD_NO_DEPRECATION
    482 #  define MHD_DEPR_MACRO_(msg)
    483 #  define MHD_NO_DEPR_IN_MACRO_ 1
    484 #  define MHD_DEPR_IN_MACRO_(msg)
    485 #  define MHD_NO_DEPR_FUNC_ 1
    486 #  define MHD_DEPR_FUNC_(msg)
    487 #endif /* MHD_NO_DEPRECATION */
    488 
    489 #ifndef MHD_DEPR_MACRO_
    490 #  if MHD_GNUC_MINV (4, 8) && !defined(__clang__)  /* GCC >= 4.8 */
    491 /* Print warning when the macro is processed (if not excluded from processing).
    492  * To be used outside other macros */
    493 #    define MHD_DEPR_MACRO_(msg) _Pragma(MHD_MACRO_STR_(GCC warning msg))
    494 /* Print warning message when another macro which includes this macro is used */
    495 #    define MHD_DEPR_IN_MACRO_(msg) MHD_DEPR_MACRO_ (msg)
    496 #  elif (MHD_CLANG_MINV (3, 3) && !defined(__apple_build_version__)) \
    497   || MHD_CLANG_MINV (5, 0)
    498 /* clang >= 3.3 (or XCode's clang >= 5.0) */
    499 /* Print warning when the macro is processed (if not excluded from processing).
    500  * To be used outside other macros */
    501 #    define MHD_DEPR_MACRO_(msg) _Pragma(MHD_MACRO_STR_(clang warning msg))
    502 /* Print warning message when another macro which includes this macro is used */
    503 #    define MHD_DEPR_IN_MACRO_(msg) MHD_DEPR_MACRO_ (msg)
    504 #  elif MHD_MSC_MINV (1500)
    505 /* Print warning when the macro is processed (if not excluded from processing).
    506  * To be used outside other macros */
    507 #    define MHD_DEPR_MACRO_(msg) \
    508             __pragma(message (__FILE__ "(" MHD_MACRO_STR_ ( __LINE__) ") : " \
    509             "warning MHDWARN01 : " msg))
    510 /* Print warning message when another macro which includes this macro is used */
    511 #    define MHD_DEPR_IN_MACRO_(msg) MHD_DEPR_MACRO_ (msg)
    512 #  elif MHD_GNUC_MINV (3, 0) /* 3.0 <= GCC < 4.8 */
    513 /* Print warning when the macro is processed (if not excluded from processing).
    514  * To be used outside other macros */
    515 #    define MHD_DEPR_MACRO_(msg) _Pragma(MHD_MACRO_STR_(message msg))
    516 #  elif MHD_CLANG_MINV (2, 9)
    517 /* Print warning when the macro is processed (if not excluded from processing).
    518  * To be used outside other macros */
    519 #    define MHD_DEPR_MACRO_(msg) _Pragma(MHD_MACRO_STR_(message msg))
    520 /* Print warning message when another macro which includes this macro is used */
    521 #    define MHD_DEPR_IN_MACRO_(msg) MHD_DEPR_MACRO_ (msg)
    522 /* #  elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
    523 #  endif
    524 #endif /* !MHD_DEPR_MACRO_ */
    525 
    526 #ifndef MHD_DEPR_FUNC_
    527 #  if MHD_GNUC_MINV (5, 0) || MHD_CLANG_MINV (2, 9)
    528 /* GCC >= 5.0 or clang >= 2.9 */
    529 #    define MHD_DEPR_FUNC_(msg) __attribute__((deprecated (msg)))
    530 #  elif  MHD_GNUC_MINV (3, 1) || defined(__clang__)
    531 /* 3.1 <= GCC < 5.0 or clang < 2.9 */
    532 #    define MHD_DEPR_FUNC_(msg) __attribute__((__deprecated__))
    533 #  elif MHD_MSC_MINV (1400)
    534 /* VS 2005 or later */
    535 #    define MHD_DEPR_FUNC_(msg) __declspec(deprecated (msg))
    536 #  elif MHD_MSC_MINV (1310)
    537 #    define MHD_DEPR_FUNC_(msg) __declspec(deprecated)
    538 /* #  elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
    539 #  endif
    540 #endif /* ! MHD_DEPR_FUNC_ */
    541 
    542 #ifndef MHD_DEPR_MACRO_
    543 #  define MHD_DEPR_MACRO_(msg)
    544 #endif /* !MHD_DEPR_MACRO_ */
    545 
    546 #ifndef MHD_DEPR_IN_MACRO_
    547 #  define MHD_NO_DEPR_IN_MACRO_ 1
    548 #  define MHD_DEPR_IN_MACRO_(msg)
    549 #endif /* !MHD_DEPR_IN_MACRO_ */
    550 
    551 #ifndef MHD_DEPR_FUNC_
    552 #  define MHD_NO_DEPR_FUNC_ 1
    553 #  define MHD_DEPR_FUNC_(msg)
    554 #endif /* !MHD_DEPR_FUNC_ */
    555 
    556 #ifdef __has_attribute
    557 #  ifndef MHD_FIXED_ENUM_
    558 #    if __has_attribute (enum_extensibility)
    559 /* Enum will not be extended */
    560 #      define MHD_FIXED_ENUM_ __attribute__((enum_extensibility (closed)))
    561 #    endif /* enum_extensibility */
    562 #  endif
    563 #  ifndef MHD_FLAGS_ENUM_
    564 #    if __has_attribute (flag_enum)
    565 /* Enum is a bitmap */
    566 #      define MHD_FLAGS_ENUM_ __attribute__((flag_enum))
    567 #    endif /* flag_enum */
    568 #  endif
    569 #endif /* __has_attribute */
    570 
    571 #ifndef MHD_FIXED_ENUM_
    572 #  define MHD_FIXED_ENUM_       /* empty */
    573 #endif /* MHD_FIXED_ENUM_ */
    574 #ifndef MHD_FLAGS_ENUM_
    575 #  define MHD_FLAGS_ENUM_       /* empty */
    576 #endif /* MHD_FLAGS_ENUM_ */
    577 
    578 #ifndef MHD_FIXED_FLAGS_ENUM_
    579 #  define MHD_FIXED_FLAGS_ENUM_ MHD_FIXED_ENUM_ MHD_FLAGS_ENUM_
    580 #endif
    581 
    582 #ifndef MHD_FIXED_ENUM_APP_SET_
    583 /* The enum is set by an application to the fixed list of values */
    584 #  define MHD_FIXED_ENUM_APP_SET_ MHD_FIXED_ENUM_
    585 #endif
    586 
    587 #ifndef MHD_FLAGS_ENUM_APP_SET_
    588 /* The enum is set by an application, it is a bitmap */
    589 #  define MHD_FLAGS_ENUM_APP_SET_ MHD_FLAGS_ENUM_
    590 #endif
    591 
    592 #ifndef MHD_FIXED_FLAGS_ENUM_APP_SET_
    593 /* The enum is set by an application to the fixed bitmap values */
    594 #  define MHD_FIXED_FLAGS_ENUM_APP_SET_ MHD_FIXED_FLAGS_ENUM_
    595 #endif
    596 
    597 #ifndef MHD_FIXED_ENUM_MHD_SET_
    598 /* The enum is set by MHD to the fixed list of values */
    599 #  define MHD_FIXED_ENUM_MHD_SET_ /* enum can be extended in next MHD versions */
    600 #endif
    601 
    602 #ifndef MHD_FLAGS_ENUM_MHD_SET_
    603 /* The enum is set by MHD, it is a bitmap */
    604 #  define MHD_FLAGS_ENUM_MHD_SET_ MHD_FLAGS_ENUM_
    605 #endif
    606 
    607 #ifndef MHD_FIXED_FLAGS_ENUM_MHD_SET_
    608 /* The enum is set by MHD to the fixed bitmap values */
    609 #  define MHD_FIXED_FLAGS_ENUM_MHD_SET_ MHD_FLAGS_ENUM_ /* enum can be extended in next MHD versions */
    610 #endif
    611 
    612 #ifndef MHD_FIXED_ENUM_MHD_APP_SET_
    613 /* The enum is set by both MHD and app to the fixed list of values */
    614 #  define MHD_FIXED_ENUM_MHD_APP_SET_ /* enum can be extended in next MHD versions */
    615 #endif
    616 
    617 #ifndef MHD_FLAGS_ENUM_MHD_APP_SET_
    618 /* The enum is set by both MHD and app, it is a bitmap */
    619 #  define MHD_FLAGS_ENUM_MHD_APP_SET_ MHD_FLAGS_ENUM_
    620 #endif
    621 
    622 #ifndef MHD_FIXED_FLAGS_ENUM_MHD_APP_SET_
    623 /* The enum is set by both MHD and app to the fixed bitmap values */
    624 #  define MHD_FIXED_FLAGS_ENUM_MHD_APP_SET_ MHD_FLAGS_ENUM_ /* enum can be extended in next MHD versions */
    625 #endif
    626 
    627 
    628 /* Define MHD_NO_FUNC_ATTRIBUTES to avoid having function attributes */
    629 #if !defined(MHD_NO_FUNC_ATTRIBUTES)
    630 #  if defined(__has_attribute)
    631 
    632 /* Override detected value of MHD_FN_PURE_ by defining it before including
    633  * the header */
    634 #    if __has_attribute (pure) && !defined(MHD_FN_PURE_)
    635 /**
    636  * MHD_FN_PURE_ functions always return the same value for this same input
    637  * if volatile memory content is not changed.
    638  * In general, such functions must must not access any global variables that
    639  * can be changed over the time.
    640  * Typical examples:
    641  *   size_t strlen(const char *str);
    642  *   int memcmpconst void *ptr1, const void *ptr2, size_t _Size);
    643  */
    644 #      define MHD_FN_PURE_ __attribute__ ((pure))
    645 #    endif /* pure && !MHD_FN_PURE_ */
    646 
    647 /* Override detected value of MHD_FN_CONST_ by defining it before including
    648  * the header */
    649 #    if !defined(MHD_FN_CONST_)
    650 #      if __has_attribute (const)
    651 /**
    652  * MHD_FN_CONST_ functions always return the same value for this same
    653  * input value, even if any memory pointed by parameter is changed or
    654  * any global value changed. The functions do not change any global values.
    655  * In general, such functions must not dereference any pointers provided
    656  * as a parameter and must not access any global variables that can be
    657  * changed over the time.
    658  * Typical examples:
    659  *   int square(int x);
    660  *   int sum(int a, int b);
    661  */
    662 #        define MHD_FN_CONST_ __attribute__ ((const))
    663 #      elif defined(MHD_FN_PURE_) /* && ! __has_attribute (const) */
    664 #        define MHD_FN_CONST_ MHD_FN_PURE_
    665 #      endif
    666 #    endif /* const && !MHD_FN_CONST_ */
    667 
    668 /* Override detected value of MHD_FN_RETURNS_NONNULL_ by defining it before
    669  * including the header */
    670 #    if __has_attribute (returns_nonnull) && \
    671   !defined(MHD_FN_RETURNS_NONNULL_)
    672 /**
    673  * MHD_FN_RETURNS_NONNULL_ indicates that function never returns NULL.
    674  */
    675 #      define MHD_FN_RETURNS_NONNULL_ __attribute__ ((returns_nonnull))
    676 #    endif /* returns_nonnull && !MHD_FN_RETURNS_NONNULL_ */
    677 
    678 /* Override detected value of MHD_FN_MUST_CHECK_RESULT_ by defining it before
    679  * including the header */
    680 #    if __has_attribute (warn_unused_result) && \
    681   !defined(MHD_FN_MUST_CHECK_RESULT_)
    682 /**
    683  * MHD_FN_MUST_CHECK_RESULT_ indicates that caller must check the value
    684  * returned by the function.
    685  */
    686 #      define MHD_FN_MUST_CHECK_RESULT_ __attribute__ ((warn_unused_result))
    687 #    endif /* warn_unused_result && !MHD_FN_MUST_CHECK_RESULT_ */
    688 
    689 /* Override detected value of MHD_FN_PAR_NONNULL_ by defining it before
    690  * including the header */
    691 #    if __has_attribute (nonnull) && \
    692   !defined(MHD_FN_PAR_NONNULL_)
    693 /**
    694  * MHD_FN_PAR_NONNULL_ indicates function parameter number @a param_num
    695  * must never be NULL.
    696  */
    697 #      define MHD_FN_PAR_NONNULL_(param_num) \
    698               __attribute__ ((nonnull (param_num)))
    699 #    endif /* nonnull && !MHD_FN_PAR_NONNULL_ */
    700 
    701 /* Override detected value of MHD_FN_PAR_NONNULL_ALL_ by defining it before
    702  * including the header */
    703 #    if __has_attribute (nonnull) && \
    704   !defined(MHD_FN_PAR_NONNULL_ALL_)
    705 /**
    706  * MHD_FN_PAR_NONNULL_ALL_ indicates all function parameters must
    707  * never be NULL.
    708  */
    709 #      define MHD_FN_PAR_NONNULL_ALL_ __attribute__ ((nonnull))
    710 #    endif /* nonnull && !MHD_FN_PAR_NONNULL_ALL_ */
    711 
    712 #    if __has_attribute (access)
    713 
    714 /* Override detected value of MHD_FN_PAR_IN_ by defining it before
    715  * including the header */
    716 #      if !defined(MHD_FN_PAR_IN_)
    717 /**
    718  * MHD_FN_PAR_IN_ indicates function parameter points to data
    719  * that must not be modified by the function
    720  */
    721 #        define MHD_FN_PAR_IN_(param_num) \
    722                 __attribute__ ((access (read_only,param_num)))
    723 #      endif /* !MHD_FN_PAR_IN_ */
    724 
    725 /* Override detected value of MHD_FN_PAR_IN_SIZE_ by defining it before
    726  * including the header */
    727 #      if !defined(MHD_FN_PAR_IN_SIZE_)
    728 /**
    729  * MHD_FN_PAR_IN_SIZE_ indicates function parameter points to data
    730  * which size is specified by @a size_num parameter and that must not be
    731  * modified by the function
    732  */
    733 #        define MHD_FN_PAR_IN_SIZE_(param_num, size_num) \
    734                 __attribute__ ((access (read_only,param_num,size_num)))
    735 #      endif /* !MHD_FN_PAR_IN_SIZE_ */
    736 
    737 /* Override detected value of MHD_FN_PAR_OUT_ by defining it before
    738  * including the header */
    739 #      if !defined(MHD_FN_PAR_OUT_)
    740 /**
    741  * MHD_FN_PAR_OUT_ indicates function parameter points to data
    742  * that could be written by the function, but not read.
    743  */
    744 #        define MHD_FN_PAR_OUT_(param_num) \
    745                 __attribute__ ((access (write_only,param_num)))
    746 #      endif /* !MHD_FN_PAR_OUT_ */
    747 
    748 /* Override detected value of MHD_FN_PAR_OUT_SIZE_ by defining it before
    749  * including the header */
    750 #      if !defined(MHD_FN_PAR_OUT_SIZE_)
    751 /**
    752  * MHD_FN_PAR_OUT_SIZE_ indicates function parameter points to data
    753  * which size is specified by @a size_num parameter and that could be
    754  * written by the function, but not read.
    755  */
    756 #        define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) \
    757                 __attribute__ ((access (write_only,param_num,size_num)))
    758 #      endif /* !MHD_FN_PAR_OUT_SIZE_ */
    759 
    760 /* Override detected value of MHD_FN_PAR_INOUT_ by defining it before
    761  * including the header */
    762 #      if !defined(MHD_FN_PAR_INOUT_)
    763 /**
    764  * MHD_FN_PAR_INOUT_ indicates function parameter points to data
    765  * that could be both read and written by the function.
    766  */
    767 #        define MHD_FN_PAR_INOUT_(param_num) \
    768                 __attribute__ ((access (read_write,param_num)))
    769 #      endif /* !MHD_FN_PAR_INOUT_ */
    770 
    771 /* Override detected value of MHD_FN_PAR_INOUT_SIZE_ by defining it before
    772  * including the header */
    773 #      if !defined(MHD_FN_PAR_INOUT_SIZE_)
    774 /**
    775  * MHD_FN_PAR_INOUT_SIZE_ indicates function parameter points to data
    776  * which size is specified by @a size_num parameter and that could be
    777  * both read and written by the function.
    778  */
    779 #        define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num) \
    780                 __attribute__ ((access (read_write,param_num,size_num)))
    781 #      endif /* !MHD_FN_PAR_INOUT_SIZE_ */
    782 
    783 #    endif /* access */
    784 
    785 /* Override detected value of MHD_FN_PAR_FD_READ_ by defining it before
    786  * including the header */
    787 #    if __has_attribute (fd_arg_read) && \
    788   !defined(MHD_FN_PAR_FD_READ_)
    789 /**
    790  * MHD_FN_PAR_FD_READ_ indicates function parameter is file descriptor that
    791  * must be in open state and available for reading
    792  */
    793 #      define MHD_FN_PAR_FD_READ_(param_num) \
    794               __attribute__ ((fd_arg_read (param_num)))
    795 #    endif /* fd_arg_read && !MHD_FN_PAR_FD_READ_ */
    796 
    797 /* Override detected value of MHD_FN_PAR_CSTR_ by defining it before
    798  * including the header */
    799 #    if __has_attribute (null_terminated_string_arg) && \
    800   !defined(MHD_FN_PAR_CSTR_)
    801 /**
    802  * MHD_FN_PAR_CSTR_ indicates function parameter is a NUL-terminated C string
    803  */
    804 #      define MHD_FN_PAR_CSTR_(param_num) \
    805               __attribute__ ((null_terminated_string_arg (param_num)))
    806 #    endif /* null_terminated_string_arg && !MHD_FN_PAR_CSTR_ */
    807 
    808 #  endif /* __has_attribute */
    809 #endif /* ! MHD_NO_FUNC_ATTRIBUTES */
    810 
    811 /* Override detected value of MHD_FN_PAR_DYN_ARR_SIZE_() by defining it
    812  * before including the header */
    813 #ifndef MHD_FN_PAR_DYN_ARR_SIZE_
    814 #  ifdef MHD_USE_VLA_TYPES
    815 #    define MHD_FN_PAR_DYN_ARR_SIZE_(size)  static size
    816 #  else
    817 #    define MHD_FN_PAR_DYN_ARR_SIZE_(size)  1
    818 #  endif
    819 #endif /* MHD_FN_PAR_DYN_ARR_SIZE_ */
    820 
    821 /* Override detected value of MHD_FN_PAR_FIX_ARR_SIZE_() by defining it
    822  * before including the header */
    823 #ifndef MHD_FN_PAR_FIX_ARR_SIZE_
    824 #  if MHD_C_MINV_99
    825 /* The size must be constant expression */
    826 #    define MHD_FN_PAR_FIX_ARR_SIZE_(size)    static size
    827 #  else
    828 /* The size must be constant expression */
    829 #    define MHD_FN_PAR_FIX_ARR_SIZE_(size)    size
    830 #  endif /* MHD_C_MINV_99 */
    831 #endif /* MHD_FN_PAR_FIX_ARR_SIZE_ */
    832 
    833 
    834 #ifndef MHD_FN_CONST_
    835 #  define MHD_FN_CONST_       /* empty */
    836 #endif /* ! MHD_FN_CONST_ */
    837 #ifndef MHD_FN_PURE_
    838 #  define MHD_FN_PURE_        /* empty */
    839 #endif /* ! MHD_FN_PURE_ */
    840 #ifndef MHD_FN_RETURNS_NONNULL_
    841 #  define MHD_FN_RETURNS_NONNULL_       /* empty */
    842 #endif /* ! MHD_FN_RETURNS_NONNULL_ */
    843 #ifndef MHD_FN_MUST_CHECK_RESULT_
    844 #  define MHD_FN_MUST_CHECK_RESULT_   /* empty */
    845 #endif /* ! MHD_FN_MUST_CHECK_RESULT_ */
    846 #ifndef MHD_FN_PAR_NONNULL_
    847 #  define MHD_FN_PAR_NONNULL_(param_num)    /* empty */
    848 #endif /* ! MHD_FN_PAR_NONNULL_ */
    849 #ifndef MHD_FN_PAR_NONNULL_ALL_
    850 #  define MHD_FN_PAR_NONNULL_ALL_   /* empty */
    851 #endif /* ! MHD_FN_PAR_NONNULL_ALL_ */
    852 #ifndef MHD_FN_PAR_IN_
    853 #  define MHD_FN_PAR_IN_(param_num) /* empty */
    854 #endif /* !MHD_FN_PAR_IN_ */
    855 #ifndef MHD_FN_PAR_IN_SIZE_
    856 #  define MHD_FN_PAR_IN_SIZE_(param_num, size_num)  /* empty */
    857 #endif /* !MHD_FN_PAR_IN_SIZE_ */
    858 #ifndef MHD_FN_PAR_OUT_
    859 #  define MHD_FN_PAR_OUT_(param_num)        /* empty */
    860 #endif /* !MHD_FN_PAR_OUT_ */
    861 #ifndef MHD_FN_PAR_OUT_SIZE_
    862 #  define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) /* empty */
    863 #endif /* !MHD_FN_PAR_OUT_SIZE_ */
    864 #ifndef MHD_FN_PAR_INOUT_
    865 #  define MHD_FN_PAR_INOUT_(param_num)      /* empty */
    866 #endif /* !MHD_FN_PAR_INOUT_ */
    867 #ifndef MHD_FN_PAR_INOUT_SIZE_
    868 #  define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num)       /* empty */
    869 #endif /* !MHD_FN_PAR_INOUT_SIZE_ */
    870 #ifndef MHD_FN_PAR_FD_READ_
    871 #  define MHD_FN_PAR_FD_READ_(param_num)        /* empty */
    872 #endif /* !MHD_FN_PAR_FD_READ_ */
    873 #ifndef MHD_FN_PAR_CSTR_
    874 #  define MHD_FN_PAR_CSTR_(param_num)   /* empty */
    875 #endif /* ! MHD_FN_PAR_CSTR_ */
    876 
    877 #endif /* ! MICROHTTPD2_PORTABILITY_H */