1 #ifndef HEADER_CURL_SETUP_H
2 #define HEADER_CURL_SETUP_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
25 #if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES)
26 #define CURL_NO_OLDIES
30 * Disable Visual Studio warnings:
31 * 4127 "conditional expression is constant"
34 #pragma warning(disable:4127)
38 * Define WIN32 when build target is Win32 API
41 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
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.
51 # ifndef WIN32_LEAN_AND_MEAN
52 # define WIN32_LEAN_AND_MEAN
60 * Include configuration script results or hand-crafted
61 * configuration file for platforms which lack config tool.
66 #include "curl_config.h"
68 #else /* HAVE_CONFIG_H */
71 # include "config-win32ce.h"
74 # include "config-win32.h"
78 #if defined(macintosh) && defined(__MRC__)
79 # include "config-mac.h"
83 # include "config-riscos.h"
87 # include "config-amigaos.h"
91 # include "config-os400.h"
95 # include "config-tpf.h"
99 # include "config-vxworks.h"
103 # include "config-plan9.h"
106 #endif /* HAVE_CONFIG_H */
108 /* ================================================================ */
109 /* Definition of preprocessor macros/symbols which modify compiler */
110 /* behavior or generated code characteristics must be done here, */
111 /* as appropriate, before any system header file is included. It is */
112 /* also possible to have them defined in the config file included */
113 /* before this point. As a result of all this we frown inclusion of */
114 /* system header files in our config files, avoid this at any cost. */
115 /* ================================================================ */
118 * AIX 4.3 and newer needs _THREAD_SAFE defined to build
119 * proper reentrant code. Others may also need it.
122 #ifdef NEED_THREAD_SAFE
123 # ifndef _THREAD_SAFE
124 # define _THREAD_SAFE
129 * Tru64 needs _REENTRANT set for a few function prototypes and
130 * things to appear in the system header files. Unixware needs it
131 * to build proper reentrant code. Others may also need it.
134 #ifdef NEED_REENTRANT
140 /* Solaris needs this to get a POSIX-conformant getpwuid_r */
141 #if defined(sun) || defined(__sun)
142 # ifndef _POSIX_PTHREAD_SEMANTICS
143 # define _POSIX_PTHREAD_SEMANTICS 1
147 /* ================================================================ */
148 /* If you need to include a system header file for your platform, */
149 /* please, do it beyond the point further indicated in this file. */
150 /* ================================================================ */
152 #include <curl/curl.h>
154 #define CURL_SIZEOF_CURL_OFF_T SIZEOF_CURL_OFF_T
157 * Disable other protocols when http is the only one desired.
161 # ifndef CURL_DISABLE_TFTP
162 # define CURL_DISABLE_TFTP
164 # ifndef CURL_DISABLE_FTP
165 # define CURL_DISABLE_FTP
167 # ifndef CURL_DISABLE_LDAP
168 # define CURL_DISABLE_LDAP
170 # ifndef CURL_DISABLE_TELNET
171 # define CURL_DISABLE_TELNET
173 # ifndef CURL_DISABLE_DICT
174 # define CURL_DISABLE_DICT
176 # ifndef CURL_DISABLE_FILE
177 # define CURL_DISABLE_FILE
179 # ifndef CURL_DISABLE_RTSP
180 # define CURL_DISABLE_RTSP
182 # ifndef CURL_DISABLE_POP3
183 # define CURL_DISABLE_POP3
185 # ifndef CURL_DISABLE_IMAP
186 # define CURL_DISABLE_IMAP
188 # ifndef CURL_DISABLE_SMTP
189 # define CURL_DISABLE_SMTP
191 # ifndef CURL_DISABLE_GOPHER
192 # define CURL_DISABLE_GOPHER
194 # ifndef CURL_DISABLE_SMB
195 # define CURL_DISABLE_SMB
200 * When http is disabled rtsp is not supported.
203 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
204 # define CURL_DISABLE_RTSP
207 /* ================================================================ */
208 /* No system header file shall be included in this file before this */
209 /* point. The only allowed ones are those included from curl/system.h */
210 /* ================================================================ */
213 * OS/400 setup file includes some system headers.
217 # include "setup-os400.h"
221 * VMS setup file includes some system headers.
225 # include "setup-vms.h"
229 * Windows setup file includes some system headers.
232 #ifdef HAVE_WINDOWS_H
233 # include "setup-win32.h"
237 * Use getaddrinfo to resolve the IPv4 address literal. If the current network
238 * interface doesn't support IPv4, but supports IPv6, NAT64, and DNS64,
239 * performing this task will result in a synthesized IPv6 address.
242 #define USE_RESOLVE_ON_IPS 1
246 # include <lwip/init.h>
247 # include <lwip/sockets.h>
248 # include <lwip/netdb.h>
251 #ifdef HAVE_EXTRA_STRICMP_H
252 # include <extra/stricmp.h>
255 #ifdef HAVE_EXTRA_STRDUP_H
256 # include <extra/strdup.h>
260 # include <strings.h> /* for bzero, strcasecmp, and strncasecmp */
261 # include <string.h> /* for strcpy and strlen */
262 # include <stdlib.h> /* for rand and srand */
263 # include <sys/socket.h> /* for select and ioctl*/
264 # include <netdb.h> /* for in_addr_t definition */
265 # include <tpf/sysapi.h> /* for tpf_process_signals */
266 /* change which select is used for libcurl */
267 # define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
271 # include <sockLib.h> /* for generic BSD socket functions */
272 # include <ioLib.h> /* for basic I/O interface functions */
276 # include <exec/types.h>
277 # include <exec/execbase.h>
278 # include <proto/exec.h>
279 # include <proto/dos.h>
280 # ifdef HAVE_PROTO_BSDSOCKET_H
281 # include <proto/bsdsocket.h> /* ensure bsdsocket.library use */
282 # define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
291 #ifdef __TANDEM /* for nsr-tandem-nsk systems */
295 #ifndef STDC_HEADERS /* no standard C headers! */
296 #include <curl/stdcheaders.h>
300 # include <sys/types.h>
302 # define sys_nerr EILSEQ
306 * Salford-C kludge section (mostly borrowed from wxWidgets).
309 #pragma suppress 353 /* Possible nested comments */
310 #pragma suppress 593 /* Define not used */
311 #pragma suppress 61 /* enum has no name */
312 #pragma suppress 106 /* unnamed, unused parameter */
317 * Large file (>2Gb) support using WIN32 functions.
320 #ifdef USE_WIN32_LARGE_FILES
322 # include <sys/types.h>
323 # include <sys/stat.h>
325 # define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
327 # define fstat(fdes,stp) _fstati64(fdes, stp)
329 # define stat(fname,stp) curlx_win32_stat(fname, stp)
330 # define struct_stat struct _stati64
331 # define LSEEK_ERROR (__int64)-1
332 # define fopen(fname,mode) curlx_win32_fopen(fname, mode)
333 # define access(fname,mode) curlx_win32_access(fname, mode)
334 int curlx_win32_stat(const char *path, struct_stat *buffer);
335 FILE *curlx_win32_fopen(const char *filename, const char *mode);
336 int curlx_win32_access(const char *path, int mode);
340 * Small file (<2Gb) support using WIN32 functions.
343 #ifdef USE_WIN32_SMALL_FILES
345 # include <sys/types.h>
346 # include <sys/stat.h>
349 # define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
350 # define fstat(fdes,stp) _fstat(fdes, stp)
351 # define stat(fname,stp) curlx_win32_stat(fname, stp)
352 # define struct_stat struct _stat
353 # define fopen(fname,mode) curlx_win32_fopen(fname, mode)
354 # define access(fname,mode) curlx_win32_access(fname, mode)
355 int curlx_win32_stat(const char *path, struct_stat *buffer);
356 FILE *curlx_win32_fopen(const char *filename, const char *mode);
357 int curlx_win32_access(const char *path, int mode);
359 # define LSEEK_ERROR (long)-1
363 # define struct_stat struct stat
367 # define LSEEK_ERROR (off_t)-1
370 #ifndef SIZEOF_TIME_T
371 /* assume default size of time_t to be 32 bit */
372 #define SIZEOF_TIME_T 4
376 * Default sizeof(off_t) in case it hasn't been defined in config file.
380 # if defined(__VMS) && !defined(__VAX)
381 # if defined(_LARGEFILE)
382 # define SIZEOF_OFF_T 8
384 # elif defined(__OS400__) && defined(__ILEC400__)
385 # if defined(_LARGE_FILES)
386 # define SIZEOF_OFF_T 8
388 # elif defined(__MVS__) && defined(__IBMC__)
389 # if defined(_LP64) || defined(_LARGE_FILES)
390 # define SIZEOF_OFF_T 8
392 # elif defined(__370__) && defined(__IBMC__)
393 # if defined(_LP64) || defined(_LARGE_FILES)
394 # define SIZEOF_OFF_T 8
397 # ifndef SIZEOF_OFF_T
398 # define SIZEOF_OFF_T 4
402 #if (SIZEOF_CURL_OFF_T == 4)
403 # define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
405 /* assume CURL_SIZEOF_CURL_OFF_T == 8 */
406 # define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
408 #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
410 #if (SIZEOF_TIME_T == 4)
411 # ifdef HAVE_TIME_T_UNSIGNED
412 # define TIME_T_MAX UINT_MAX
413 # define TIME_T_MIN 0
415 # define TIME_T_MAX INT_MAX
416 # define TIME_T_MIN INT_MIN
419 # ifdef HAVE_TIME_T_UNSIGNED
420 # define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
421 # define TIME_T_MIN 0
423 # define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
424 # define TIME_T_MIN (-TIME_T_MAX - 1)
429 /* some limits.h headers have this defined, some don't */
430 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
431 #define SIZE_T_MAX 18446744073709551615U
433 #define SIZE_T_MAX 4294967295U
438 * Arg 2 type for gethostname in case it hasn't been defined in config file.
441 #ifndef GETHOSTNAME_TYPE_ARG2
443 # define GETHOSTNAME_TYPE_ARG2 int
445 # define GETHOSTNAME_TYPE_ARG2 size_t
449 /* Below we define some functions. They should
451 4. set the SIGALRM signal timeout
452 5. set dir/file naming defines
457 # define DIR_CHAR "\\"
461 # ifdef MSDOS /* Watt-32 */
463 # include <sys/ioctl.h>
464 # define select(n,r,w,x,t) select_s(n,r,w,x,t)
465 # define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
477 /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
478 extern char *strtok_r(char *s, const char *delim, char **last);
479 extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
482 # define DIR_CHAR "/"
484 # ifndef fileno /* sunos 4 have this as a macro! */
485 int fileno(FILE *stream);
491 * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
492 * defined in ws2tcpip.h as well as to provide IPv6 support.
493 * Does not apply if lwIP is used.
496 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(USE_LWIPSOCK)
497 # if !defined(HAVE_WS2TCPIP_H) || \
498 ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
499 # undef HAVE_GETADDRINFO_THREADSAFE
500 # undef HAVE_FREEADDRINFO
501 # undef HAVE_GETADDRINFO
502 # undef HAVE_GETNAMEINFO
507 /* ---------------------------------------------------------------- */
508 /* resolver specialty compile-time defines */
509 /* CURLRES_* defines to use in the host*.c sources */
510 /* ---------------------------------------------------------------- */
513 * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
516 #if defined(__LCC__) && defined(WIN32)
517 # undef USE_THREADS_POSIX
518 # undef USE_THREADS_WIN32
522 * MSVC threads support requires a multi-threaded runtime library.
523 * _beginthreadex() is not available in single-threaded ones.
526 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
527 # undef USE_THREADS_POSIX
528 # undef USE_THREADS_WIN32
532 * Mutually exclusive CURLRES_* definitions.
535 #if defined(ENABLE_IPV6) && defined(HAVE_GETADDRINFO)
536 # define CURLRES_IPV6
538 # define CURLRES_IPV4
542 # define CURLRES_ASYNCH
543 # define CURLRES_ARES
544 /* now undef the stock libc functions just to avoid them being used */
545 # undef HAVE_GETADDRINFO
546 # undef HAVE_FREEADDRINFO
547 # undef HAVE_GETHOSTBYNAME
548 #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
549 # define CURLRES_ASYNCH
550 # define CURLRES_THREADED
552 # define CURLRES_SYNCH
555 /* ---------------------------------------------------------------- */
558 * msvc 6.0 does not have struct sockaddr_storage and
559 * does not define IPPROTO_ESP in winsock2.h. But both
560 * are available if PSDK is properly installed.
563 #if defined(_MSC_VER) && !defined(__POCC__)
564 # if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
565 # undef HAVE_STRUCT_SOCKADDR_STORAGE
570 * Intentionally fail to build when using msvc 6.0 without PSDK installed.
571 * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
572 * in lib/config-win32.h although absolutely discouraged and unsupported.
575 #if defined(_MSC_VER) && !defined(__POCC__)
576 # if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
577 # if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
578 # error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
579 "Windows Server 2003 PSDK"
581 # define CURL_DISABLE_LDAP 1
587 int netware_init(void);
588 #ifndef __NOVELL_LIBC__
589 #include <sys/bsdskt.h>
590 #include <sys/timeval.h>
594 #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && !defined(USE_WIN32_IDN)
595 /* The lib and header are present */
599 #if defined(USE_LIBIDN2) && defined(USE_WIN32_IDN)
600 #error "Both libidn2 and WinIDN are enabled, choose one."
603 #define LIBIDN_REQUIRED_VERSION "0.4.1"
605 #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_NSS) || \
606 defined(USE_MBEDTLS) || \
607 defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || \
608 defined(USE_SECTRANSP) || defined(USE_GSKIT) || defined(USE_MESALINK) || \
610 #define USE_SSL /* SSL support has been enabled */
613 /* Single point where USE_SPNEGO definition might be defined */
614 #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
615 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
619 /* Single point where USE_KERBEROS5 definition might be defined */
620 #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
621 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
622 #define USE_KERBEROS5
625 /* Single point where USE_NTLM definition might be defined */
626 #if !defined(CURL_DISABLE_NTLM) && !defined(CURL_DISABLE_CRYPTO_AUTH)
627 #if defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
628 defined(USE_GNUTLS) || defined(USE_NSS) || defined(USE_SECTRANSP) || \
629 defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
630 (defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT))
632 #define USE_CURL_NTLM_CORE
634 # if defined(USE_MBEDTLS)
635 /* Get definition of MBEDTLS_MD4_C */
636 # include <mbedtls/md4.h>
641 #if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI)
646 #ifdef CURL_WANTS_CA_BUNDLE_ENV
647 #error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
650 #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) || defined(USE_WOLFSSH)
655 * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
656 * Parameters should of course normally not be unused, but for example when
657 * we have multiple implementations of the same interface it may happen.
660 #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
661 ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
662 # define UNUSED_PARAM __attribute__((__unused__))
663 # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
665 # define UNUSED_PARAM /*NOTHING*/
666 # define WARN_UNUSED_RESULT
670 * Include macros and defines that should only be processed once.
673 #ifndef HEADER_CURL_SETUP_ONCE_H
674 #include "curl_setup_once.h"
678 * Definition of our NOP statement Object-like macro
681 #ifndef Curl_nop_stmt
682 # define Curl_nop_stmt do { } while(0)
686 * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
689 #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
690 # if defined(SOCKET) || \
691 defined(USE_WINSOCK) || \
692 defined(HAVE_WINSOCK_H) || \
693 defined(HAVE_WINSOCK2_H) || \
694 defined(HAVE_WS2TCPIP_H)
695 # error "WinSock and lwIP TCP/IP stack definitions shall not coexist!"
700 * Portable symbolic names for Winsock shutdown() mode flags.
704 # define SHUT_RD 0x00
705 # define SHUT_WR 0x01
706 # define SHUT_RDWR 0x02
709 /* Define S_ISREG if not defined by system headers, f.e. MSVC */
710 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
711 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
714 /* Define S_ISDIR if not defined by system headers, f.e. MSVC */
715 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
716 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
719 /* In Windows the default file mode is text but an application can override it.
720 Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
722 #if defined(WIN32) || defined(MSDOS)
723 #define FOPEN_READTEXT "rt"
724 #define FOPEN_WRITETEXT "wt"
725 #define FOPEN_APPENDTEXT "at"
726 #elif defined(__CYGWIN__)
727 /* Cygwin has specific behavior we need to address when WIN32 is not defined.
728 https://cygwin.com/cygwin-ug-net/using-textbinary.html
729 For write we want our output to have line endings of LF and be compatible with
730 other Cygwin utilities. For read we want to handle input that may have line
731 endings either CRLF or LF so 't' is appropriate.
733 #define FOPEN_READTEXT "rt"
734 #define FOPEN_WRITETEXT "w"
735 #define FOPEN_APPENDTEXT "a"
737 #define FOPEN_READTEXT "r"
738 #define FOPEN_WRITETEXT "w"
739 #define FOPEN_APPENDTEXT "a"
742 /* WinSock destroys recv() buffer when send() failed.
743 * Enabled automatically for Windows and for Cygwin as Cygwin sockets are
744 * wrappers for WinSock sockets. https://github.com/curl/curl/issues/657
745 * Define DONT_USE_RECV_BEFORE_SEND_WORKAROUND to force disable workaround.
747 #if !defined(DONT_USE_RECV_BEFORE_SEND_WORKAROUND)
748 # if defined(WIN32) || defined(__CYGWIN__)
749 # define USE_RECV_BEFORE_SEND_WORKAROUND
751 #else /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
752 # ifdef USE_RECV_BEFORE_SEND_WORKAROUND
753 # undef USE_RECV_BEFORE_SEND_WORKAROUND
755 #endif /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
757 /* Detect Windows App environment which has a restricted access
758 * to the Win32 APIs. */
759 # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
760 defined(WINAPI_FAMILY)
761 # include <winapifamily.h>
762 # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
763 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
764 # define CURL_WINDOWS_APP
768 /* for systems that don't detect this in configure, use a sensible default */
769 #ifndef CURL_SA_FAMILY_T
770 #define CURL_SA_FAMILY_T unsigned short
773 /* Some convenience macros to get the larger/smaller value out of two given.
774 We prefix with CURL to prevent name collisions. */
775 #define CURLMAX(x,y) ((x)>(y)?(x):(y))
776 #define CURLMIN(x,y) ((x)<(y)?(x):(y))
778 /* Some versions of the Android SDK is missing the declaration */
779 #if defined(HAVE_GETPWUID_R) && defined(HAVE_DECL_GETPWUID_R_MISSING)
781 int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
782 size_t buflen, struct passwd **result);
788 #define UNITTEST static
791 #if defined(USE_NGTCP2) || defined(USE_QUICHE)
795 #endif /* HEADER_CURL_SETUP_H */