1 #ifndef HEADER_CURL_SETUP_H
2 #define HEADER_CURL_SETUP_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2017, 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 * Define WIN32 when build target is Win32 API
33 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && \
34 !defined(__SYMBIAN32__)
40 * Don't include unneeded stuff in Windows headers to avoid compiler
41 * warnings and macro clashes.
42 * Make sure to define this macro before including any Windows headers.
44 # ifndef WIN32_LEAN_AND_MEAN
45 # define WIN32_LEAN_AND_MEAN
50 * Include configuration script results or hand-crafted
51 * configuration file for platforms which lack config tool.
56 #include "curl_config.h"
58 #else /* HAVE_CONFIG_H */
61 # include "config-win32ce.h"
64 # include "config-win32.h"
68 #if defined(macintosh) && defined(__MRC__)
69 # include "config-mac.h"
73 # include "config-riscos.h"
77 # include "config-amigaos.h"
81 # include "config-symbian.h"
85 # include "config-os400.h"
89 # include "config-tpf.h"
93 # include "config-vxworks.h"
96 #endif /* HAVE_CONFIG_H */
98 /* ================================================================ */
99 /* Definition of preprocessor macros/symbols which modify compiler */
100 /* behavior or generated code characteristics must be done here, */
101 /* as appropriate, before any system header file is included. It is */
102 /* also possible to have them defined in the config file included */
103 /* before this point. As a result of all this we frown inclusion of */
104 /* system header files in our config files, avoid this at any cost. */
105 /* ================================================================ */
108 * AIX 4.3 and newer needs _THREAD_SAFE defined to build
109 * proper reentrant code. Others may also need it.
112 #ifdef NEED_THREAD_SAFE
113 # ifndef _THREAD_SAFE
114 # define _THREAD_SAFE
119 * Tru64 needs _REENTRANT set for a few function prototypes and
120 * things to appear in the system header files. Unixware needs it
121 * to build proper reentrant code. Others may also need it.
124 #ifdef NEED_REENTRANT
130 /* Solaris needs this to get a POSIX-conformant getpwuid_r */
131 #if defined(sun) || defined(__sun)
132 # ifndef _POSIX_PTHREAD_SEMANTICS
133 # define _POSIX_PTHREAD_SEMANTICS 1
137 /* ================================================================ */
138 /* If you need to include a system header file for your platform, */
139 /* please, do it beyond the point further indicated in this file. */
140 /* ================================================================ */
142 #include <curl/curl.h>
144 #define CURL_SIZEOF_CURL_OFF_T SIZEOF_CURL_OFF_T
147 * Disable other protocols when http is the only one desired.
151 # ifndef CURL_DISABLE_TFTP
152 # define CURL_DISABLE_TFTP
154 # ifndef CURL_DISABLE_FTP
155 # define CURL_DISABLE_FTP
157 # ifndef CURL_DISABLE_LDAP
158 # define CURL_DISABLE_LDAP
160 # ifndef CURL_DISABLE_TELNET
161 # define CURL_DISABLE_TELNET
163 # ifndef CURL_DISABLE_DICT
164 # define CURL_DISABLE_DICT
166 # ifndef CURL_DISABLE_FILE
167 # define CURL_DISABLE_FILE
169 # ifndef CURL_DISABLE_RTSP
170 # define CURL_DISABLE_RTSP
172 # ifndef CURL_DISABLE_POP3
173 # define CURL_DISABLE_POP3
175 # ifndef CURL_DISABLE_IMAP
176 # define CURL_DISABLE_IMAP
178 # ifndef CURL_DISABLE_SMTP
179 # define CURL_DISABLE_SMTP
181 # ifndef CURL_DISABLE_GOPHER
182 # define CURL_DISABLE_GOPHER
184 # ifndef CURL_DISABLE_SMB
185 # define CURL_DISABLE_SMB
190 * When http is disabled rtsp is not supported.
193 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
194 # define CURL_DISABLE_RTSP
197 /* ================================================================ */
198 /* No system header file shall be included in this file before this */
199 /* point. The only allowed ones are those included from curl/system.h */
200 /* ================================================================ */
203 * OS/400 setup file includes some system headers.
207 # include "setup-os400.h"
211 * VMS setup file includes some system headers.
215 # include "setup-vms.h"
219 * Use getaddrinfo to resolve the IPv4 address literal. If the current network
220 * interface doesn’t support IPv4, but supports IPv6, NAT64, and DNS64,
221 * performing this task will result in a synthesized IPv6 address.
224 #define USE_RESOLVE_ON_IPS 1
228 * Include header files for windows builds before redefining anything.
229 * Use this preprocessor block only to include or exclude windows.h,
230 * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
231 * to any other further and independent block. Under Cygwin things work
232 * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
233 * never be included when __CYGWIN__ is defined. configure script takes
234 * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
235 * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
238 #ifdef HAVE_WINDOWS_H
239 # if defined(UNICODE) && !defined(_UNICODE)
242 # if defined(_UNICODE) && !defined(UNICODE)
245 # include <windows.h>
246 # ifdef HAVE_WINSOCK2_H
247 # include <winsock2.h>
248 # ifdef HAVE_WS2TCPIP_H
249 # include <ws2tcpip.h>
252 # ifdef HAVE_WINSOCK_H
253 # include <winsock.h>
258 typedef wchar_t *(*curl_wcsdup_callback)(const wchar_t *str);
263 * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
264 * define USE_WINSOCK to 1 if we have and use WINSOCK API, else
265 * undefine USE_WINSOCK.
270 #ifdef HAVE_WINSOCK2_H
271 # define USE_WINSOCK 2
273 # ifdef HAVE_WINSOCK_H
274 # define USE_WINSOCK 1
279 # include <lwip/init.h>
280 # include <lwip/sockets.h>
281 # include <lwip/netdb.h>
284 #ifdef HAVE_EXTRA_STRICMP_H
285 # include <extra/stricmp.h>
288 #ifdef HAVE_EXTRA_STRDUP_H
289 # include <extra/strdup.h>
293 # include <strings.h> /* for bzero, strcasecmp, and strncasecmp */
294 # include <string.h> /* for strcpy and strlen */
295 # include <stdlib.h> /* for rand and srand */
296 # include <sys/socket.h> /* for select and ioctl*/
297 # include <netdb.h> /* for in_addr_t definition */
298 # include <tpf/sysapi.h> /* for tpf_process_signals */
299 /* change which select is used for libcurl */
300 # define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
304 # include <sockLib.h> /* for generic BSD socket functions */
305 # include <ioLib.h> /* for basic I/O interface functions */
310 # include <exec/types.h>
311 # include <exec/execbase.h>
312 # include <proto/exec.h>
313 # include <proto/dos.h>
314 # define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
323 #ifdef __TANDEM /* for nsr-tandem-nsk systems */
327 #ifndef STDC_HEADERS /* no standard C headers! */
328 #include <curl/stdcheaders.h>
332 # include <sys/types.h>
334 # define sys_nerr EILSEQ
338 * Salford-C kludge section (mostly borrowed from wxWidgets).
341 #pragma suppress 353 /* Possible nested comments */
342 #pragma suppress 593 /* Define not used */
343 #pragma suppress 61 /* enum has no name */
344 #pragma suppress 106 /* unnamed, unused parameter */
349 * Large file (>2Gb) support using WIN32 functions.
352 #ifdef USE_WIN32_LARGE_FILES
354 # include <sys/types.h>
355 # include <sys/stat.h>
357 # define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
359 # define fstat(fdes,stp) _fstati64(fdes, stp)
361 # define stat(fname,stp) _stati64(fname, stp)
362 # define struct_stat struct _stati64
363 # define LSEEK_ERROR (__int64)-1
367 * Small file (<2Gb) support using WIN32 functions.
370 #ifdef USE_WIN32_SMALL_FILES
372 # include <sys/types.h>
373 # include <sys/stat.h>
376 # define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
377 # define fstat(fdes,stp) _fstat(fdes, stp)
378 # define stat(fname,stp) _stat(fname, stp)
379 # define struct_stat struct _stat
381 # define LSEEK_ERROR (long)-1
385 # define struct_stat struct stat
389 # define LSEEK_ERROR (off_t)-1
393 * Default sizeof(off_t) in case it hasn't been defined in config file.
397 # if defined(__VMS) && !defined(__VAX)
398 # if defined(_LARGEFILE)
399 # define SIZEOF_OFF_T 8
401 # elif defined(__OS400__) && defined(__ILEC400__)
402 # if defined(_LARGE_FILES)
403 # define SIZEOF_OFF_T 8
405 # elif defined(__MVS__) && defined(__IBMC__)
406 # if defined(_LP64) || defined(_LARGE_FILES)
407 # define SIZEOF_OFF_T 8
409 # elif defined(__370__) && defined(__IBMC__)
410 # if defined(_LP64) || defined(_LARGE_FILES)
411 # define SIZEOF_OFF_T 8
414 # ifndef SIZEOF_OFF_T
415 # define SIZEOF_OFF_T 4
420 * Arg 2 type for gethostname in case it hasn't been defined in config file.
423 #ifndef GETHOSTNAME_TYPE_ARG2
425 # define GETHOSTNAME_TYPE_ARG2 int
427 # define GETHOSTNAME_TYPE_ARG2 size_t
431 /* Below we define some functions. They should
433 4. set the SIGALRM signal timeout
434 5. set dir/file naming defines
439 # define DIR_CHAR "\\"
440 # define DOT_CHAR "_"
444 # ifdef MSDOS /* Watt-32 */
446 # include <sys/ioctl.h>
447 # define select(n,r,w,x,t) select_s(n,r,w,x,t)
448 # define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
460 /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
461 extern char *strtok_r(char *s, const char *delim, char **last);
462 extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
465 # define DIR_CHAR "/"
467 # define DOT_CHAR "."
472 # define DOT_CHAR "_"
475 # ifndef fileno /* sunos 4 have this as a macro! */
476 int fileno(FILE *stream);
482 * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
483 * defined in ws2tcpip.h as well as to provide IPv6 support.
484 * Does not apply if lwIP is used.
487 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(USE_LWIPSOCK)
488 # if !defined(HAVE_WS2TCPIP_H) || \
489 ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
490 # undef HAVE_GETADDRINFO_THREADSAFE
491 # undef HAVE_FREEADDRINFO
492 # undef HAVE_GETADDRINFO
493 # undef HAVE_GETNAMEINFO
498 /* ---------------------------------------------------------------- */
499 /* resolver specialty compile-time defines */
500 /* CURLRES_* defines to use in the host*.c sources */
501 /* ---------------------------------------------------------------- */
504 * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
507 #if defined(__LCC__) && defined(WIN32)
508 # undef USE_THREADS_POSIX
509 # undef USE_THREADS_WIN32
513 * MSVC threads support requires a multi-threaded runtime library.
514 * _beginthreadex() is not available in single-threaded ones.
517 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
518 # undef USE_THREADS_POSIX
519 # undef USE_THREADS_WIN32
523 * Mutually exclusive CURLRES_* definitions.
527 # define CURLRES_ASYNCH
528 # define CURLRES_ARES
529 /* now undef the stock libc functions just to avoid them being used */
530 # undef HAVE_GETADDRINFO
531 # undef HAVE_FREEADDRINFO
532 # undef HAVE_GETHOSTBYNAME
533 #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
534 # define CURLRES_ASYNCH
535 # define CURLRES_THREADED
537 # define CURLRES_SYNCH
541 # define CURLRES_IPV6
543 # define CURLRES_IPV4
546 /* ---------------------------------------------------------------- */
549 * When using WINSOCK, TELNET protocol requires WINSOCK2 API.
552 #if defined(USE_WINSOCK) && (USE_WINSOCK != 2)
553 # define CURL_DISABLE_TELNET 1
557 * msvc 6.0 does not have struct sockaddr_storage and
558 * does not define IPPROTO_ESP in winsock2.h. But both
559 * are available if PSDK is properly installed.
562 #if defined(_MSC_VER) && !defined(__POCC__)
563 # if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
564 # undef HAVE_STRUCT_SOCKADDR_STORAGE
569 * Intentionally fail to build when using msvc 6.0 without PSDK installed.
570 * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
571 * in lib/config-win32.h although absolutely discouraged and unsupported.
574 #if defined(_MSC_VER) && !defined(__POCC__)
575 # if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
576 # if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
577 # error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
578 "Windows Server 2003 PSDK"
580 # define CURL_DISABLE_LDAP 1
586 int netware_init(void);
587 #ifndef __NOVELL_LIBC__
588 #include <sys/bsdskt.h>
589 #include <sys/timeval.h>
593 #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && !defined(USE_WIN32_IDN)
594 /* The lib and header are present */
598 #if defined(USE_LIBIDN2) && defined(USE_WIN32_IDN)
599 #error "Both libidn2 and WinIDN are enabled, choose one."
602 #ifndef SIZEOF_TIME_T
603 /* assume default size of time_t to be 32 bit */
604 #define SIZEOF_TIME_T 4
607 #define LIBIDN_REQUIRED_VERSION "0.4.1"
609 #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_NSS) || \
610 defined(USE_POLARSSL) || defined(USE_AXTLS) || defined(USE_MBEDTLS) || \
611 defined(USE_CYASSL) || defined(USE_SCHANNEL) || \
612 defined(USE_DARWINSSL) || defined(USE_GSKIT)
613 #define USE_SSL /* SSL support has been enabled */
616 /* Single point where USE_SPNEGO definition might be defined */
617 #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
618 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
622 /* Single point where USE_KERBEROS5 definition might be defined */
623 #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
624 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
625 #define USE_KERBEROS5
628 /* Single point where USE_NTLM definition might be defined */
629 #if !defined(CURL_DISABLE_NTLM) && !defined(CURL_DISABLE_CRYPTO_AUTH)
630 #if defined(USE_OPENSSL) || defined(USE_WINDOWS_SSPI) || \
631 defined(USE_GNUTLS) || defined(USE_NSS) || defined(USE_DARWINSSL) || \
632 defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
637 # if defined(USE_MBEDTLS)
638 /* Get definition of MBEDTLS_MD4_C */
639 # include <mbedtls/md4.h>
645 #ifdef CURL_WANTS_CA_BUNDLE_ENV
646 #error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
650 * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
651 * Parameters should of course normally not be unused, but for example when
652 * we have multiple implementations of the same interface it may happen.
655 #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
656 ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
657 # define UNUSED_PARAM __attribute__((__unused__))
658 # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
660 # define UNUSED_PARAM /*NOTHING*/
661 # define WARN_UNUSED_RESULT
665 * Include macros and defines that should only be processed once.
668 #ifndef HEADER_CURL_SETUP_ONCE_H
669 #include "curl_setup_once.h"
673 * Definition of our NOP statement Object-like macro
676 #ifndef Curl_nop_stmt
677 # define Curl_nop_stmt do { } WHILE_FALSE
681 * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
684 #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
685 # if defined(SOCKET) || \
686 defined(USE_WINSOCK) || \
687 defined(HAVE_WINSOCK_H) || \
688 defined(HAVE_WINSOCK2_H) || \
689 defined(HAVE_WS2TCPIP_H)
690 # error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
695 * Portable symbolic names for Winsock shutdown() mode flags.
699 # define SHUT_RD 0x00
700 # define SHUT_WR 0x01
701 # define SHUT_RDWR 0x02
704 /* Define S_ISREG if not defined by system headers, f.e. MSVC */
705 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
706 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
709 /* Define S_ISDIR if not defined by system headers, f.e. MSVC */
710 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
711 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
714 /* In Windows the default file mode is text but an application can override it.
715 Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
717 #if defined(WIN32) || defined(MSDOS)
718 #define FOPEN_READTEXT "rt"
719 #define FOPEN_WRITETEXT "wt"
720 #define FOPEN_APPENDTEXT "at"
721 #elif defined(__CYGWIN__)
722 /* Cygwin has specific behavior we need to address when WIN32 is not defined.
723 https://cygwin.com/cygwin-ug-net/using-textbinary.html
724 For write we want our output to have line endings of LF and be compatible with
725 other Cygwin utilities. For read we want to handle input that may have line
726 endings either CRLF or LF so 't' is appropriate.
728 #define FOPEN_READTEXT "rt"
729 #define FOPEN_WRITETEXT "w"
730 #define FOPEN_APPENDTEXT "a"
732 #define FOPEN_READTEXT "r"
733 #define FOPEN_WRITETEXT "w"
734 #define FOPEN_APPENDTEXT "a"
737 /* WinSock destroys recv() buffer when send() failed.
738 * Enabled automatically for Windows and for Cygwin as Cygwin sockets are
739 * wrappers for WinSock sockets. https://github.com/curl/curl/issues/657
740 * Define DONT_USE_RECV_BEFORE_SEND_WORKAROUND to force disable workaround.
742 #if !defined(DONT_USE_RECV_BEFORE_SEND_WORKAROUND)
743 # if defined(WIN32) || defined(__CYGWIN__)
744 # define USE_RECV_BEFORE_SEND_WORKAROUND
746 #else /* DONT_USE_RECV_BEFORE_SEND_WORKAROUNDS */
747 # ifdef USE_RECV_BEFORE_SEND_WORKAROUND
748 # undef USE_RECV_BEFORE_SEND_WORKAROUND
750 #endif /* DONT_USE_RECV_BEFORE_SEND_WORKAROUNDS */
752 /* Detect Windows App environment which has a restricted access
753 * to the Win32 APIs. */
754 # if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
755 # include <winapifamily.h>
756 # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
757 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
758 # define CURL_WINDOWS_APP
762 #endif /* HEADER_CURL_SETUP_H */