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