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