xref: /curl/lib/curl_setup.h (revision fc8e0dee)
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 /* FIXME: Delete this once the warnings have been fixed. */
32 #if !defined(CURL_WARN_SIGN_CONVERSION)
33 #ifdef __GNUC__
34 #pragma GCC diagnostic ignored "-Wsign-conversion"
35 #endif
36 #endif
37 
38 /* Set default _WIN32_WINNT */
39 #ifdef __MINGW32__
40 #include <_mingw.h>
41 #endif
42 
43 /*
44  * Disable Visual Studio warnings:
45  * 4127 "conditional expression is constant"
46  */
47 #ifdef _MSC_VER
48 #pragma warning(disable:4127)
49 #endif
50 
51 #ifdef _WIN32
52 /*
53  * Don't include unneeded stuff in Windows headers to avoid compiler
54  * warnings and macro clashes.
55  * Make sure to define this macro before including any Windows headers.
56  */
57 #  ifndef WIN32_LEAN_AND_MEAN
58 #    define WIN32_LEAN_AND_MEAN
59 #  endif
60 #  ifndef NOGDI
61 #    define NOGDI
62 #  endif
63 /* Detect Windows App environment which has a restricted access
64  * to the Win32 APIs. */
65 # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
66   defined(WINAPI_FAMILY)
67 #  include <winapifamily.h>
68 #  if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) &&  \
69      !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
70 #    define CURL_WINDOWS_APP
71 #  endif
72 # endif
73 #endif
74 
75 /* Compatibility */
76 #if defined(ENABLE_IPV6)
77 #  define USE_IPV6 1
78 #endif
79 
80 /*
81  * Include configuration script results or hand-crafted
82  * configuration file for platforms which lack config tool.
83  */
84 
85 #ifdef HAVE_CONFIG_H
86 
87 #include "curl_config.h"
88 
89 #else /* HAVE_CONFIG_H */
90 
91 #ifdef _WIN32_WCE
92 #  include "config-win32ce.h"
93 #else
94 #  ifdef _WIN32
95 #    include "config-win32.h"
96 #  endif
97 #endif
98 
99 #ifdef macintosh
100 #  include "config-mac.h"
101 #endif
102 
103 #ifdef __riscos__
104 #  include "config-riscos.h"
105 #endif
106 
107 #ifdef __AMIGA__
108 #  include "config-amigaos.h"
109 #endif
110 
111 #ifdef __OS400__
112 #  include "config-os400.h"
113 #endif
114 
115 #ifdef __PLAN9__
116 #  include "config-plan9.h"
117 #endif
118 
119 #ifdef MSDOS
120 #  include "config-dos.h"
121 #endif
122 
123 #endif /* HAVE_CONFIG_H */
124 
125 /* ================================================================ */
126 /* Definition of preprocessor macros/symbols which modify compiler  */
127 /* behavior or generated code characteristics must be done here,   */
128 /* as appropriate, before any system header file is included. It is */
129 /* also possible to have them defined in the config file included   */
130 /* before this point. As a result of all this we frown inclusion of */
131 /* system header files in our config files, avoid this at any cost. */
132 /* ================================================================ */
133 
134 /*
135  * AIX 4.3 and newer needs _THREAD_SAFE defined to build
136  * proper reentrant code. Others may also need it.
137  */
138 
139 #ifdef NEED_THREAD_SAFE
140 #  ifndef _THREAD_SAFE
141 #    define _THREAD_SAFE
142 #  endif
143 #endif
144 
145 /*
146  * Tru64 needs _REENTRANT set for a few function prototypes and
147  * things to appear in the system header files. Unixware needs it
148  * to build proper reentrant code. Others may also need it.
149  */
150 
151 #ifdef NEED_REENTRANT
152 #  ifndef _REENTRANT
153 #    define _REENTRANT
154 #  endif
155 #endif
156 
157 /* Solaris needs this to get a POSIX-conformant getpwuid_r */
158 #if defined(sun) || defined(__sun)
159 #  ifndef _POSIX_PTHREAD_SEMANTICS
160 #    define _POSIX_PTHREAD_SEMANTICS 1
161 #  endif
162 #endif
163 
164 /* ================================================================ */
165 /*  If you need to include a system header file for your platform,  */
166 /*  please, do it beyond the point further indicated in this file.  */
167 /* ================================================================ */
168 
169 /*
170  * Disable other protocols when http is the only one desired.
171  */
172 
173 #ifdef HTTP_ONLY
174 #  ifndef CURL_DISABLE_DICT
175 #    define CURL_DISABLE_DICT
176 #  endif
177 #  ifndef CURL_DISABLE_FILE
178 #    define CURL_DISABLE_FILE
179 #  endif
180 #  ifndef CURL_DISABLE_FTP
181 #    define CURL_DISABLE_FTP
182 #  endif
183 #  ifndef CURL_DISABLE_GOPHER
184 #    define CURL_DISABLE_GOPHER
185 #  endif
186 #  ifndef CURL_DISABLE_IMAP
187 #    define CURL_DISABLE_IMAP
188 #  endif
189 #  ifndef CURL_DISABLE_LDAP
190 #    define CURL_DISABLE_LDAP
191 #  endif
192 #  ifndef CURL_DISABLE_LDAPS
193 #    define CURL_DISABLE_LDAPS
194 #  endif
195 #  ifndef CURL_DISABLE_MQTT
196 #    define CURL_DISABLE_MQTT
197 #  endif
198 #  ifndef CURL_DISABLE_POP3
199 #    define CURL_DISABLE_POP3
200 #  endif
201 #  ifndef CURL_DISABLE_RTSP
202 #    define CURL_DISABLE_RTSP
203 #  endif
204 #  ifndef CURL_DISABLE_SMB
205 #    define CURL_DISABLE_SMB
206 #  endif
207 #  ifndef CURL_DISABLE_SMTP
208 #    define CURL_DISABLE_SMTP
209 #  endif
210 #  ifndef CURL_DISABLE_TELNET
211 #    define CURL_DISABLE_TELNET
212 #  endif
213 #  ifndef CURL_DISABLE_TFTP
214 #    define CURL_DISABLE_TFTP
215 #  endif
216 #endif
217 
218 /*
219  * When http is disabled rtsp is not supported.
220  */
221 
222 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
223 #  define CURL_DISABLE_RTSP
224 #endif
225 
226 /*
227  * When HTTP is disabled, disable HTTP-only features
228  */
229 
230 #if defined(CURL_DISABLE_HTTP)
231 #  define CURL_DISABLE_ALTSVC 1
232 #  define CURL_DISABLE_COOKIES 1
233 #  define CURL_DISABLE_BASIC_AUTH 1
234 #  define CURL_DISABLE_BEARER_AUTH 1
235 #  define CURL_DISABLE_AWS 1
236 #  define CURL_DISABLE_DOH 1
237 #  define CURL_DISABLE_FORM_API 1
238 #  define CURL_DISABLE_HEADERS_API 1
239 #  define CURL_DISABLE_HSTS 1
240 #  define CURL_DISABLE_HTTP_AUTH 1
241 #endif
242 
243 /* ================================================================ */
244 /* No system header file shall be included in this file before this */
245 /* point.                                                           */
246 /* ================================================================ */
247 
248 /*
249  * OS/400 setup file includes some system headers.
250  */
251 
252 #ifdef __OS400__
253 #  include "setup-os400.h"
254 #endif
255 
256 /*
257  * VMS setup file includes some system headers.
258  */
259 
260 #ifdef __VMS
261 #  include "setup-vms.h"
262 #endif
263 
264 /*
265  * Windows setup file includes some system headers.
266  */
267 
268 #ifdef _WIN32
269 #  include "setup-win32.h"
270 #endif
271 
272 #include <curl/system.h>
273 
274 /* Helper macro to expand and concatenate two macros.
275  * Direct macros concatenation does not work because macros
276  * are not expanded before direct concatenation.
277  */
278 #define CURL_CONC_MACROS_(A,B) A ## B
279 #define CURL_CONC_MACROS(A,B) CURL_CONC_MACROS_(A,B)
280 
281 /* curl uses its own printf() function internally. It understands the GNU
282  * format. Use this format, so that is matches the GNU format attribute we
283  * use with the mingw compiler, allowing it to verify them at compile-time.
284  */
285 #ifdef  __MINGW32__
286 #  undef CURL_FORMAT_CURL_OFF_T
287 #  undef CURL_FORMAT_CURL_OFF_TU
288 #  define CURL_FORMAT_CURL_OFF_T   "lld"
289 #  define CURL_FORMAT_CURL_OFF_TU  "llu"
290 #endif
291 
292 /* based on logic in "curl/mprintf.h" */
293 
294 #if (defined(__GNUC__) || defined(__clang__) ||                         \
295   defined(__IAR_SYSTEMS_ICC__)) &&                                      \
296   defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) &&         \
297   !defined(CURL_NO_FMT_CHECKS)
298 #if defined(__MINGW32__) && !defined(__clang__)
299 #define CURL_PRINTF(fmt, arg) \
300   __attribute__((format(gnu_printf, fmt, arg)))
301 #else
302 #define CURL_PRINTF(fmt, arg) \
303   __attribute__((format(__printf__, fmt, arg)))
304 #endif
305 #else
306 #define CURL_PRINTF(fmt, arg)
307 #endif
308 
309 /*
310  * Use getaddrinfo to resolve the IPv4 address literal. If the current network
311  * interface doesn't support IPv4, but supports IPv6, NAT64, and DNS64,
312  * performing this task will result in a synthesized IPv6 address.
313  */
314 #if defined(__APPLE__) && !defined(USE_ARES)
315 #include <TargetConditionals.h>
316 #define USE_RESOLVE_ON_IPS 1
317 #  if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
318      defined(USE_IPV6)
319 #    define CURL_MACOS_CALL_COPYPROXIES 1
320 #  endif
321 #endif
322 
323 #ifdef USE_LWIPSOCK
324 #  include <lwip/init.h>
325 #  include <lwip/sockets.h>
326 #  include <lwip/netdb.h>
327 #endif
328 
329 #ifdef HAVE_EXTRA_STRICMP_H
330 #  include <extra/stricmp.h>
331 #endif
332 
333 #ifdef HAVE_EXTRA_STRDUP_H
334 #  include <extra/strdup.h>
335 #endif
336 
337 #ifdef __AMIGA__
338 #  ifdef __amigaos4__
339 #    define __USE_INLINE__
340      /* use our own resolver which uses runtime feature detection */
341 #    define CURLRES_AMIGA
342      /* getaddrinfo() currently crashes bsdsocket.library, so disable */
343 #    undef HAVE_GETADDRINFO
344 #    if !(defined(__NEWLIB__) || \
345           (defined(__CLIB2__) && defined(__THREAD_SAFE)))
346        /* disable threaded resolver with clib2 - requires newlib or clib-ts */
347 #      undef USE_THREADS_POSIX
348 #    endif
349 #  endif
350 #  include <exec/types.h>
351 #  include <exec/execbase.h>
352 #  include <proto/exec.h>
353 #  include <proto/dos.h>
354 #  include <unistd.h>
355 #  if defined(HAVE_PROTO_BSDSOCKET_H) && \
356     (!defined(__amigaos4__) || defined(USE_AMISSL))
357      /* use bsdsocket.library directly, instead of libc networking functions */
358 #    define _SYS_MBUF_H /* m_len define clashes with curl */
359 #    include <proto/bsdsocket.h>
360 #    ifdef __amigaos4__
361        int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds,
362                              fd_set *errorfds, struct timeval *timeout);
363 #      define select(a,b,c,d,e) Curl_amiga_select(a,b,c,d,e)
364 #    else
365 #      define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
366 #    endif
367      /* must not use libc's fcntl() on bsdsocket.library sockfds! */
368 #    undef HAVE_FCNTL
369 #    undef HAVE_FCNTL_O_NONBLOCK
370 #  else
371      /* use libc networking and hence close() and fnctl() */
372 #    undef HAVE_CLOSESOCKET_CAMEL
373 #    undef HAVE_IOCTLSOCKET_CAMEL
374 #  endif
375 /*
376  * In clib2 arpa/inet.h warns that some prototypes may clash
377  * with bsdsocket.library. This avoids the definition of those.
378  */
379 #  define __NO_NET_API
380 #endif
381 
382 #include <stdio.h>
383 #include <assert.h>
384 
385 #ifdef __TANDEM /* for ns*-tandem-nsk systems */
386 # if ! defined __LP64
387 #  include <floss.h> /* FLOSS is only used for 32-bit builds. */
388 # endif
389 #endif
390 
391 #ifndef STDC_HEADERS /* no standard C headers! */
392 #include <curl/stdcheaders.h>
393 #endif
394 
395 /*
396  * Large file (>2Gb) support using WIN32 functions.
397  */
398 
399 #ifdef USE_WIN32_LARGE_FILES
400 #  include <io.h>
401 #  include <sys/types.h>
402 #  include <sys/stat.h>
403 #  undef  lseek
404 #  define lseek(fdes,offset,whence)  _lseeki64(fdes, offset, whence)
405 #  undef  fstat
406 #  define fstat(fdes,stp)            _fstati64(fdes, stp)
407 #  undef  stat
408 #  define stat(fname,stp)            curlx_win32_stat(fname, stp)
409 #  define struct_stat                struct _stati64
410 #  define LSEEK_ERROR                (__int64)-1
411 #  define open                       curlx_win32_open
412 #  define fopen(fname,mode)          curlx_win32_fopen(fname, mode)
413    int curlx_win32_open(const char *filename, int oflag, ...);
414    int curlx_win32_stat(const char *path, struct_stat *buffer);
415    FILE *curlx_win32_fopen(const char *filename, const char *mode);
416 #endif
417 
418 /*
419  * Small file (<2Gb) support using WIN32 functions.
420  */
421 
422 #ifdef USE_WIN32_SMALL_FILES
423 #  include <io.h>
424 #  include <sys/types.h>
425 #  include <sys/stat.h>
426 #  ifndef _WIN32_WCE
427 #    undef  lseek
428 #    define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
429 #    define fstat(fdes,stp)            _fstat(fdes, stp)
430 #    define stat(fname,stp)            curlx_win32_stat(fname, stp)
431 #    define struct_stat                struct _stat
432 #    define open                       curlx_win32_open
433 #    define fopen(fname,mode)          curlx_win32_fopen(fname, mode)
434      int curlx_win32_stat(const char *path, struct_stat *buffer);
435      int curlx_win32_open(const char *filename, int oflag, ...);
436      FILE *curlx_win32_fopen(const char *filename, const char *mode);
437 #  endif
438 #  define LSEEK_ERROR                (long)-1
439 #endif
440 
441 #ifndef struct_stat
442 #  define struct_stat struct stat
443 #endif
444 
445 #ifndef LSEEK_ERROR
446 #  define LSEEK_ERROR (off_t)-1
447 #endif
448 
449 #ifndef SIZEOF_TIME_T
450 /* assume default size of time_t to be 32 bit */
451 #define SIZEOF_TIME_T 4
452 #endif
453 
454 #ifndef SIZEOF_CURL_SOCKET_T
455 /* configure and cmake check and set the define */
456 #  ifdef _WIN64
457 #    define SIZEOF_CURL_SOCKET_T 8
458 #  else
459 /* default guess */
460 #    define SIZEOF_CURL_SOCKET_T 4
461 #  endif
462 #endif
463 
464 #if SIZEOF_CURL_SOCKET_T < 8
465 #  define CURL_FORMAT_SOCKET_T "d"
466 #elif defined(__MINGW32__)
467 #  define CURL_FORMAT_SOCKET_T "zd"
468 #else
469 #  define CURL_FORMAT_SOCKET_T "qd"
470 #endif
471 
472 /*
473  * Default sizeof(off_t) in case it hasn't been defined in config file.
474  */
475 
476 #ifndef SIZEOF_OFF_T
477 #  if defined(__VMS) && !defined(__VAX)
478 #    if defined(_LARGEFILE)
479 #      define SIZEOF_OFF_T 8
480 #    endif
481 #  elif defined(__OS400__) && defined(__ILEC400__)
482 #    if defined(_LARGE_FILES)
483 #      define SIZEOF_OFF_T 8
484 #    endif
485 #  elif defined(__MVS__) && defined(__IBMC__)
486 #    if defined(_LP64) || defined(_LARGE_FILES)
487 #      define SIZEOF_OFF_T 8
488 #    endif
489 #  elif defined(__370__) && defined(__IBMC__)
490 #    if defined(_LP64) || defined(_LARGE_FILES)
491 #      define SIZEOF_OFF_T 8
492 #    endif
493 #  endif
494 #  ifndef SIZEOF_OFF_T
495 #    define SIZEOF_OFF_T 4
496 #  endif
497 #endif
498 
499 #if (SIZEOF_CURL_OFF_T < 8)
500 #error "too small curl_off_t"
501 #else
502    /* assume SIZEOF_CURL_OFF_T == 8 */
503 #  define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
504 #endif
505 #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
506 
507 #if (SIZEOF_CURL_OFF_T != 8)
508 #  error "curl_off_t must be exactly 64 bits"
509 #else
510   typedef unsigned CURL_TYPEOF_CURL_OFF_T curl_uint64_t;
511   typedef CURL_TYPEOF_CURL_OFF_T  curl_int64_t;
512 #  ifndef CURL_SUFFIX_CURL_OFF_TU
513 #    error "CURL_SUFFIX_CURL_OFF_TU must be defined"
514 #  endif
515 #  define CURL_UINT64_SUFFIX  CURL_SUFFIX_CURL_OFF_TU
516 #  define CURL_UINT64_C(val)  CURL_CONC_MACROS(val,CURL_UINT64_SUFFIX)
517 # define CURL_PRId64  CURL_FORMAT_CURL_OFF_T
518 # define CURL_PRIu64  CURL_FORMAT_CURL_OFF_TU
519 #endif
520 
521 #if (SIZEOF_TIME_T == 4)
522 #  ifdef HAVE_TIME_T_UNSIGNED
523 #  define TIME_T_MAX UINT_MAX
524 #  define TIME_T_MIN 0
525 #  else
526 #  define TIME_T_MAX INT_MAX
527 #  define TIME_T_MIN INT_MIN
528 #  endif
529 #else
530 #  ifdef HAVE_TIME_T_UNSIGNED
531 #  define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
532 #  define TIME_T_MIN 0
533 #  else
534 #  define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
535 #  define TIME_T_MIN (-TIME_T_MAX - 1)
536 #  endif
537 #endif
538 
539 #ifndef SIZE_T_MAX
540 /* some limits.h headers have this defined, some don't */
541 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
542 #define SIZE_T_MAX 18446744073709551615U
543 #else
544 #define SIZE_T_MAX 4294967295U
545 #endif
546 #endif
547 
548 #ifndef SSIZE_T_MAX
549 /* some limits.h headers have this defined, some don't */
550 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
551 #define SSIZE_T_MAX 9223372036854775807
552 #else
553 #define SSIZE_T_MAX 2147483647
554 #endif
555 #endif
556 
557 /*
558  * Arg 2 type for gethostname in case it hasn't been defined in config file.
559  */
560 
561 #ifndef GETHOSTNAME_TYPE_ARG2
562 #  ifdef USE_WINSOCK
563 #    define GETHOSTNAME_TYPE_ARG2 int
564 #  else
565 #    define GETHOSTNAME_TYPE_ARG2 size_t
566 #  endif
567 #endif
568 
569 /* Below we define some functions. They should
570 
571    4. set the SIGALRM signal timeout
572    5. set dir/file naming defines
573    */
574 
575 #ifdef _WIN32
576 
577 #  define DIR_CHAR      "\\"
578 
579 #else /* _WIN32 */
580 
581 #  ifdef MSDOS  /* Watt-32 */
582 
583 #    include <sys/ioctl.h>
584 #    define select(n,r,w,x,t) select_s(n,r,w,x,t)
585 #    define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
586 #    include <tcp.h>
587 #    ifdef word
588 #      undef word
589 #    endif
590 #    ifdef byte
591 #      undef byte
592 #    endif
593 
594 #  endif /* MSDOS */
595 
596 #  ifdef __minix
597      /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
598      extern char *strtok_r(char *s, const char *delim, char **last);
599      extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
600 #  endif
601 
602 #  define DIR_CHAR      "/"
603 
604 #endif /* _WIN32 */
605 
606 /* ---------------------------------------------------------------- */
607 /*             resolver specialty compile-time defines              */
608 /*         CURLRES_* defines to use in the host*.c sources          */
609 /* ---------------------------------------------------------------- */
610 
611 /*
612  * MSVC threads support requires a multi-threaded runtime library.
613  * _beginthreadex() is not available in single-threaded ones.
614  */
615 
616 #if defined(_MSC_VER) && !defined(_MT)
617 #  undef USE_THREADS_POSIX
618 #  undef USE_THREADS_WIN32
619 #endif
620 
621 /*
622  * Mutually exclusive CURLRES_* definitions.
623  */
624 
625 #if defined(USE_IPV6) && defined(HAVE_GETADDRINFO)
626 #  define CURLRES_IPV6
627 #elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__))
628 /* assume on Windows that IPv6 without getaddrinfo is a broken build */
629 #  error "Unexpected build: IPv6 is enabled but getaddrinfo was not found."
630 #else
631 #  define CURLRES_IPV4
632 #endif
633 
634 #ifdef USE_ARES
635 #  define CURLRES_ASYNCH
636 #  define CURLRES_ARES
637 /* now undef the stock libc functions just to avoid them being used */
638 #  undef HAVE_GETADDRINFO
639 #  undef HAVE_FREEADDRINFO
640 #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
641 #  define CURLRES_ASYNCH
642 #  define CURLRES_THREADED
643 #else
644 #  define CURLRES_SYNCH
645 #endif
646 
647 /* ---------------------------------------------------------------- */
648 
649 #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && \
650   !defined(USE_WIN32_IDN) && !defined(USE_APPLE_IDN)
651 /* The lib and header are present */
652 #define USE_LIBIDN2
653 #endif
654 
655 #if defined(USE_LIBIDN2) && (defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN))
656 #error "libidn2 cannot be enabled with WinIDN or AppleIDN, choose one."
657 #endif
658 
659 #define LIBIDN_REQUIRED_VERSION "0.4.1"
660 
661 #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
662   defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \
663   defined(USE_BEARSSL) || defined(USE_RUSTLS)
664 #define USE_SSL    /* SSL support has been enabled */
665 #endif
666 
667 /* Single point where USE_SPNEGO definition might be defined */
668 #if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \
669     (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
670 #define USE_SPNEGO
671 #endif
672 
673 /* Single point where USE_KERBEROS5 definition might be defined */
674 #if !defined(CURL_DISABLE_KERBEROS_AUTH) && \
675     (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
676 #define USE_KERBEROS5
677 #endif
678 
679 /* Single point where USE_NTLM definition might be defined */
680 #if !defined(CURL_DISABLE_NTLM)
681 #  if defined(USE_OPENSSL) || defined(USE_MBEDTLS) ||                   \
682   defined(USE_GNUTLS) || defined(USE_SECTRANSP) ||                      \
683   defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) ||              \
684   (defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT))
685 #    define USE_CURL_NTLM_CORE
686 #  endif
687 #  if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI)
688 #    define USE_NTLM
689 #  endif
690 #endif
691 
692 #ifdef CURL_WANTS_CA_BUNDLE_ENV
693 #error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
694 #endif
695 
696 #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) || defined(USE_WOLFSSH)
697 #define USE_SSH
698 #endif
699 
700 /*
701  * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
702  * Parameters should of course normally not be unused, but for example when
703  * we have multiple implementations of the same interface it may happen.
704  */
705 
706 #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
707   ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
708 #  define UNUSED_PARAM __attribute__((__unused__))
709 #  define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
710 #elif defined(__IAR_SYSTEMS_ICC__)
711 #  define UNUSED_PARAM __attribute__((__unused__))
712 #  if (__VER__ >= 9040001)
713 #    define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
714 #  else
715 #    define WARN_UNUSED_RESULT
716 #  endif
717 #else
718 #  define UNUSED_PARAM /* NOTHING */
719 #  define WARN_UNUSED_RESULT
720 #endif
721 
722 /* noreturn attribute */
723 
724 #if !defined(CURL_NORETURN)
725 #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \
726   defined(__IAR_SYSTEMS_ICC__)
727 #  define CURL_NORETURN  __attribute__((__noreturn__))
728 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
729 #  define CURL_NORETURN  __declspec(noreturn)
730 #else
731 #  define CURL_NORETURN
732 #endif
733 #endif
734 
735 /* fallthrough attribute */
736 
737 #if !defined(FALLTHROUGH)
738 #if (defined(__GNUC__) && __GNUC__ >= 7) || \
739     (defined(__clang__) && __clang_major__ >= 10)
740 #  define FALLTHROUGH()  __attribute__((fallthrough))
741 #else
742 #  define FALLTHROUGH()  do {} while (0)
743 #endif
744 #endif
745 
746 /*
747  * Include macros and defines that should only be processed once.
748  */
749 
750 #ifndef HEADER_CURL_SETUP_ONCE_H
751 #include "curl_setup_once.h"
752 #endif
753 
754 /*
755  * Definition of our NOP statement Object-like macro
756  */
757 
758 #ifndef Curl_nop_stmt
759 #  define Curl_nop_stmt do { } while(0)
760 #endif
761 
762 /*
763  * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
764  */
765 
766 #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
767 #  if defined(SOCKET) || defined(USE_WINSOCK)
768 #    error "WinSock and lwIP TCP/IP stack definitions shall not coexist!"
769 #  endif
770 #endif
771 
772 /*
773  * shutdown() flags for systems that don't define them
774  */
775 
776 #ifndef SHUT_RD
777 #define SHUT_RD 0x00
778 #endif
779 
780 #ifndef SHUT_WR
781 #define SHUT_WR 0x01
782 #endif
783 
784 #ifndef SHUT_RDWR
785 #define SHUT_RDWR 0x02
786 #endif
787 
788 /* Define S_ISREG if not defined by system headers, e.g. MSVC */
789 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
790 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
791 #endif
792 
793 /* Define S_ISDIR if not defined by system headers, e.g. MSVC */
794 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
795 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
796 #endif
797 
798 /* In Windows the default file mode is text but an application can override it.
799 Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
800 */
801 #if defined(_WIN32) || defined(MSDOS)
802 #define FOPEN_READTEXT "rt"
803 #define FOPEN_WRITETEXT "wt"
804 #define FOPEN_APPENDTEXT "at"
805 #elif defined(__CYGWIN__)
806 /* Cygwin has specific behavior we need to address when WIN32 is not defined.
807 https://cygwin.com/cygwin-ug-net/using-textbinary.html
808 For write we want our output to have line endings of LF and be compatible with
809 other Cygwin utilities. For read we want to handle input that may have line
810 endings either CRLF or LF so 't' is appropriate.
811 */
812 #define FOPEN_READTEXT "rt"
813 #define FOPEN_WRITETEXT "w"
814 #define FOPEN_APPENDTEXT "a"
815 #else
816 #define FOPEN_READTEXT "r"
817 #define FOPEN_WRITETEXT "w"
818 #define FOPEN_APPENDTEXT "a"
819 #endif
820 
821 /* for systems that don't detect this in configure */
822 #ifndef CURL_SA_FAMILY_T
823 #  if defined(HAVE_SA_FAMILY_T)
824 #    define CURL_SA_FAMILY_T sa_family_t
825 #  elif defined(HAVE_ADDRESS_FAMILY)
826 #    define CURL_SA_FAMILY_T ADDRESS_FAMILY
827 #  else
828 /* use a sensible default */
829 #    define CURL_SA_FAMILY_T unsigned short
830 #  endif
831 #endif
832 
833 /* Some convenience macros to get the larger/smaller value out of two given.
834    We prefix with CURL to prevent name collisions. */
835 #define CURLMAX(x,y) ((x)>(y)?(x):(y))
836 #define CURLMIN(x,y) ((x)<(y)?(x):(y))
837 
838 /* A convenience macro to provide both the string literal and the length of
839    the string literal in one go, useful for functions that take "string,len"
840    as their argument */
841 #define STRCONST(x) x,sizeof(x)-1
842 
843 /* Some versions of the Android SDK is missing the declaration */
844 #if defined(HAVE_GETPWUID_R) && defined(HAVE_DECL_GETPWUID_R_MISSING)
845 struct passwd;
846 int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
847                size_t buflen, struct passwd **result);
848 #endif
849 
850 #ifdef UNITTESTS
851 #define UNITTEST
852 #else
853 #define UNITTEST static
854 #endif
855 
856 /* Hyper supports HTTP2 also, but Curl's integration with Hyper does not */
857 #if defined(USE_NGHTTP2)
858 #define USE_HTTP2
859 #endif
860 
861 #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || \
862     (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \
863     defined(USE_QUICHE) || defined(USE_MSH3)
864 
865 #ifdef CURL_WITH_MULTI_SSL
866 #error "Multi-SSL combined with QUIC is not supported"
867 #endif
868 
869 #define USE_HTTP3
870 #endif
871 
872 /* Certain Windows implementations are not aligned with what curl expects,
873    so always use the local one on this platform. E.g. the mingw-w64
874    implementation can return wrong results for non-ASCII inputs. */
875 #if defined(HAVE_BASENAME) && defined(_WIN32)
876 #undef HAVE_BASENAME
877 #endif
878 
879 #if defined(USE_UNIX_SOCKETS) && defined(_WIN32)
880 #  if !defined(UNIX_PATH_MAX)
881      /* Replicating logic present in afunix.h
882         (distributed with newer Windows 10 SDK versions only) */
883 #    define UNIX_PATH_MAX 108
884      /* !checksrc! disable TYPEDEFSTRUCT 1 */
885      typedef struct sockaddr_un {
886        ADDRESS_FAMILY sun_family;
887        char sun_path[UNIX_PATH_MAX];
888      } SOCKADDR_UN, *PSOCKADDR_UN;
889 #    define WIN32_SOCKADDR_UN
890 #  endif
891 #endif
892 
893 /* OpenSSLv3 marks DES, MD5 and ENGINE functions deprecated but we have no
894    replacements (yet) so tell the compiler to not warn for them. */
895 #ifdef USE_OPENSSL
896 #define OPENSSL_SUPPRESS_DEPRECATED
897 #endif
898 
899 #if defined(inline)
900   /* 'inline' is defined as macro and assumed to be correct */
901   /* No need for 'inline' replacement */
902 #elif defined(__cplusplus)
903   /* The code is compiled with C++ compiler.
904      C++ always supports 'inline'. */
905   /* No need for 'inline' replacement */
906 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
907   /* C99 (and later) supports 'inline' keyword */
908   /* No need for 'inline' replacement */
909 #elif defined(__GNUC__) && __GNUC__ >= 3
910   /* GCC supports '__inline__' as an extension */
911 #  define inline __inline__
912 #elif defined(_MSC_VER) && _MSC_VER >= 1400
913   /* MSC supports '__inline' from VS 2005 (or even earlier) */
914 #  define inline __inline
915 #else
916   /* Probably 'inline' is not supported by compiler.
917      Define to the empty string to be on the safe side. */
918 #  define inline /* empty */
919 #endif
920 
921 #endif /* HEADER_CURL_SETUP_H */
922