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