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