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