xref: /aosp_15_r20/external/curl/lib/curl_setup.h (revision 6236dae45794135f37c4eb022389c904c8b0090d)
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, <[email protected]>, 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 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 /* Give calloc a chance to be dragging in early, so we do not redefine */
212 #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
213 #  include <pthread.h>
214 #endif
215 
216 /*
217  * Disable other protocols when http is the only one desired.
218  */
219 
220 #ifdef HTTP_ONLY
221 #  ifndef CURL_DISABLE_DICT
222 #    define CURL_DISABLE_DICT
223 #  endif
224 #  ifndef CURL_DISABLE_FILE
225 #    define CURL_DISABLE_FILE
226 #  endif
227 #  ifndef CURL_DISABLE_FTP
228 #    define CURL_DISABLE_FTP
229 #  endif
230 #  ifndef CURL_DISABLE_GOPHER
231 #    define CURL_DISABLE_GOPHER
232 #  endif
233 #  ifndef CURL_DISABLE_IMAP
234 #    define CURL_DISABLE_IMAP
235 #  endif
236 #  ifndef CURL_DISABLE_LDAP
237 #    define CURL_DISABLE_LDAP
238 #  endif
239 #  ifndef CURL_DISABLE_LDAPS
240 #    define CURL_DISABLE_LDAPS
241 #  endif
242 #  ifndef CURL_DISABLE_MQTT
243 #    define CURL_DISABLE_MQTT
244 #  endif
245 #  ifndef CURL_DISABLE_POP3
246 #    define CURL_DISABLE_POP3
247 #  endif
248 #  ifndef CURL_DISABLE_RTSP
249 #    define CURL_DISABLE_RTSP
250 #  endif
251 #  ifndef CURL_DISABLE_SMB
252 #    define CURL_DISABLE_SMB
253 #  endif
254 #  ifndef CURL_DISABLE_SMTP
255 #    define CURL_DISABLE_SMTP
256 #  endif
257 #  ifndef CURL_DISABLE_TELNET
258 #    define CURL_DISABLE_TELNET
259 #  endif
260 #  ifndef CURL_DISABLE_TFTP
261 #    define CURL_DISABLE_TFTP
262 #  endif
263 #endif
264 
265 /*
266  * When http is disabled rtsp is not supported.
267  */
268 
269 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
270 #  define CURL_DISABLE_RTSP
271 #endif
272 
273 /*
274  * When HTTP is disabled, disable HTTP-only features
275  */
276 
277 #if defined(CURL_DISABLE_HTTP)
278 #  define CURL_DISABLE_ALTSVC 1
279 #  define CURL_DISABLE_COOKIES 1
280 #  define CURL_DISABLE_BASIC_AUTH 1
281 #  define CURL_DISABLE_BEARER_AUTH 1
282 #  define CURL_DISABLE_AWS 1
283 #  define CURL_DISABLE_DOH 1
284 #  define CURL_DISABLE_FORM_API 1
285 #  define CURL_DISABLE_HEADERS_API 1
286 #  define CURL_DISABLE_HSTS 1
287 #  define CURL_DISABLE_HTTP_AUTH 1
288 #endif
289 
290 /* ================================================================ */
291 /* No system header file shall be included in this file before this */
292 /* point.                                                           */
293 /* ================================================================ */
294 
295 /*
296  * OS/400 setup file includes some system headers.
297  */
298 
299 #ifdef __OS400__
300 #  include "setup-os400.h"
301 #endif
302 
303 /*
304  * VMS setup file includes some system headers.
305  */
306 
307 #ifdef __VMS
308 #  include "setup-vms.h"
309 #endif
310 
311 /*
312  * Windows setup file includes some system headers.
313  */
314 
315 #ifdef _WIN32
316 #  include "setup-win32.h"
317 #endif
318 
319 #include <curl/system.h>
320 
321 /* Helper macro to expand and concatenate two macros.
322  * Direct macros concatenation does not work because macros
323  * are not expanded before direct concatenation.
324  */
325 #define CURL_CONC_MACROS_(A,B) A ## B
326 #define CURL_CONC_MACROS(A,B) CURL_CONC_MACROS_(A,B)
327 
328 /* curl uses its own printf() function internally. It understands the GNU
329  * format. Use this format, so that is matches the GNU format attribute we
330  * use with the MinGW compiler, allowing it to verify them at compile-time.
331  */
332 #ifdef  __MINGW32__
333 #  undef CURL_FORMAT_CURL_OFF_T
334 #  undef CURL_FORMAT_CURL_OFF_TU
335 #  define CURL_FORMAT_CURL_OFF_T   "lld"
336 #  define CURL_FORMAT_CURL_OFF_TU  "llu"
337 #endif
338 
339 /* based on logic in "curl/mprintf.h" */
340 
341 #if (defined(__GNUC__) || defined(__clang__) ||                         \
342   defined(__IAR_SYSTEMS_ICC__)) &&                                      \
343   defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) &&         \
344   !defined(CURL_NO_FMT_CHECKS)
345 #if defined(__MINGW32__) && !defined(__clang__)
346 #define CURL_PRINTF(fmt, arg) \
347   __attribute__((format(gnu_printf, fmt, arg)))
348 #else
349 #define CURL_PRINTF(fmt, arg) \
350   __attribute__((format(__printf__, fmt, arg)))
351 #endif
352 #else
353 #define CURL_PRINTF(fmt, arg)
354 #endif
355 
356 /* Override default printf mask check rules in "curl/mprintf.h" */
357 #define CURL_TEMP_PRINTF CURL_PRINTF
358 
359 /* Workaround for mainline llvm v16 and earlier missing a built-in macro
360    expected by macOS SDK v14 / Xcode v15 (2023) and newer.
361    gcc (as of v14) is also missing it. */
362 #if defined(__APPLE__) &&                                   \
363   ((!defined(__apple_build_version__) &&                    \
364     defined(__clang__) && __clang_major__ < 17) ||          \
365    (defined(__GNUC__) && __GNUC__ <= 14)) &&                \
366   defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
367   !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__)
368 #define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__             \
369   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
370 #endif
371 
372 /*
373  * Use getaddrinfo to resolve the IPv4 address literal. If the current network
374  * interface does not support IPv4, but supports IPv6, NAT64, and DNS64,
375  * performing this task will result in a synthesized IPv6 address.
376  */
377 #if defined(__APPLE__) && !defined(USE_ARES)
378 #define USE_RESOLVE_ON_IPS 1
379 #  if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
380      defined(USE_IPV6)
381 #    define CURL_MACOS_CALL_COPYPROXIES 1
382 #  endif
383 #endif
384 
385 #ifdef USE_LWIPSOCK
386 #  include <lwip/init.h>
387 #  include <lwip/sockets.h>
388 #  include <lwip/netdb.h>
389 #endif
390 
391 #ifdef HAVE_EXTRA_STRICMP_H
392 #  include <extra/stricmp.h>
393 #endif
394 
395 #ifdef HAVE_EXTRA_STRDUP_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 /*
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 /*
481  * Small file (<2Gb) support using Win32 functions.
482  */
483 
484 #ifdef USE_WIN32_SMALL_FILES
485 #  include <io.h>
486 #  include <sys/types.h>
487 #  include <sys/stat.h>
488 #  ifndef _WIN32_WCE
489 #    undef  lseek
490 #    define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
491 #    define fstat(fdes,stp)            _fstat(fdes, stp)
492 #    define stat(fname,stp)            curlx_win32_stat(fname, stp)
493 #    define struct_stat                struct _stat
494 #    define open                       curlx_win32_open
495 #    define fopen(fname,mode)          curlx_win32_fopen(fname, mode)
496      int curlx_win32_stat(const char *path, struct_stat *buffer);
497      int curlx_win32_open(const char *filename, int oflag, ...);
498      FILE *curlx_win32_fopen(const char *filename, const char *mode);
499 #  endif
500 #  define LSEEK_ERROR                (long)-1
501 #endif
502 
503 #ifndef struct_stat
504 #  define struct_stat struct stat
505 #endif
506 
507 #ifndef LSEEK_ERROR
508 #  define LSEEK_ERROR (off_t)-1
509 #endif
510 
511 #ifndef SIZEOF_TIME_T
512 /* assume default size of time_t to be 32 bits */
513 #define SIZEOF_TIME_T 4
514 #endif
515 
516 #ifndef SIZEOF_CURL_SOCKET_T
517 /* configure and cmake check and set the define */
518 #  ifdef _WIN64
519 #    define SIZEOF_CURL_SOCKET_T 8
520 #  else
521 /* default guess */
522 #    define SIZEOF_CURL_SOCKET_T 4
523 #  endif
524 #endif
525 
526 #if SIZEOF_CURL_SOCKET_T < 8
527 #  define FMT_SOCKET_T "d"
528 #elif defined(__MINGW32__)
529 #  define FMT_SOCKET_T "zd"
530 #else
531 #  define FMT_SOCKET_T "qd"
532 #endif
533 
534 /*
535  * Default sizeof(off_t) in case it has not been defined in config file.
536  */
537 
538 #ifndef SIZEOF_OFF_T
539 #  if defined(__VMS) && !defined(__VAX)
540 #    if defined(_LARGEFILE)
541 #      define SIZEOF_OFF_T 8
542 #    endif
543 #  elif defined(__OS400__) && defined(__ILEC400__)
544 #    if defined(_LARGE_FILES)
545 #      define SIZEOF_OFF_T 8
546 #    endif
547 #  elif defined(__MVS__) && defined(__IBMC__)
548 #    if defined(_LP64) || defined(_LARGE_FILES)
549 #      define SIZEOF_OFF_T 8
550 #    endif
551 #  elif defined(__370__) && defined(__IBMC__)
552 #    if defined(_LP64) || defined(_LARGE_FILES)
553 #      define SIZEOF_OFF_T 8
554 #    endif
555 #  endif
556 #  ifndef SIZEOF_OFF_T
557 #    define SIZEOF_OFF_T 4
558 #  endif
559 #endif
560 
561 #if (SIZEOF_CURL_OFF_T < 8)
562 #error "too small curl_off_t"
563 #else
564    /* assume SIZEOF_CURL_OFF_T == 8 */
565 #  define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
566 #endif
567 #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
568 
569 #if (SIZEOF_CURL_OFF_T != 8)
570 #  error "curl_off_t must be exactly 64 bits"
571 #else
572   typedef unsigned CURL_TYPEOF_CURL_OFF_T curl_uint64_t;
573   typedef CURL_TYPEOF_CURL_OFF_T  curl_int64_t;
574 #  ifndef CURL_SUFFIX_CURL_OFF_TU
575 #    error "CURL_SUFFIX_CURL_OFF_TU must be defined"
576 #  endif
577 #  define CURL_UINT64_SUFFIX  CURL_SUFFIX_CURL_OFF_TU
578 #  define CURL_UINT64_C(val)  CURL_CONC_MACROS(val,CURL_UINT64_SUFFIX)
579 # define FMT_PRId64  CURL_FORMAT_CURL_OFF_T
580 # define FMT_PRIu64  CURL_FORMAT_CURL_OFF_TU
581 #endif
582 
583 #define FMT_OFF_T CURL_FORMAT_CURL_OFF_T
584 #define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU
585 
586 #if (SIZEOF_TIME_T == 4)
587 #  ifdef HAVE_TIME_T_UNSIGNED
588 #  define TIME_T_MAX UINT_MAX
589 #  define TIME_T_MIN 0
590 #  else
591 #  define TIME_T_MAX INT_MAX
592 #  define TIME_T_MIN INT_MIN
593 #  endif
594 #else
595 #  ifdef HAVE_TIME_T_UNSIGNED
596 #  define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
597 #  define TIME_T_MIN 0
598 #  else
599 #  define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
600 #  define TIME_T_MIN (-TIME_T_MAX - 1)
601 #  endif
602 #endif
603 
604 #ifndef SIZE_T_MAX
605 /* some limits.h headers have this defined, some do not */
606 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
607 #define SIZE_T_MAX 18446744073709551615U
608 #else
609 #define SIZE_T_MAX 4294967295U
610 #endif
611 #endif
612 
613 #ifndef SSIZE_T_MAX
614 /* some limits.h headers have this defined, some do not */
615 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
616 #define SSIZE_T_MAX 9223372036854775807
617 #else
618 #define SSIZE_T_MAX 2147483647
619 #endif
620 #endif
621 
622 /*
623  * Arg 2 type for gethostname in case it has not been defined in config file.
624  */
625 
626 #ifndef GETHOSTNAME_TYPE_ARG2
627 #  ifdef USE_WINSOCK
628 #    define GETHOSTNAME_TYPE_ARG2 int
629 #  else
630 #    define GETHOSTNAME_TYPE_ARG2 size_t
631 #  endif
632 #endif
633 
634 /* Below we define some functions. They should
635 
636    4. set the SIGALRM signal timeout
637    5. set dir/file naming defines
638    */
639 
640 #ifdef _WIN32
641 
642 #  define DIR_CHAR      "\\"
643 
644 #else /* _WIN32 */
645 
646 #  ifdef MSDOS  /* Watt-32 */
647 
648 #    include <sys/ioctl.h>
649 #    define select(n,r,w,x,t) select_s(n,r,w,x,t)
650 #    define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
651 #    include <tcp.h>
652 #    ifdef word
653 #      undef word
654 #    endif
655 #    ifdef byte
656 #      undef byte
657 #    endif
658 
659 #  endif /* MSDOS */
660 
661 #  ifdef __minix
662      /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
663      extern char *strtok_r(char *s, const char *delim, char **last);
664      extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
665 #  endif
666 
667 #  define DIR_CHAR      "/"
668 
669 #endif /* _WIN32 */
670 
671 /* ---------------------------------------------------------------- */
672 /*             resolver specialty compile-time defines              */
673 /*         CURLRES_* defines to use in the host*.c sources          */
674 /* ---------------------------------------------------------------- */
675 
676 /*
677  * MSVC threads support requires a multi-threaded runtime library.
678  * _beginthreadex() is not available in single-threaded ones.
679  */
680 
681 #if defined(_MSC_VER) && !defined(_MT)
682 #  undef USE_THREADS_POSIX
683 #  undef USE_THREADS_WIN32
684 #endif
685 
686 /*
687  * Mutually exclusive CURLRES_* definitions.
688  */
689 
690 #if defined(USE_IPV6) && defined(HAVE_GETADDRINFO)
691 #  define CURLRES_IPV6
692 #elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__))
693 /* assume on Windows that IPv6 without getaddrinfo is a broken build */
694 #  error "Unexpected build: IPv6 is enabled but getaddrinfo was not found."
695 #else
696 #  define CURLRES_IPV4
697 #endif
698 
699 #ifdef USE_ARES
700 #  define CURLRES_ASYNCH
701 #  define CURLRES_ARES
702 /* now undef the stock libc functions just to avoid them being used */
703 #  undef HAVE_GETADDRINFO
704 #  undef HAVE_FREEADDRINFO
705 #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
706 #  define CURLRES_ASYNCH
707 #  define CURLRES_THREADED
708 #else
709 #  define CURLRES_SYNCH
710 #endif
711 
712 /* ---------------------------------------------------------------- */
713 
714 #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && \
715   !defined(USE_WIN32_IDN) && !defined(USE_APPLE_IDN)
716 /* The lib and header are present */
717 #define USE_LIBIDN2
718 #endif
719 
720 #if defined(USE_LIBIDN2) && (defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN))
721 #error "libidn2 cannot be enabled with WinIDN or AppleIDN, choose one."
722 #endif
723 
724 #define LIBIDN_REQUIRED_VERSION "0.4.1"
725 
726 #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
727   defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \
728   defined(USE_BEARSSL) || defined(USE_RUSTLS)
729 #define USE_SSL    /* SSL support has been enabled */
730 #endif
731 
732 #if defined(USE_WOLFSSL) && defined(USE_GNUTLS)
733 /* Avoid defining unprefixed wolfSSL SHA macros colliding with nettle ones */
734 #define NO_OLD_WC_NAMES
735 #endif
736 
737 /* Single point where USE_SPNEGO definition might be defined */
738 #if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \
739     (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
740 #define USE_SPNEGO
741 #endif
742 
743 /* Single point where USE_KERBEROS5 definition might be defined */
744 #if !defined(CURL_DISABLE_KERBEROS_AUTH) && \
745     (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
746 #define USE_KERBEROS5
747 #endif
748 
749 /* Single point where USE_NTLM definition might be defined */
750 #if !defined(CURL_DISABLE_NTLM)
751 #  if defined(USE_OPENSSL) || defined(USE_MBEDTLS) ||                   \
752   defined(USE_GNUTLS) || defined(USE_SECTRANSP) ||                      \
753   defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) ||              \
754   (defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT))
755 #    define USE_CURL_NTLM_CORE
756 #  endif
757 #  if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI)
758 #    define USE_NTLM
759 #  endif
760 #endif
761 
762 #ifdef CURL_WANTS_CA_BUNDLE_ENV
763 #error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
764 #endif
765 
766 #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) || defined(USE_WOLFSSH)
767 #define USE_SSH
768 #endif
769 
770 /*
771  * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
772  * Parameters should of course normally not be unused, but for example when
773  * we have multiple implementations of the same interface it may happen.
774  */
775 
776 #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
777   ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
778 #  define UNUSED_PARAM __attribute__((__unused__))
779 #  define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
780 #elif defined(__IAR_SYSTEMS_ICC__)
781 #  define UNUSED_PARAM __attribute__((__unused__))
782 #  if (__VER__ >= 9040001)
783 #    define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
784 #  else
785 #    define WARN_UNUSED_RESULT
786 #  endif
787 #else
788 #  define UNUSED_PARAM /* NOTHING */
789 #  define WARN_UNUSED_RESULT
790 #endif
791 
792 /* noreturn attribute */
793 
794 #if !defined(CURL_NORETURN)
795 #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \
796   defined(__IAR_SYSTEMS_ICC__)
797 #  define CURL_NORETURN  __attribute__((__noreturn__))
798 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
799 #  define CURL_NORETURN  __declspec(noreturn)
800 #else
801 #  define CURL_NORETURN
802 #endif
803 #endif
804 
805 /* fallthrough attribute */
806 
807 #if !defined(FALLTHROUGH)
808 #if (defined(__GNUC__) && __GNUC__ >= 7) || \
809     (defined(__clang__) && __clang_major__ >= 10)
810 #  define FALLTHROUGH()  __attribute__((fallthrough))
811 #else
812 #  define FALLTHROUGH()  do {} while (0)
813 #endif
814 #endif
815 
816 /*
817  * Include macros and defines that should only be processed once.
818  */
819 
820 #ifndef HEADER_CURL_SETUP_ONCE_H
821 #include "curl_setup_once.h"
822 #endif
823 
824 /*
825  * Definition of our NOP statement Object-like macro
826  */
827 
828 #ifndef Curl_nop_stmt
829 #  define Curl_nop_stmt do { } while(0)
830 #endif
831 
832 /*
833  * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
834  */
835 
836 #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
837 #  if defined(SOCKET) || defined(USE_WINSOCK)
838 #    error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
839 #  endif
840 #endif
841 
842 /*
843  * shutdown() flags for systems that do not define them
844  */
845 
846 #ifndef SHUT_RD
847 #define SHUT_RD 0x00
848 #endif
849 
850 #ifndef SHUT_WR
851 #define SHUT_WR 0x01
852 #endif
853 
854 #ifndef SHUT_RDWR
855 #define SHUT_RDWR 0x02
856 #endif
857 
858 /* Define S_ISREG if not defined by system headers, e.g. MSVC */
859 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
860 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
861 #endif
862 
863 /* Define S_ISDIR if not defined by system headers, e.g. MSVC */
864 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
865 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
866 #endif
867 
868 /* In Windows the default file mode is text but an application can override it.
869 Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
870 */
871 #if defined(_WIN32) || defined(MSDOS)
872 #define FOPEN_READTEXT "rt"
873 #define FOPEN_WRITETEXT "wt"
874 #define FOPEN_APPENDTEXT "at"
875 #elif defined(__CYGWIN__)
876 /* Cygwin has specific behavior we need to address when _WIN32 is not defined.
877 https://cygwin.com/cygwin-ug-net/using-textbinary.html
878 For write we want our output to have line endings of LF and be compatible with
879 other Cygwin utilities. For read we want to handle input that may have line
880 endings either CRLF or LF so 't' is appropriate.
881 */
882 #define FOPEN_READTEXT "rt"
883 #define FOPEN_WRITETEXT "w"
884 #define FOPEN_APPENDTEXT "a"
885 #else
886 #define FOPEN_READTEXT "r"
887 #define FOPEN_WRITETEXT "w"
888 #define FOPEN_APPENDTEXT "a"
889 #endif
890 
891 /* for systems that do not detect this in configure */
892 #ifndef CURL_SA_FAMILY_T
893 #  if defined(HAVE_SA_FAMILY_T)
894 #    define CURL_SA_FAMILY_T sa_family_t
895 #  elif defined(HAVE_ADDRESS_FAMILY)
896 #    define CURL_SA_FAMILY_T ADDRESS_FAMILY
897 #  else
898 /* use a sensible default */
899 #    define CURL_SA_FAMILY_T unsigned short
900 #  endif
901 #endif
902 
903 /* Some convenience macros to get the larger/smaller value out of two given.
904    We prefix with CURL to prevent name collisions. */
905 #define CURLMAX(x,y) ((x)>(y)?(x):(y))
906 #define CURLMIN(x,y) ((x)<(y)?(x):(y))
907 
908 /* A convenience macro to provide both the string literal and the length of
909    the string literal in one go, useful for functions that take "string,len"
910    as their argument */
911 #define STRCONST(x) x,sizeof(x)-1
912 
913 /* Some versions of the Android SDK is missing the declaration */
914 #if defined(HAVE_GETPWUID_R) && defined(HAVE_DECL_GETPWUID_R_MISSING)
915 struct passwd;
916 int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
917                size_t buflen, struct passwd **result);
918 #endif
919 
920 #ifdef UNITTESTS
921 #define UNITTEST
922 #else
923 #define UNITTEST static
924 #endif
925 
926 /* Hyper supports HTTP2 also, but Curl's integration with Hyper does not */
927 #if defined(USE_NGHTTP2)
928 #define USE_HTTP2
929 #endif
930 
931 #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || \
932     (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \
933     defined(USE_QUICHE) || defined(USE_MSH3)
934 
935 #ifdef CURL_WITH_MULTI_SSL
936 #error "Multi-SSL combined with QUIC is not supported"
937 #endif
938 
939 #define USE_HTTP3
940 #endif
941 
942 /* Certain Windows implementations are not aligned with what curl expects,
943    so always use the local one on this platform. E.g. the mingw-w64
944    implementation can return wrong results for non-ASCII inputs. */
945 #if defined(HAVE_BASENAME) && defined(_WIN32)
946 #undef HAVE_BASENAME
947 #endif
948 
949 #if defined(USE_UNIX_SOCKETS) && defined(_WIN32)
950 #  if !defined(UNIX_PATH_MAX)
951      /* Replicating logic present in afunix.h
952         (distributed with newer Windows 10 SDK versions only) */
953 #    define UNIX_PATH_MAX 108
954      /* !checksrc! disable TYPEDEFSTRUCT 1 */
955      typedef struct sockaddr_un {
956        ADDRESS_FAMILY sun_family;
957        char sun_path[UNIX_PATH_MAX];
958      } SOCKADDR_UN, *PSOCKADDR_UN;
959 #    define WIN32_SOCKADDR_UN
960 #  endif
961 #endif
962 
963 /* OpenSSLv3 marks DES, MD5 and ENGINE functions deprecated but we have no
964    replacements (yet) so tell the compiler to not warn for them. */
965 #ifdef USE_OPENSSL
966 #define OPENSSL_SUPPRESS_DEPRECATED
967 #endif
968 
969 #if defined(inline)
970   /* 'inline' is defined as macro and assumed to be correct */
971   /* No need for 'inline' replacement */
972 #elif defined(__cplusplus)
973   /* The code is compiled with C++ compiler.
974      C++ always supports 'inline'. */
975   /* No need for 'inline' replacement */
976 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
977   /* C99 (and later) supports 'inline' keyword */
978   /* No need for 'inline' replacement */
979 #elif defined(__GNUC__) && __GNUC__ >= 3
980   /* GCC supports '__inline__' as an extension */
981 #  define inline __inline__
982 #elif defined(_MSC_VER) && _MSC_VER >= 1400
983   /* MSC supports '__inline' from VS 2005 (or even earlier) */
984 #  define inline __inline
985 #else
986   /* Probably 'inline' is not supported by compiler.
987      Define to the empty string to be on the safe side. */
988 #  define inline /* empty */
989 #endif
990 
991 #endif /* HEADER_CURL_SETUP_H */
992