curl_setup.h (31145B)
1 #ifndef HEADER_CURL_SETUP_H 2 #define HEADER_CURL_SETUP_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 12 * This software is licensed as described in the file COPYING, which 13 * you should have received as part of this distribution. The terms 14 * are also available at https://curl.se/docs/copyright.html. 15 * 16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 * copies of the Software, and permit persons to whom the Software is 18 * furnished to do so, under the terms of the COPYING file. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 * SPDX-License-Identifier: curl 24 * 25 ***************************************************************************/ 26 27 #if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES) 28 #define CURL_NO_OLDIES 29 #endif 30 31 /* Set default _WIN32_WINNT */ 32 #ifdef __MINGW32__ 33 #include <_mingw.h> 34 #endif 35 36 /* Workaround for Homebrew gcc 12.4.0, 13.3.0, 14.1.0, 14.2.0 (initial build) 37 that started advertising the `availability` attribute, which then gets used 38 by Apple SDK, but, in a way incompatible with gcc, resulting in misc errors 39 inside SDK headers, e.g.: 40 error: attributes should be specified before the declarator in a function 41 definition 42 error: expected ',' or '}' before 43 Followed by missing declarations. 44 Work it around by overriding the built-in feature-check macro used by the 45 headers to enable the problematic attributes. This makes the feature check 46 fail. Fixed in 14.2.0_1. Disable the workaround if the fix is detected. */ 47 #if defined(__APPLE__) && !defined(__clang__) && defined(__GNUC__) && \ 48 defined(__has_attribute) 49 # if !defined(__has_feature) 50 # define availability curl_pp_attribute_disabled 51 # elif !__has_feature(attribute_availability) 52 # define availability curl_pp_attribute_disabled 53 # endif 54 #endif 55 56 #ifdef __APPLE__ 57 #include <sys/types.h> 58 #include <TargetConditionals.h> 59 /* Fixup faulty target macro initialization in macOS SDK since v14.4 (as of 60 15.0 beta). The SDK target detection in `TargetConditionals.h` correctly 61 detects macOS, but fails to set the macro's old name `TARGET_OS_OSX`, then 62 continues to set it to a default value of 0. Other parts of the SDK still 63 rely on the old name, and with this inconsistency our builds fail due to 64 missing declarations. It happens when using mainline llvm older than v18. 65 Later versions fixed it by predefining these target macros, avoiding the 66 faulty dynamic detection. gcc is not affected (for now) because it lacks 67 the necessary dynamic detection features, so the SDK falls back to 68 a codepath that sets both the old and new macro to 1. */ 69 #if defined(TARGET_OS_MAC) && TARGET_OS_MAC && \ 70 defined(TARGET_OS_OSX) && !TARGET_OS_OSX && \ 71 (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \ 72 (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR) 73 #undef TARGET_OS_OSX 74 #define TARGET_OS_OSX TARGET_OS_MAC 75 #endif 76 #endif 77 78 /* Visual Studio 2008 is the minimum Visual Studio version we support. 79 Workarounds for older versions of Visual Studio have been removed. */ 80 #if defined(_MSC_VER) && (_MSC_VER < 1500) 81 #error "Ancient versions of Visual Studio are no longer supported due to bugs." 82 #endif 83 84 #ifdef _MSC_VER 85 /* Disable Visual Studio warnings: 4127 "conditional expression is constant" */ 86 #pragma warning(disable:4127) 87 /* Avoid VS2005 and upper complaining about portable C functions. */ 88 #ifndef _CRT_NONSTDC_NO_DEPRECATE 89 #define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write(), etc. */ 90 #endif 91 #ifndef _CRT_SECURE_NO_DEPRECATE 92 #define _CRT_SECURE_NO_DEPRECATE /* for fopen(), getenv(), etc. */ 93 #endif 94 #endif /* _MSC_VER */ 95 96 #ifdef _WIN32 97 /* 98 * Do not include unneeded stuff in Windows headers to avoid compiler 99 * warnings and macro clashes. 100 * Make sure to define this macro before including any Windows headers. 101 */ 102 # ifndef WIN32_LEAN_AND_MEAN 103 # define WIN32_LEAN_AND_MEAN 104 # endif 105 # ifndef NOGDI 106 # define NOGDI 107 # endif 108 /* Detect Windows App environment which has a restricted access 109 * to the Win32 APIs. */ 110 # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ 111 defined(WINAPI_FAMILY) 112 # include <winapifamily.h> 113 # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ 114 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 115 # define CURL_WINDOWS_UWP 116 # endif 117 # endif 118 #endif 119 120 /* Avoid bogus format check warnings with mingw32ce gcc 4.4.0 in 121 C99 (-std=gnu99) mode */ 122 #if defined(__MINGW32CE__) && !defined(CURL_NO_FMT_CHECKS) && \ 123 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) && \ 124 (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4)) 125 #define CURL_NO_FMT_CHECKS 126 #endif 127 128 /* Compatibility */ 129 #ifdef ENABLE_IPV6 130 #define USE_IPV6 1 131 #endif 132 133 /* 134 * Include configuration script results or hand-crafted 135 * configuration file for platforms which lack config tool. 136 */ 137 138 #ifdef HAVE_CONFIG_H 139 140 #include "curl_config.h" 141 142 #else /* HAVE_CONFIG_H */ 143 144 #ifdef _WIN32 145 # include "config-win32.h" 146 #endif 147 148 #ifdef macintosh 149 # include "config-mac.h" 150 #endif 151 152 #ifdef __riscos__ 153 # include "config-riscos.h" 154 #endif 155 156 #ifdef __OS400__ 157 # include "config-os400.h" 158 #endif 159 160 #ifdef __PLAN9__ 161 # include "config-plan9.h" 162 #endif 163 164 #endif /* HAVE_CONFIG_H */ 165 166 /* ================================================================ */ 167 /* Definition of preprocessor macros/symbols which modify compiler */ 168 /* behavior or generated code characteristics must be done here, */ 169 /* as appropriate, before any system header file is included. It is */ 170 /* also possible to have them defined in the config file included */ 171 /* before this point. As a result of all this we frown inclusion of */ 172 /* system header files in our config files, avoid this at any cost. */ 173 /* ================================================================ */ 174 175 #ifdef HAVE_LIBZ 176 # ifndef ZLIB_CONST 177 # define ZLIB_CONST /* Use z_const. Supported by v1.2.5.2 and upper. */ 178 # endif 179 #endif 180 181 /* 182 * AIX 4.3 and newer needs _THREAD_SAFE defined to build 183 * proper reentrant code. Others may also need it. 184 */ 185 186 #ifdef NEED_THREAD_SAFE 187 # ifndef _THREAD_SAFE 188 # define _THREAD_SAFE 189 # endif 190 #endif 191 192 /* 193 * Tru64 needs _REENTRANT set for a few function prototypes and 194 * things to appear in the system header files. Unixware needs it 195 * to build proper reentrant code. Others may also need it. 196 */ 197 198 #ifdef NEED_REENTRANT 199 # ifndef _REENTRANT 200 # define _REENTRANT 201 # endif 202 #endif 203 204 /* Solaris needs this to get a POSIX-conformant getpwuid_r */ 205 #if defined(sun) || defined(__sun) 206 # ifndef _POSIX_PTHREAD_SEMANTICS 207 # define _POSIX_PTHREAD_SEMANTICS 1 208 # endif 209 #endif 210 211 /* ================================================================ */ 212 /* If you need to include a system header file for your platform, */ 213 /* please, do it beyond the point further indicated in this file. */ 214 /* ================================================================ */ 215 216 /* Give calloc a chance to be dragging in early, so we do not redefine */ 217 #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) 218 # include <pthread.h> 219 #endif 220 221 /* 222 * Disable other protocols when http is the only one desired. 223 */ 224 225 #ifdef HTTP_ONLY 226 # ifndef CURL_DISABLE_DICT 227 # define CURL_DISABLE_DICT 228 # endif 229 # ifndef CURL_DISABLE_FILE 230 # define CURL_DISABLE_FILE 231 # endif 232 # ifndef CURL_DISABLE_FTP 233 # define CURL_DISABLE_FTP 234 # endif 235 # ifndef CURL_DISABLE_GOPHER 236 # define CURL_DISABLE_GOPHER 237 # endif 238 # ifndef CURL_DISABLE_IMAP 239 # define CURL_DISABLE_IMAP 240 # endif 241 # ifndef CURL_DISABLE_LDAP 242 # define CURL_DISABLE_LDAP 243 # endif 244 # ifndef CURL_DISABLE_LDAPS 245 # define CURL_DISABLE_LDAPS 246 # endif 247 # ifndef CURL_DISABLE_MQTT 248 # define CURL_DISABLE_MQTT 249 # endif 250 # ifndef CURL_DISABLE_POP3 251 # define CURL_DISABLE_POP3 252 # endif 253 # ifndef CURL_DISABLE_RTSP 254 # define CURL_DISABLE_RTSP 255 # endif 256 # ifndef CURL_DISABLE_SMB 257 # define CURL_DISABLE_SMB 258 # endif 259 # ifndef CURL_DISABLE_SMTP 260 # define CURL_DISABLE_SMTP 261 # endif 262 # ifndef CURL_DISABLE_TELNET 263 # define CURL_DISABLE_TELNET 264 # endif 265 # ifndef CURL_DISABLE_TFTP 266 # define CURL_DISABLE_TFTP 267 # endif 268 #endif 269 270 /* 271 * When http is disabled rtsp is not supported. 272 */ 273 274 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP) 275 # define CURL_DISABLE_RTSP 276 #endif 277 278 /* 279 * When HTTP is disabled, disable HTTP-only features 280 */ 281 282 #ifdef CURL_DISABLE_HTTP 283 # define CURL_DISABLE_ALTSVC 1 284 # define CURL_DISABLE_COOKIES 1 285 # define CURL_DISABLE_BASIC_AUTH 1 286 # define CURL_DISABLE_BEARER_AUTH 1 287 # define CURL_DISABLE_AWS 1 288 # define CURL_DISABLE_DOH 1 289 # define CURL_DISABLE_FORM_API 1 290 # define CURL_DISABLE_HEADERS_API 1 291 # define CURL_DISABLE_HSTS 1 292 # define CURL_DISABLE_HTTP_AUTH 1 293 #endif 294 295 /* ================================================================ */ 296 /* No system header file shall be included in this file before this */ 297 /* point. */ 298 /* ================================================================ */ 299 300 /* 301 * OS/400 setup file includes some system headers. 302 */ 303 304 #ifdef __OS400__ 305 # include "setup-os400.h" 306 #endif 307 308 /* 309 * VMS setup file includes some system headers. 310 */ 311 312 #ifdef __VMS 313 # include "setup-vms.h" 314 #endif 315 316 /* 317 * Windows setup file includes some system headers. 318 */ 319 320 #ifdef _WIN32 321 # include "setup-win32.h" 322 #endif 323 324 #include <curl/system.h> 325 326 /* Helper macro to expand and concatenate two macros. 327 * Direct macros concatenation does not work because macros 328 * are not expanded before direct concatenation. 329 */ 330 #define CURL_CONC_MACROS_(A,B) A ## B 331 #define CURL_CONC_MACROS(A,B) CURL_CONC_MACROS_(A,B) 332 333 /* curl uses its own printf() function internally. It understands the GNU 334 * format. Use this format, so that is matches the GNU format attribute we 335 * use with the MinGW compiler, allowing it to verify them at compile-time. 336 */ 337 #ifdef __MINGW32__ 338 # undef CURL_FORMAT_CURL_OFF_T 339 # undef CURL_FORMAT_CURL_OFF_TU 340 # define CURL_FORMAT_CURL_OFF_T "lld" 341 # define CURL_FORMAT_CURL_OFF_TU "llu" 342 #endif 343 344 /* based on logic in "curl/mprintf.h" */ 345 346 #if (defined(__GNUC__) || defined(__clang__) || \ 347 defined(__IAR_SYSTEMS_ICC__)) && \ 348 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ 349 !defined(CURL_NO_FMT_CHECKS) 350 #if defined(__MINGW32__) && !defined(__clang__) 351 #define CURL_PRINTF(fmt, arg) \ 352 __attribute__((format(gnu_printf, fmt, arg))) 353 #else 354 #define CURL_PRINTF(fmt, arg) \ 355 __attribute__((format(__printf__, fmt, arg))) 356 #endif 357 #else 358 #define CURL_PRINTF(fmt, arg) 359 #endif 360 361 /* Override default printf mask check rules in "curl/mprintf.h" */ 362 #define CURL_TEMP_PRINTF CURL_PRINTF 363 364 /* Workaround for mainline llvm v16 and earlier missing a built-in macro 365 expected by macOS SDK v14 / Xcode v15 (2023) and newer. 366 gcc (as of v14) is also missing it. */ 367 #if defined(__APPLE__) && \ 368 ((!defined(__apple_build_version__) && \ 369 defined(__clang__) && __clang_major__ < 17) || \ 370 (defined(__GNUC__) && __GNUC__ <= 14)) && \ 371 defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 372 !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__) 373 #define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ \ 374 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 375 #endif 376 377 /* 378 * Use getaddrinfo to resolve the IPv4 address literal. If the current network 379 * interface does not support IPv4, but supports IPv6, NAT64, and DNS64, 380 * performing this task will result in a synthesized IPv6 address. 381 */ 382 #if defined(__APPLE__) && !defined(USE_ARES) 383 #define USE_RESOLVE_ON_IPS 1 384 # if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \ 385 defined(USE_IPV6) 386 # define CURL_MACOS_CALL_COPYPROXIES 1 387 # endif 388 #endif 389 390 #ifdef USE_ARES 391 # ifndef CARES_NO_DEPRECATED 392 # define CARES_NO_DEPRECATED /* for ares_getsock() */ 393 # endif 394 # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && defined(_WIN32) 395 # define CARES_STATICLIB /* define it before including ares.h */ 396 # endif 397 #endif 398 399 #ifdef USE_LWIPSOCK 400 # include <lwip/init.h> 401 # include <lwip/sockets.h> 402 # include <lwip/netdb.h> 403 #endif 404 405 #ifdef macintosh 406 # include <extra/stricmp.h> 407 # include <extra/strdup.h> 408 #endif 409 410 #ifdef __AMIGA__ 411 # ifdef __amigaos4__ 412 # define __USE_INLINE__ 413 /* use our own resolver which uses runtime feature detection */ 414 # define CURLRES_AMIGA 415 /* getaddrinfo() currently crashes bsdsocket.library, so disable */ 416 # undef HAVE_GETADDRINFO 417 # if !(defined(__NEWLIB__) || \ 418 (defined(__CLIB2__) && defined(__THREAD_SAFE))) 419 /* disable threaded resolver with clib2 - requires newlib or clib-ts */ 420 # undef USE_THREADS_POSIX 421 # endif 422 # endif 423 # include <exec/types.h> 424 # include <exec/execbase.h> 425 # include <proto/exec.h> 426 # include <proto/dos.h> 427 # include <unistd.h> 428 # if defined(HAVE_PROTO_BSDSOCKET_H) && \ 429 (!defined(__amigaos4__) || defined(USE_AMISSL)) 430 /* use bsdsocket.library directly, instead of libc networking functions */ 431 # define _SYS_MBUF_H /* m_len define clashes with curl */ 432 # include <proto/bsdsocket.h> 433 # ifdef __amigaos4__ 434 int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds, 435 fd_set *errorfds, struct timeval *timeout); 436 # define select(a,b,c,d,e) Curl_amiga_select(a,b,c,d,e) 437 # else 438 # define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0) 439 # endif 440 /* must not use libc's fcntl() on bsdsocket.library sockfds! */ 441 # undef HAVE_FCNTL 442 # undef HAVE_FCNTL_O_NONBLOCK 443 # else 444 /* use libc networking and hence close() and fnctl() */ 445 # undef HAVE_CLOSESOCKET_CAMEL 446 # undef HAVE_IOCTLSOCKET_CAMEL 447 # endif 448 /* 449 * In clib2 arpa/inet.h warns that some prototypes may clash 450 * with bsdsocket.library. This avoids the definition of those. 451 */ 452 # define __NO_NET_API 453 #endif 454 455 /* Whether to use eventfd() */ 456 #if defined(HAVE_EVENTFD) && defined(HAVE_SYS_EVENTFD_H) 457 #define USE_EVENTFD 458 #endif 459 460 #include <stdio.h> 461 #include <assert.h> 462 463 #ifdef __TANDEM /* for ns*-tandem-nsk systems */ 464 # if ! defined __LP64 465 # include <floss.h> /* FLOSS is only used for 32-bit builds. */ 466 # endif 467 #endif 468 469 #ifndef STDC_HEADERS /* no standard C headers! */ 470 #include <curl/stdcheaders.h> 471 #endif 472 473 #ifdef _WIN32 474 # ifdef HAVE_IO_H 475 # include <io.h> 476 # endif 477 # include <sys/types.h> 478 # include <sys/stat.h> 479 # ifdef USE_WIN32_LARGE_FILES 480 /* Large file (>2Gb) support using Win32 functions. */ 481 # undef lseek 482 # define lseek(fdes, offset, whence) _lseeki64(fdes, offset, whence) 483 # undef fstat 484 # define fstat(fdes,stp) _fstati64(fdes, stp) 485 # undef stat 486 # define struct_stat struct _stati64 487 # define LSEEK_ERROR (__int64)-1 488 # else 489 /* Small file (<2Gb) support using Win32 functions. */ 490 # ifndef UNDER_CE 491 # undef lseek 492 # define lseek(fdes, offset, whence) _lseek(fdes, (long)offset, whence) 493 # define fstat(fdes, stp) _fstat(fdes, stp) 494 # define struct_stat struct _stat 495 # endif 496 # define LSEEK_ERROR (long)-1 497 # endif 498 # ifndef UNDER_CE 499 int curlx_win32_stat(const char *path, struct_stat *buffer); 500 int curlx_win32_open(const char *filename, int oflag, ...); 501 FILE *curlx_win32_fopen(const char *filename, const char *mode); 502 # define stat(fname, stp) curlx_win32_stat(fname, stp) 503 # define open curlx_win32_open 504 # define CURL_FOPEN(fname, mode) curlx_win32_fopen(fname, mode) 505 # define fopen(fname, mode) CURL_FOPEN(fname, mode) 506 # endif 507 #elif defined(__DJGPP__) 508 /* Requires DJGPP 2.04 */ 509 # include <unistd.h> 510 # undef lseek 511 # define lseek(fdes,offset,whence) llseek(fdes, offset, whence) 512 # define LSEEK_ERROR (offset_t)-1 513 #endif 514 515 #ifndef struct_stat 516 #define struct_stat struct stat 517 #endif 518 519 #ifndef LSEEK_ERROR 520 #define LSEEK_ERROR (off_t)-1 521 #endif 522 523 #ifndef SIZEOF_TIME_T 524 /* assume default size of time_t to be 32 bits */ 525 #define SIZEOF_TIME_T 4 526 #endif 527 528 #ifndef SIZEOF_CURL_SOCKET_T 529 /* configure and cmake check and set the define */ 530 # ifdef _WIN64 531 # define SIZEOF_CURL_SOCKET_T 8 532 # else 533 /* default guess */ 534 # define SIZEOF_CURL_SOCKET_T 4 535 # endif 536 #endif 537 538 #if SIZEOF_CURL_SOCKET_T < 8 539 # define FMT_SOCKET_T "d" 540 #elif defined(__MINGW32__) 541 # define FMT_SOCKET_T "zd" 542 #else 543 # define FMT_SOCKET_T "qd" 544 #endif 545 546 /* 547 * Default sizeof(off_t) in case it has not been defined in config file. 548 */ 549 550 #ifndef SIZEOF_OFF_T 551 # if defined(__VMS) && !defined(__VAX) 552 # if defined(_LARGEFILE) 553 # define SIZEOF_OFF_T 8 554 # endif 555 # elif defined(__OS400__) && defined(__ILEC400__) 556 # if defined(_LARGE_FILES) 557 # define SIZEOF_OFF_T 8 558 # endif 559 # elif defined(__MVS__) && defined(__IBMC__) 560 # if defined(_LP64) || defined(_LARGE_FILES) 561 # define SIZEOF_OFF_T 8 562 # endif 563 # elif defined(__370__) && defined(__IBMC__) 564 # if defined(_LP64) || defined(_LARGE_FILES) 565 # define SIZEOF_OFF_T 8 566 # endif 567 # endif 568 # ifndef SIZEOF_OFF_T 569 # define SIZEOF_OFF_T 4 570 # endif 571 #endif 572 573 #if (SIZEOF_CURL_OFF_T < 8) 574 #error "too small curl_off_t" 575 #else 576 /* assume SIZEOF_CURL_OFF_T == 8 */ 577 # define CURL_OFF_T_MAX 0x7FFFFFFFFFFFFFFF 578 #endif 579 #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - 1) 580 581 #if (SIZEOF_CURL_OFF_T != 8) 582 # error "curl_off_t must be exactly 64 bits" 583 #else 584 typedef unsigned CURL_TYPEOF_CURL_OFF_T curl_uint64_t; 585 typedef CURL_TYPEOF_CURL_OFF_T curl_int64_t; 586 # ifndef CURL_SUFFIX_CURL_OFF_TU 587 # error "CURL_SUFFIX_CURL_OFF_TU must be defined" 588 # endif 589 # define CURL_UINT64_SUFFIX CURL_SUFFIX_CURL_OFF_TU 590 # define CURL_UINT64_C(val) CURL_CONC_MACROS(val,CURL_UINT64_SUFFIX) 591 # define FMT_PRId64 CURL_FORMAT_CURL_OFF_T 592 # define FMT_PRIu64 CURL_FORMAT_CURL_OFF_TU 593 #endif 594 595 #define FMT_OFF_T CURL_FORMAT_CURL_OFF_T 596 #define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU 597 598 #if (SIZEOF_TIME_T == 4) 599 # ifdef HAVE_TIME_T_UNSIGNED 600 # define TIME_T_MAX UINT_MAX 601 # define TIME_T_MIN 0 602 # else 603 # define TIME_T_MAX INT_MAX 604 # define TIME_T_MIN INT_MIN 605 # endif 606 #else 607 # ifdef HAVE_TIME_T_UNSIGNED 608 # define TIME_T_MAX 0xFFFFFFFFFFFFFFFF 609 # define TIME_T_MIN 0 610 # else 611 # define TIME_T_MAX 0x7FFFFFFFFFFFFFFF 612 # define TIME_T_MIN (-TIME_T_MAX - 1) 613 # endif 614 #endif 615 616 #ifndef SIZE_T_MAX 617 /* some limits.h headers have this defined, some do not */ 618 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4) 619 #define SIZE_T_MAX 18446744073709551615U 620 #else 621 #define SIZE_T_MAX 4294967295U 622 #endif 623 #endif 624 625 #ifndef SSIZE_T_MAX 626 /* some limits.h headers have this defined, some do not */ 627 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4) 628 #define SSIZE_T_MAX 9223372036854775807 629 #else 630 #define SSIZE_T_MAX 2147483647 631 #endif 632 #endif 633 634 /* 635 * Arg 2 type for gethostname in case it has not been defined in config file. 636 */ 637 638 #ifndef GETHOSTNAME_TYPE_ARG2 639 # ifdef USE_WINSOCK 640 # define GETHOSTNAME_TYPE_ARG2 int 641 # else 642 # define GETHOSTNAME_TYPE_ARG2 size_t 643 # endif 644 #endif 645 646 /* Below we define some functions. They should 647 648 4. set the SIGALRM signal timeout 649 5. set dir/file naming defines 650 */ 651 652 #ifdef _WIN32 653 654 # define DIR_CHAR "\\" 655 656 #else /* _WIN32 */ 657 658 # ifdef MSDOS /* Watt-32 */ 659 660 # include <sys/ioctl.h> 661 # define select(n,r,w,x,t) select_s(n,r,w,x,t) 662 # define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z)) 663 # include <tcp.h> 664 # undef word 665 # undef byte 666 667 # endif /* MSDOS */ 668 669 # ifdef __minix 670 /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */ 671 extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp); 672 # endif 673 674 # define DIR_CHAR "/" 675 676 #endif /* _WIN32 */ 677 678 /* ---------------------------------------------------------------- */ 679 /* resolver specialty compile-time defines */ 680 /* CURLRES_* defines to use in the host*.c sources */ 681 /* ---------------------------------------------------------------- */ 682 683 /* 684 * Mutually exclusive CURLRES_* definitions. 685 */ 686 687 #if defined(USE_IPV6) && defined(HAVE_GETADDRINFO) 688 # define CURLRES_IPV6 689 #elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__)) 690 /* assume on Windows that IPv6 without getaddrinfo is a broken build */ 691 # error "Unexpected build: IPv6 is enabled but getaddrinfo was not found." 692 #else 693 # define CURLRES_IPV4 694 #endif 695 696 #if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) 697 # define CURLRES_ASYNCH 698 # define CURLRES_THREADED 699 #elif defined(USE_ARES) 700 # define CURLRES_ASYNCH 701 # define CURLRES_ARES 702 /* now undef the stock libc functions just to avoid them being used */ 703 # undef HAVE_GETADDRINFO 704 # undef HAVE_FREEADDRINFO 705 #else 706 # define CURLRES_SYNCH 707 #endif 708 709 /* ---------------------------------------------------------------- */ 710 711 #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && \ 712 !defined(USE_WIN32_IDN) && !defined(USE_APPLE_IDN) 713 /* The lib and header are present */ 714 #define USE_LIBIDN2 715 #endif 716 717 #if defined(USE_LIBIDN2) && (defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)) 718 #error "libidn2 cannot be enabled with WinIDN or AppleIDN, choose one." 719 #endif 720 721 #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \ 722 defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || \ 723 defined(USE_RUSTLS) 724 #define USE_SSL /* SSL support has been enabled */ 725 #endif 726 727 #if defined(USE_OPENSSL) && defined(USE_WOLFSSL) 728 # include <wolfssl/version.h> 729 # if LIBWOLFSSL_VERSION_HEX >= 0x05007006 730 # ifndef OPENSSL_COEXIST 731 # define OPENSSL_COEXIST 732 # endif 733 # else 734 # error "OpenSSL can only coexist with wolfSSL v5.7.6 or upper" 735 # endif 736 #endif 737 738 #if defined(USE_WOLFSSL) && defined(USE_GNUTLS) 739 /* Avoid defining unprefixed wolfSSL SHA macros colliding with nettle ones */ 740 #define NO_OLD_WC_NAMES 741 #endif 742 743 /* Single point where USE_SPNEGO definition might be defined */ 744 #if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \ 745 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) 746 #define USE_SPNEGO 747 #endif 748 749 /* Single point where USE_KERBEROS5 definition might be defined */ 750 #if !defined(CURL_DISABLE_KERBEROS_AUTH) && \ 751 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) 752 #define USE_KERBEROS5 753 #endif 754 755 /* Single point where USE_NTLM definition might be defined */ 756 #ifndef CURL_DISABLE_NTLM 757 # if defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \ 758 defined(USE_GNUTLS) || \ 759 defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \ 760 (defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT)) 761 # define USE_CURL_NTLM_CORE 762 # endif 763 # if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI) 764 # define USE_NTLM 765 # endif 766 #endif 767 768 #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) || defined(USE_WOLFSSH) 769 #define USE_SSH 770 #endif 771 772 /* 773 * Provide a mechanism to silence picky compilers, such as gcc 4.6+. 774 * Parameters should of course normally not be unused, but for example when 775 * we have multiple implementations of the same interface it may happen. 776 */ 777 778 #if defined(__GNUC__) && ((__GNUC__ >= 3) || \ 779 ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7))) 780 # define UNUSED_PARAM __attribute__((__unused__)) 781 # define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 782 #elif defined(__IAR_SYSTEMS_ICC__) 783 # define UNUSED_PARAM __attribute__((__unused__)) 784 # if (__VER__ >= 9040001) 785 # define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 786 # else 787 # define WARN_UNUSED_RESULT 788 # endif 789 #else 790 # define UNUSED_PARAM /* NOTHING */ 791 # define WARN_UNUSED_RESULT 792 #endif 793 794 /* noreturn attribute */ 795 796 #ifndef CURL_NORETURN 797 #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \ 798 defined(__IAR_SYSTEMS_ICC__) 799 # define CURL_NORETURN __attribute__((__noreturn__)) 800 #elif defined(_MSC_VER) 801 # define CURL_NORETURN __declspec(noreturn) 802 #else 803 # define CURL_NORETURN 804 #endif 805 #endif 806 807 /* fallthrough attribute */ 808 809 #ifndef FALLTHROUGH 810 #if (defined(__GNUC__) && __GNUC__ >= 7) || \ 811 (defined(__clang__) && __clang_major__ >= 10) 812 # define FALLTHROUGH() __attribute__((fallthrough)) 813 #else 814 # define FALLTHROUGH() do {} while (0) 815 #endif 816 #endif 817 818 /* 819 * Include macros and defines that should only be processed once. 820 */ 821 822 #ifndef HEADER_CURL_SETUP_ONCE_H 823 #include "curl_setup_once.h" 824 #endif 825 826 #ifdef UNDER_CE 827 #define getenv curl_getenv /* Windows CE does not support getenv() */ 828 #define raise(s) ((void)(s)) 829 /* Terrible workarounds to make Windows CE compile */ 830 #define errno 0 831 #define CURL_SETERRNO(x) ((void)(x)) 832 #define EINTR 4 833 #define EAGAIN 11 834 #define ENOMEM 12 835 #define EACCES 13 836 #define EEXIST 17 837 #define EISDIR 21 838 #define EINVAL 22 839 #define ENOSPC 28 840 #define strerror(x) "?" 841 #undef STDIN_FILENO 842 #define STDIN_FILENO 0 843 #else 844 #define CURL_SETERRNO(x) (errno = (x)) 845 #endif 846 847 /* 848 * Definition of our NOP statement Object-like macro 849 */ 850 851 #ifndef Curl_nop_stmt 852 #define Curl_nop_stmt do { } while(0) 853 #endif 854 855 /* 856 * Ensure that Winsock and lwIP TCP/IP stacks are not mixed. 857 */ 858 859 #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H) 860 # if defined(SOCKET) || defined(USE_WINSOCK) 861 # error "Winsock and lwIP TCP/IP stack definitions shall not coexist!" 862 # endif 863 #endif 864 865 /* 866 * shutdown() flags for systems that do not define them 867 */ 868 869 #ifndef SHUT_RD 870 #define SHUT_RD 0x00 871 #endif 872 873 #ifndef SHUT_WR 874 #define SHUT_WR 0x01 875 #endif 876 877 #ifndef SHUT_RDWR 878 #define SHUT_RDWR 0x02 879 #endif 880 881 /* Define S_ISREG if not defined by system headers, e.g. MSVC */ 882 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) 883 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 884 #endif 885 886 /* Define S_ISDIR if not defined by system headers, e.g. MSVC */ 887 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) 888 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 889 #endif 890 891 /* For MSVC (all versions as of VS2022) */ 892 #ifndef STDIN_FILENO 893 #define STDIN_FILENO fileno(stdin) 894 #endif 895 #ifndef STDOUT_FILENO 896 #define STDOUT_FILENO fileno(stdout) 897 #endif 898 #ifndef STDERR_FILENO 899 #define STDERR_FILENO fileno(stderr) 900 #endif 901 902 /* Since O_BINARY is used in bitmasks, setting it to zero makes it usable in 903 source code but yet it does not ruin anything */ 904 #ifdef O_BINARY 905 #define CURL_O_BINARY O_BINARY 906 #else 907 #define CURL_O_BINARY 0 908 #endif 909 910 /* In Windows the default file mode is text but an application can override it. 911 Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 912 */ 913 #if defined(_WIN32) || defined(MSDOS) 914 #define FOPEN_READTEXT "rt" 915 #define FOPEN_WRITETEXT "wt" 916 #define FOPEN_APPENDTEXT "at" 917 #elif defined(__CYGWIN__) 918 /* Cygwin has specific behavior we need to address when _WIN32 is not defined. 919 https://cygwin.com/cygwin-ug-net/using-textbinary.html 920 For write we want our output to have line endings of LF and be compatible with 921 other Cygwin utilities. For read we want to handle input that may have line 922 endings either CRLF or LF so 't' is appropriate. 923 */ 924 #define FOPEN_READTEXT "rt" 925 #define FOPEN_WRITETEXT "w" 926 #define FOPEN_APPENDTEXT "a" 927 #else 928 #define FOPEN_READTEXT "r" 929 #define FOPEN_WRITETEXT "w" 930 #define FOPEN_APPENDTEXT "a" 931 #endif 932 933 /* for systems that do not detect this in configure */ 934 #ifndef CURL_SA_FAMILY_T 935 # if defined(HAVE_SA_FAMILY_T) 936 # define CURL_SA_FAMILY_T sa_family_t 937 # elif defined(HAVE_ADDRESS_FAMILY) 938 # define CURL_SA_FAMILY_T ADDRESS_FAMILY 939 # elif defined(__AMIGA__) 940 # define CURL_SA_FAMILY_T unsigned char 941 # else 942 /* use a sensible default */ 943 # define CURL_SA_FAMILY_T unsigned short 944 # endif 945 #endif 946 947 /* Some convenience macros to get the larger/smaller value out of two given. 948 We prefix with CURL to prevent name collisions. */ 949 #define CURLMAX(x,y) ((x)>(y)?(x):(y)) 950 #define CURLMIN(x,y) ((x)<(y)?(x):(y)) 951 952 /* A convenience macro to provide both the string literal and the length of 953 the string literal in one go, useful for functions that take "string,len" 954 as their argument */ 955 #define STRCONST(x) x,sizeof(x)-1 956 957 #define CURL_ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) 958 959 #ifdef CURLDEBUG 960 #define CURL_GETADDRINFO(host,serv,hint,res) \ 961 curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__) 962 #define CURL_FREEADDRINFO(data) \ 963 curl_dbg_freeaddrinfo(data, __LINE__, __FILE__) 964 #else 965 #define CURL_GETADDRINFO getaddrinfo 966 #define CURL_FREEADDRINFO freeaddrinfo 967 #endif 968 969 /* Some versions of the Android NDK is missing the declaration */ 970 #if defined(HAVE_GETPWUID_R) && \ 971 defined(__ANDROID_API__) && (__ANDROID_API__ < 21) 972 struct passwd; 973 int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, 974 size_t buflen, struct passwd **result); 975 #endif 976 977 #ifdef UNITTESTS 978 #define UNITTEST 979 #else 980 #define UNITTEST static 981 #endif 982 983 #ifdef USE_NGHTTP2 984 #define USE_HTTP2 985 #endif 986 987 #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || \ 988 (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \ 989 defined(USE_QUICHE) || defined(USE_MSH3) 990 991 #ifdef CURL_WITH_MULTI_SSL 992 #error "MultiSSL combined with QUIC is not supported" 993 #endif 994 995 #define USE_HTTP3 996 #endif 997 998 /* Certain Windows implementations are not aligned with what curl expects, 999 so always use the local one on this platform. E.g. the mingw-w64 1000 implementation can return wrong results for non-ASCII inputs. */ 1001 #if defined(HAVE_BASENAME) && defined(_WIN32) 1002 #undef HAVE_BASENAME 1003 #endif 1004 1005 #if defined(USE_UNIX_SOCKETS) && defined(_WIN32) 1006 # if !defined(UNIX_PATH_MAX) 1007 /* Replicating logic present in afunix.h 1008 (distributed with newer Windows 10 SDK versions only) */ 1009 # define UNIX_PATH_MAX 108 1010 /* !checksrc! disable TYPEDEFSTRUCT 1 */ 1011 typedef struct sockaddr_un { 1012 CURL_SA_FAMILY_T sun_family; 1013 char sun_path[UNIX_PATH_MAX]; 1014 } SOCKADDR_UN, *PSOCKADDR_UN; 1015 # define WIN32_SOCKADDR_UN 1016 # endif 1017 #endif 1018 1019 #ifdef USE_OPENSSL 1020 /* OpenSSLv3 marks DES, MD5 and ENGINE functions deprecated but we have no 1021 replacements (yet) so tell the compiler to not warn for them. */ 1022 # define OPENSSL_SUPPRESS_DEPRECATED 1023 # ifdef _WIN32 1024 /* Silence LibreSSL warnings about wincrypt.h collision. Works in 3.8.2+ */ 1025 # ifndef LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING 1026 # define LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING 1027 # endif 1028 # endif 1029 #endif 1030 1031 #ifdef CURL_INLINE 1032 /* 'CURL_INLINE' defined, use as-is */ 1033 #elif defined(inline) 1034 # define CURL_INLINE inline /* 'inline' defined, assumed correct */ 1035 #elif defined(__cplusplus) 1036 /* The code is compiled with C++ compiler. 1037 C++ always supports 'inline'. */ 1038 # define CURL_INLINE inline /* 'inline' keyword supported */ 1039 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 1040 /* C99 (and later) supports 'inline' keyword */ 1041 # define CURL_INLINE inline /* 'inline' keyword supported */ 1042 #elif defined(__GNUC__) && __GNUC__ >= 3 1043 /* GCC supports '__inline__' as an extension */ 1044 # define CURL_INLINE __inline__ 1045 #elif defined(_MSC_VER) 1046 # define CURL_INLINE __inline 1047 #else 1048 /* Probably 'inline' is not supported by compiler. 1049 Define to the empty string to be on the safe side. */ 1050 # define CURL_INLINE /* empty */ 1051 #endif 1052 1053 #endif /* HEADER_CURL_SETUP_H */