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