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