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