master
1#ifndef HEADER_CURL_SETUP_H
2#define HEADER_CURL_SETUP_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) 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 ***************************************************************************/
27#if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES)
28#define CURL_NO_OLDIES
29#endif
31/* Set default _WIN32_WINNT */
32#ifdef __MINGW32__
33#include <_mingw.h>
34#endif
36/* Workaround for Homebrew gcc 12.4.0, 13.3.0, 14.1.0, 14.2.0 (initial build)
37 that started advertising the `availability` attribute, which then gets used
38 by Apple SDK, but, in a way incompatible with gcc, resulting in misc errors
39 inside SDK headers, e.g.:
40 error: attributes should be specified before the declarator in a function
41 definition
42 error: expected ',' or '}' before
43 Followed by missing declarations.
44 Work it around by overriding the built-in feature-check macro used by the
45 headers to enable the problematic attributes. This makes the feature check
46 fail. Fixed in 14.2.0_1. Disable the workaround if the fix is detected. */
47#if defined(__APPLE__) && !defined(__clang__) && defined(__GNUC__) && \
48 defined(__has_attribute)
49# if !defined(__has_feature) /* Keep this PP check separate from others */
50# define availability curl_pp_attribute_disabled
51# elif !__has_feature(attribute_availability)
52# define availability curl_pp_attribute_disabled
53# endif
54#endif
56#ifdef __APPLE__
57#include <sys/types.h>
58#include <TargetConditionals.h>
59/* Fixup faulty target macro initialization in macOS SDK since v14.4 (as of
60 15.0 beta). The SDK target detection in `TargetConditionals.h` correctly
61 detects macOS, but fails to set the macro's old name `TARGET_OS_OSX`, then
62 continues to set it to a default value of 0. Other parts of the SDK still
63 rely on the old name, and with this inconsistency our builds fail due to
64 missing declarations. It happens when using mainline llvm older than v18.
65 Later versions fixed it by predefining these target macros, avoiding the
66 faulty dynamic detection. gcc is not affected (for now) because it lacks
67 the necessary dynamic detection features, so the SDK falls back to
68 a codepath that sets both the old and new macro to 1. */
69#if defined(TARGET_OS_MAC) && TARGET_OS_MAC && \
70 defined(TARGET_OS_OSX) && !TARGET_OS_OSX && \
71 (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \
72 (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR)
73#undef TARGET_OS_OSX
74#define TARGET_OS_OSX TARGET_OS_MAC
75#endif
76#endif
78#if defined(__MINGW32__) && \
79 (!defined(__MINGW64_VERSION_MAJOR) || (__MINGW64_VERSION_MAJOR < 3))
80#error "mingw-w64 3.0 or greater required"
81#endif
83/* Visual Studio 2010 is the minimum Visual Studio version we support.
84 Workarounds for older versions of Visual Studio have been removed. */
85#if defined(_MSC_VER) && (_MSC_VER < 1600)
86#error "Ancient versions of Visual Studio are no longer supported due to bugs."
87#endif
89#ifdef _MSC_VER
90/* Disable Visual Studio warnings: 4127 "conditional expression is constant" */
91#pragma warning(disable:4127)
92#ifndef _CRT_SECURE_NO_WARNINGS
93#define _CRT_SECURE_NO_WARNINGS /* for getenv(), sscanf(), vsnprintf() */
94#endif
95#endif /* _MSC_VER */
97#ifdef _WIN32
98/*
99 * Do not include unneeded stuff in Windows headers to avoid compiler
100 * warnings and macro clashes.
101 * Make sure to define this macro before including any Windows headers.
102 */
103# ifndef WIN32_LEAN_AND_MEAN
104# define WIN32_LEAN_AND_MEAN
105# endif
106# ifndef NOGDI
107# define NOGDI
108# endif
110/* Detect Windows App environment which has a restricted access
111 * to the Win32 APIs. */
112# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
113 defined(WINAPI_FAMILY)
114# include <winapifamily.h>
115# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
116 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
117# define CURL_WINDOWS_UWP
118# endif
119# endif
121/* Mandatory to define SECURITY_WIN32 or SECURITY_KERNEL to indicating who is
122 compiling the code. */
123#undef SECURITY_KERNEL
124#undef SECURITY_WIN32
125#define SECURITY_WIN32 /* for <sspi.h> */
126#endif
128/*
129 * Include configuration script results or hand-crafted
130 * configuration file for platforms which lack config tool.
131 */
133#ifdef HAVE_CONFIG_H
135#include "curl_config.h"
137#else /* HAVE_CONFIG_H */
139#ifdef _WIN32
140# include "config-win32.h"
141#endif
143#ifdef macintosh
144# include "config-mac.h"
145#endif
147#ifdef __OS400__
148# include "config-os400.h"
149#endif
151#endif /* HAVE_CONFIG_H */
153#ifdef _WIN32
154# if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
155# error The minimum build target is Windows Vista (0x0600)
156# endif
158# if !defined(CURL_WINDOWS_UWP) && (defined(_MSC_VER) || defined(__MINGW32__))
159# ifndef HAVE_IF_NAMETOINDEX
160# define HAVE_IF_NAMETOINDEX
161# endif
162# endif
163#endif
165/* ================================================================ */
166/* Definition of preprocessor macros/symbols which modify compiler */
167/* behavior or generated code characteristics must be done here, */
168/* as appropriate, before any system header file is included. It is */
169/* also possible to have them defined in the config file included */
170/* before this point. As a result of all this we frown inclusion of */
171/* system header files in our config files, avoid this at any cost. */
172/* ================================================================ */
174#ifdef HAVE_LIBZ
175# ifndef ZLIB_CONST
176# define ZLIB_CONST /* Use z_const. Supported by v1.2.5.2 or greater. */
177# endif
178#endif
180/*
181 * AIX 4.3 and newer needs _THREAD_SAFE defined to build
182 * proper reentrant code. Others may also need it.
183 */
184#ifdef NEED_THREAD_SAFE
185# ifndef _THREAD_SAFE
186# define _THREAD_SAFE
187# endif
188#endif
190/*
191 * Tru64 needs _REENTRANT set for a few function prototypes and
192 * things to appear in the system header files. Unixware needs it
193 * to build proper reentrant code. Others may also need it.
194 */
195#ifdef NEED_REENTRANT
196# ifndef _REENTRANT
197# define _REENTRANT
198# endif
199#endif
201/* Solaris needs this to get a POSIX-conformant getpwuid_r */
202#if defined(sun) || defined(__sun)
203# ifndef _POSIX_PTHREAD_SEMANTICS
204# define _POSIX_PTHREAD_SEMANTICS 1
205# endif
206#endif
208/* ================================================================ */
209/* If you need to include a system header file for your platform, */
210/* please, do it beyond the point further indicated in this file. */
211/* ================================================================ */
213/* Give calloc a chance to be included early, so we do not redefine */
214#ifdef HAVE_THREADS_POSIX
215# include <pthread.h>
216#endif
218/*
219 * When HTTP is disabled, disable HTTP-only features
220 */
221#ifdef CURL_DISABLE_HTTP
222# ifndef CURL_DISABLE_ALTSVC
223# define CURL_DISABLE_ALTSVC
224# endif
225# ifndef CURL_DISABLE_AWS
226# define CURL_DISABLE_AWS
227# endif
228# ifndef CURL_DISABLE_BASIC_AUTH
229# define CURL_DISABLE_BASIC_AUTH
230# endif
231# ifndef CURL_DISABLE_BEARER_AUTH
232# define CURL_DISABLE_BEARER_AUTH
233# endif
234# ifndef CURL_DISABLE_COOKIES
235# define CURL_DISABLE_COOKIES
236# endif
237# ifndef CURL_DISABLE_DOH
238# define CURL_DISABLE_DOH
239# endif
240# ifndef CURL_DISABLE_FORM_API
241# define CURL_DISABLE_FORM_API
242# endif
243# ifndef CURL_DISABLE_HEADERS_API
244# define CURL_DISABLE_HEADERS_API
245# endif
246# ifndef CURL_DISABLE_HSTS
247# define CURL_DISABLE_HSTS
248# endif
249# ifndef CURL_DISABLE_HTTPSIG
250# define CURL_DISABLE_HTTPSIG
251# endif
252# ifndef CURL_DISABLE_HTTP_AUTH
253# define CURL_DISABLE_HTTP_AUTH
254# endif
255# ifndef CURL_DISABLE_RTSP
256# define CURL_DISABLE_RTSP
257# endif
258# ifndef CURL_DISABLE_WEBSOCKETS
259# define CURL_DISABLE_WEBSOCKETS /* no WebSockets without HTTP present */
260# endif
261#endif
263/* ================================================================ */
264/* No system header file shall be included in this file before this */
265/* point. */
266/* ================================================================ */
268/*
269 * OS/400 setup file includes some system headers.
270 */
271#ifdef __OS400__
272# include "setup-os400.h"
273#endif
275/*
276 * VMS setup file includes some system headers.
277 */
278#ifdef __VMS
279# include "setup-vms.h"
280#endif
282/*
283 * Windows setup file includes some system headers.
284 */
285#ifdef _WIN32
286# include "setup-win32.h"
287#endif
289#include <curl/system.h>
291#if !defined(HAVE_PIPE2) && \
292 ((defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
293 __MAC_OS_X_VERSION_MAX_ALLOWED >= 270000 && \
294 defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
295 __MAC_OS_X_VERSION_MIN_REQUIRED >= 270000) || \
296 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
297 __IPHONE_OS_VERSION_MAX_ALLOWED >= 270000 && \
298 defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && \
299 __IPHONE_OS_VERSION_MIN_REQUIRED >= 270000) || \
300 (defined(__TV_OS_VERSION_MAX_ALLOWED) && \
301 __TV_OS_VERSION_MAX_ALLOWED >= 270000 && \
302 defined(__TV_OS_VERSION_MIN_REQUIRED) && \
303 __TV_OS_VERSION_MIN_REQUIRED >= 270000) || \
304 (defined(__WATCH_OS_VERSION_MAX_ALLOWED) && \
305 __WATCH_OS_VERSION_MAX_ALLOWED >= 270000 && \
306 defined(__WATCH_OS_VERSION_MIN_REQUIRED) && \
307 __WATCH_OS_VERSION_MIN_REQUIRED >= 270000) || \
308 (defined(__VISION_OS_VERSION_MAX_ALLOWED) && \
309 __VISION_OS_VERSION_MAX_ALLOWED >= 270000 && \
310 defined(__VISION_OS_VERSION_MIN_REQUIRED) && \
311 __VISION_OS_VERSION_MIN_REQUIRED >= 270000))
312#define HAVE_PIPE2
313#endif
315/* Helper macro to expand and concatenate two macros.
316 * Direct macros concatenation does not work because macros
317 * are not expanded before direct concatenation.
318 */
319#define CURL_CONC_MACROS_(A, B) A ## B
320#define CURL_CONC_MACROS(A, B) CURL_CONC_MACROS_(A, B)
322/* curl uses its own printf() function internally. It understands the GNU
323 * format. Use this format, so that it matches the GNU format attribute we
324 * use with the MinGW compiler, allowing it to verify them at compile-time.
325 */
326#ifdef __MINGW32__
327# undef CURL_FORMAT_CURL_OFF_T
328# undef CURL_FORMAT_CURL_OFF_TU
329# define CURL_FORMAT_CURL_OFF_T "lld"
330# define CURL_FORMAT_CURL_OFF_TU "llu"
331#endif
333/* based on logic in "curl/mprintf.h" */
334#if (defined(__GNUC__) || defined(__clang__) || \
335 defined(__IAR_SYSTEMS_ICC__)) && \
336 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
337 !defined(CURL_NO_FMT_CHECKS)
338#if defined(__MINGW32__) && !defined(__clang__)
339#define CURL_PRINTF(fmt, arg) __attribute__((format(gnu_printf, fmt, arg)))
340#else
341#define CURL_PRINTF(fmt, arg) __attribute__((format(__printf__, fmt, arg)))
342#endif
343#else
344#define CURL_PRINTF(fmt, arg)
345#endif
347/* Override default printf mask check rules in "curl/mprintf.h" */
348#define CURL_TEMP_PRINTF CURL_PRINTF
350/* Workaround for mainline llvm v16 and earlier missing a built-in macro
351 expected by macOS SDK v14 / Xcode v15 (2023) and newer.
352 gcc (as of v14) is also missing it. */
353#if defined(__APPLE__) && \
354 ((!defined(__apple_build_version__) && \
355 defined(__clang__) && __clang_major__ < 17) || \
356 (defined(__GNUC__) && __GNUC__ <= 14)) && \
357 defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
358 !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__)
359#define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ \
360 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
361#endif
363/*
364 * Use getaddrinfo to resolve the IPv4 address literal. If the current network
365 * interface does not support IPv4, but supports IPv6, NAT64, and DNS64,
366 * performing this task will result in a synthesized IPv6 address.
367 */
368#if defined(__APPLE__) && !defined(USE_ARES)
369# define USE_RESOLVE_ON_IPS 1
370# if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
371 defined(USE_IPV6)
372# define CURL_MACOS_CALL_COPYPROXIES 1
373# endif
374#endif
376#ifdef USE_ARES
377# ifndef CARES_NO_DEPRECATED
378# define CARES_NO_DEPRECATED /* for ares_getsock() */
379# endif
380# if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && defined(_WIN32)
381# define CARES_STATICLIB /* define it before including ares.h */
382# endif
383#endif
385#ifdef USE_LWIPSOCK
386# include <lwip/init.h>
387# include <lwip/sockets.h>
388# include <lwip/netdb.h>
389#endif
391#ifdef macintosh
392# include <extra/stricmp.h>
393# include <extra/strdup.h>
394#endif
396#ifdef __AMIGA__
397# ifdef __amigaos4__
398# define __USE_INLINE__
399 /* use our own resolver which uses runtime feature detection */
400# define CURLRES_AMIGA
401 /* getaddrinfo() currently crashes bsdsocket.library, so disable */
402# undef HAVE_GETADDRINFO
403# if !(defined(__NEWLIB__) || \
404 (defined(__CLIB2__) && defined(__THREAD_SAFE)))
405 /* disable threaded resolver with clib2 - requires newlib or clib-ts */
406# undef USE_RESOLV_THREADED
407# endif
408# endif
409# include <exec/types.h>
410# include <exec/execbase.h>
411# include <proto/exec.h>
412# include <proto/dos.h>
413# include <unistd.h>
414# if defined(HAVE_PROTO_BSDSOCKET_H) && \
415 (!defined(__amigaos4__) || defined(USE_AMISSL))
416 /* use bsdsocket.library directly, instead of libc networking functions */
417# define _SYS_MBUF_H /* m_len define clashes with curl */
418# include <proto/bsdsocket.h>
419# ifdef __amigaos4__
420 int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds,
421 fd_set *errorfds, struct timeval *timeout);
422# define select(a, b, c, d, e) Curl_amiga_select(a, b, c, d, e)
423# else
424# define select(a, b, c, d, e) WaitSelect(a, b, c, d, e, 0)
425# endif
426 /* must not use libc's fcntl() on bsdsocket.library sockfds! */
427# undef HAVE_FCNTL
428# undef HAVE_FCNTL_O_NONBLOCK
429# else
430 /* use libc networking and hence close() and fcntl() */
431# undef HAVE_CLOSESOCKET_CAMEL
432# undef HAVE_IOCTLSOCKET_CAMEL
433# endif
434/*
435 * In clib2 arpa/inet.h warns that some prototypes may clash
436 * with bsdsocket.library. This avoids the definition of those.
437 */
438# define __NO_NET_API
439#endif
441/* Whether to use eventfd() */
442#if defined(HAVE_EVENTFD) && defined(HAVE_SYS_EVENTFD_H)
443#define USE_EVENTFD
444#endif
446#ifdef SO_NOSIGPIPE
447#define USE_SO_NOSIGPIPE
448#endif
450#include <stdio.h>
451#include <assert.h>
453#ifdef __TANDEM /* for ns*-tandem-nsk systems */
454# ifndef __LP64
455# include <floss.h> /* FLOSS is only used for 32-bit builds. */
456# endif
457#endif
459#include <stdint.h>
460#define HAVE_UINTPTR_T /* assume uintptr_t is provided by stdint.h */
462#ifdef __DJGPP__
463/* By default, DJGPP provides this type as a version of 'unsigned long' which
464 forces us to use a define use it in printf() format strings without
465 warnings. long and int are both 32 bits for this platform. */
466#define uint32_t unsigned int
467#endif
469/* Disable uintptr_t for targets known to miss it from stdint.h */
470#ifdef __OS400__
471#undef HAVE_UINTPTR_T
472#endif
474#include <limits.h>
475/* Include after setting system macros that may affect type sizes
476 (e.g. 'off_t' or 'time_t'), or suppress warnings
477 (e.g. '_CRT_SECURE_NO_WARNINGS`), but before including sys/stat.h */
478#include <sys/types.h>
480#ifdef _WIN32
481# ifdef HAVE_IO_H
482# include <io.h>
483# endif
484# include <sys/stat.h>
485 /* Large file (>2Gb) support using Win32 functions. */
486# define curl_lseek _lseeki64
487# define LSEEK_ERROR ((__int64)-1)
488#elif defined(__DJGPP__)
489 /* Requires DJGPP 2.04 */
490# include <unistd.h>
491# define curl_lseek llseek
492# define LSEEK_ERROR ((offset_t)-1)
493#elif defined(__AMIGA__)
494# define curl_lseek(fd, offset, whence) lseek(fd, (off_t)(offset), whence)
495# define LSEEK_ERROR ((off_t)-1)
496#else
497# define curl_lseek lseek
498# define LSEEK_ERROR ((off_t)-1)
499#endif
501#ifndef SIZEOF_TIME_T
502/* assume default size of time_t to be 32 bits */
503#define SIZEOF_TIME_T 4
504#endif
506#ifndef SIZEOF_CURL_SOCKET_T
507/* configure and cmake check and set the define */
508# if defined(USE_WINSOCK) && defined(_WIN64)
509# define SIZEOF_CURL_SOCKET_T 8
510# else
511/* default guess */
512# define SIZEOF_CURL_SOCKET_T 4
513# endif
514#endif
516#if SIZEOF_CURL_SOCKET_T < 8
517#ifdef USE_WINSOCK
518# define FMT_SOCKET_T "u"
519#else
520# define FMT_SOCKET_T "d"
521#endif
522#elif defined(USE_WINSOCK)
523# define FMT_SOCKET_T "zu"
524#else
525# define FMT_SOCKET_T "qd"
526#endif
528/*
529 * Default sizeof(off_t) in case it has not been defined in config file.
530 */
532#ifndef SIZEOF_OFF_T
533# if defined(__VMS) && !defined(__VAX)
534# ifdef _LARGEFILE
535# define SIZEOF_OFF_T 8
536# endif
537# elif defined(__OS400__) && defined(__ILEC400__)
538# ifdef _LARGE_FILES
539# define SIZEOF_OFF_T 8
540# endif
541# elif defined(__MVS__) && defined(__IBMC__)
542# if defined(_LP64) || defined(_LARGE_FILES)
543# define SIZEOF_OFF_T 8
544# endif
545# elif defined(__370__) && defined(__IBMC__)
546# if defined(_LP64) || defined(_LARGE_FILES)
547# define SIZEOF_OFF_T 8
548# endif
549# endif
550# ifndef SIZEOF_OFF_T
551# define SIZEOF_OFF_T 4
552# endif
553#endif
555#if SIZEOF_CURL_OFF_T < 8
556#error "too small curl_off_t"
557#else
558 /* assume SIZEOF_CURL_OFF_T == 8 */
559# define CURL_OFF_T_MAX 0x7FFFFFFFFFFFFFFF
560#endif
561#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - 1)
563#define FMT_OFF_T CURL_FORMAT_CURL_OFF_T
564#define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU
566#if SIZEOF_TIME_T == 4
567# ifdef HAVE_TIME_T_UNSIGNED
568# define TIME_T_MAX UINT_MAX
569# define TIME_T_MIN 0
570# else
571# define TIME_T_MAX INT_MAX
572# define TIME_T_MIN INT_MIN
573# endif
574#else
575# ifdef HAVE_TIME_T_UNSIGNED
576# define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
577# define TIME_T_MIN 0
578# else
579# define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
580# define TIME_T_MIN (-TIME_T_MAX - 1)
581# endif
582#endif
584#ifndef SIZE_MAX
585/* some limits.h headers have this defined, some do not */
586#if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
587#define SIZE_MAX 18446744073709551615U
588#else
589#define SIZE_MAX 4294967295U
590#endif
591#endif
593#ifndef SSIZE_MAX
594/* some limits.h headers have this defined, some do not */
595#if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
596#define SSIZE_MAX 9223372036854775807
597#else
598#define SSIZE_MAX 2147483647
599#endif
600#endif
602#if SIZEOF_LONG > SIZEOF_SIZE_T
603#error "unexpected: 'long' is larger than 'size_t'"
604#endif
606/*
607 * Arg 2 type for gethostname in case it has not been defined in config file.
608 */
609#ifndef GETHOSTNAME_TYPE_ARG2
610# ifdef USE_WINSOCK
611# define GETHOSTNAME_TYPE_ARG2 int
612# else
613# define GETHOSTNAME_TYPE_ARG2 size_t
614# endif
615#endif
617/* Below we define some functions. They should
618 4. set the SIGALRM signal timeout
619 5. set dir/file naming defines
620 */
622#ifdef _WIN32
624# define DIR_CHAR "\\"
626#else /* _WIN32 */
628# ifdef MSDOS /* Watt-32 */
630# include <sys/ioctl.h>
631# define select(n, r, w, x, t) select_s(n, r, w, x, t)
632# define ioctl(x, y, z) ioctlsocket(x, y, (char *)(z))
633# include <tcp.h>
634# undef word
635# undef byte
637# endif /* MSDOS */
639# ifdef __minix
640 /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
641 extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
642# endif
644# define DIR_CHAR "/"
646#endif /* _WIN32 */
648/* We want to use mutex when available. */
649#if defined(HAVE_THREADS_POSIX) || defined(_WIN32)
650#define USE_MUTEX
651#endif
653/* threaded resolver is the only feature requiring threads. */
654#ifdef USE_RESOLV_THREADED
655#define USE_THREADS
656#endif
658/* ---------------------------------------------------------------- */
659/* resolver specialty compile-time defines */
660/* CURLRES_* defines to use in the host*.c sources */
661/* ---------------------------------------------------------------- */
663/*
664 * Mutually exclusive CURLRES_* definitions.
665 */
666#if defined(USE_IPV6) && defined(HAVE_GETADDRINFO)
667# define CURLRES_IPV6
668#elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__))
669/* assume on Windows that IPv6 without getaddrinfo is a broken build */
670# error "Unexpected build: IPv6 is enabled but getaddrinfo was not found."
671#else
672# define CURLRES_IPV4
673#endif
675#ifdef USE_RESOLV_THREADED
676# define CURLRES_ASYNCH
677#elif defined(USE_RESOLV_ARES)
678# define CURLRES_ASYNCH
679/* now undef the stock libc functions to avoid them being used */
680# undef HAVE_GETADDRINFO
681# undef HAVE_FREEADDRINFO
682#else
683# define CURLRES_SYNCH
684#endif
686/* ---------------------------------------------------------------- */
688#if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && \
689 !defined(USE_WIN32_IDN) && !defined(USE_APPLE_IDN)
690/* The lib and header are present */
691#define USE_LIBIDN2
692#endif
694#if defined(USE_LIBIDN2) && (defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN))
695#error "libidn2 cannot be enabled with WinIDN or AppleIDN, choose one."
696#endif
698#if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
699 defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || defined(USE_RUSTLS)
700#define USE_SSL /* SSL support has been enabled */
701#endif
703#if defined(USE_OPENSSL) && defined(USE_WOLFSSL)
704#ifndef OPENSSL_COEXIST
705#define OPENSSL_COEXIST
706#endif
707#endif
709#if defined(USE_WOLFSSL) && defined(USE_GNUTLS)
710/* Avoid defining unprefixed wolfSSL SHA macros colliding with nettle ones */
711#define NO_OLD_WC_NAMES
712#endif
714/* Single point where USE_SPNEGO definition might be defined */
715#if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \
716 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
717#define USE_SPNEGO
718#endif
720/* Single point where USE_KERBEROS5 definition might be defined */
721#if !defined(CURL_DISABLE_KERBEROS_AUTH) && \
722 (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
723#define USE_KERBEROS5
724#endif
726#if defined(USE_LIBSSH2) || defined(USE_LIBSSH)
727#define USE_SSH
728#endif
730/* GCC <4.6 does not support '#pragma GCC diagnostic push' and does not support
731 'pragma GCC diagnostic' inside functions.
732 Use CURL_HAVE_DIAG to guard the above in the curl codebase, instead of
733 defined(__GNUC__) || defined(__clang__).
734 */
735#if defined(__clang__) || (defined(__GNUC__) && \
736 ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))))
737#define CURL_HAVE_DIAG
738#endif
740/*
741 * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
742 * Parameters should of course normally not be unused, but for example when
743 * we have multiple implementations of the same interface it may happen.
744 */
745#if defined(__GNUC__) && ((__GNUC__ >= 3) || \
746 ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
747# define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
748#elif defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 9040001)
749# define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
750#else
751# define WARN_UNUSED_RESULT
752#endif
754/* noreturn attribute */
756#ifndef CURL_NORETURN
757#if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \
758 defined(__IAR_SYSTEMS_ICC__)
759# define CURL_NORETURN __attribute__((__noreturn__))
760#elif defined(_MSC_VER)
761# define CURL_NORETURN __declspec(noreturn)
762#else
763# define CURL_NORETURN
764#endif
765#endif
767/* fallthrough attribute */
769#ifndef FALLTHROUGH
770#if (defined(__GNUC__) && __GNUC__ >= 7) || \
771 (defined(__clang__) && __clang_major__ >= 10)
772# define FALLTHROUGH() __attribute__((fallthrough))
773#else
774# define FALLTHROUGH() do {} while(0)
775#endif
776#endif
778/*
779 * Inclusion of common header files.
780 */
782#include <stdlib.h>
783#include <string.h>
784#include <stdarg.h>
785#include <time.h>
786#include <errno.h>
788#include <sys/stat.h>
790#if !defined(_WIN32) || defined(__MINGW32__)
791#include <sys/time.h>
792#endif
794#ifdef HAVE_IO_H
795#include <io.h>
796#endif
798#ifdef HAVE_FCNTL_H
799#include <fcntl.h>
800#endif
802#if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T)
803#include <stdbool.h>
804#endif
806#ifdef HAVE_UNISTD_H
807#include <unistd.h>
808#endif
810/* Macro to strip 'const' without triggering a compiler warning.
811 Use it for APIs that do not or cannot support the const qualifier. */
812#ifdef HAVE_UINTPTR_T
813#define CURL_UNCONST(p) ((void *)(uintptr_t)(const void *)(p))
814#else
815#define CURL_UNCONST(p) ((void *)(p)) /* Fall back to simple cast */
816#endif
818#ifdef USE_SCHANNEL
819/* Must set this before <schannel.h> is included directly or indirectly by
820 another Windows header. */
821# define SCHANNEL_USE_BLACKLISTS /* for SCH_CREDENTIALS */
822# include <subauth.h> /* for [P]UNICODE_STRING in SCH_CREDENTIALS */
823#endif
825#ifdef __hpux
826# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
827# ifdef _APP32_64BIT_OFF_T
828# define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T
829# undef _APP32_64BIT_OFF_T
830# else
831# undef OLD_APP32_64BIT_OFF_T
832# endif
833# endif
834#endif
836#ifndef _WIN32
837#include <sys/socket.h> /* also for MSG_NOSIGNAL */
838#endif
840#include "functypes.h"
842#ifdef __hpux
843# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
844# ifdef OLD_APP32_64BIT_OFF_T
845# define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T
846# undef OLD_APP32_64BIT_OFF_T
847# endif
848# endif
849#endif
851/*
852 * Definition of timeval struct for platforms that do not have it.
853 */
854#ifndef HAVE_STRUCT_TIMEVAL
855struct timeval {
856 long tv_sec;
857 long tv_usec;
858};
859#endif
861/*
862 * If we have the MSG_NOSIGNAL define, make sure we use
863 * it as the fourth argument of function send()
864 */
865#ifdef MSG_NOSIGNAL
866#define SEND_4TH_ARG MSG_NOSIGNAL
867#else
868#define SEND_4TH_ARG 0
869#endif
871#ifdef __minix
872/* Minix does not support recv on TCP sockets */
873#define sread(x, y, z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
874 (RECV_TYPE_ARG2)(y), \
875 (RECV_TYPE_ARG3)(z))
877#elif defined(HAVE_RECV)
878/*
879 * The definitions for the return type and arguments types
880 * of functions recv() and send() belong and come from the
881 * configuration file. Do not define them in any other place.
882 *
883 * HAVE_RECV is defined if you have a function named recv()
884 * which is used to read incoming data from sockets. If your
885 * function has another name then do not define HAVE_RECV.
886 *
887 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
888 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
889 * be defined.
890 *
891 * HAVE_SEND is defined if you have a function named send()
892 * which is used to write outgoing data on a connected socket.
893 * If yours has another name then do not define HAVE_SEND.
894 *
895 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_TYPE_ARG2,
896 * SEND_TYPE_ARG3, SEND_TYPE_ARG4 and SEND_TYPE_RETV must also
897 * be defined. SEND_NONCONST_ARG2 must also be defined if ARG2
898 * does not accept const.
899 */
901#define sread(x, y, z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
902 (RECV_TYPE_ARG2)(y), \
903 (RECV_TYPE_ARG3)(z), \
904 (RECV_TYPE_ARG4)(0))
905#else /* HAVE_RECV */
906#ifndef sread
907#error "Missing definition of macro sread"
908#endif
909#endif /* HAVE_RECV */
911#ifdef __minix
912/* Minix does not support send on TCP sockets */
913#define swrite(x, y, z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
914 (SEND_TYPE_ARG2)CURL_UNCONST(y), \
915 (SEND_TYPE_ARG3)(z))
916#elif defined(HAVE_SEND)
917#ifdef SEND_NONCONST_ARG2
918#define swrite(x, y, z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
919 (SEND_TYPE_ARG2)CURL_UNCONST(y), \
920 (SEND_TYPE_ARG3)(z), \
921 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
922#else
923#define swrite(x, y, z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
924 (const SEND_TYPE_ARG2)(y), \
925 (SEND_TYPE_ARG3)(z), \
926 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
927#endif /* SEND_NONCONST_ARG2 */
928#else /* HAVE_SEND */
929#ifndef swrite
930#error "Missing definition of macro swrite"
931#endif
932#endif /* HAVE_SEND */
934/*
935 * Function-like macro definition used to close a socket.
936 */
937#ifdef HAVE_CLOSESOCKET
938# define CURL_SCLOSE(x) closesocket(x)
939#elif defined(HAVE_CLOSESOCKET_CAMEL)
940# define CURL_SCLOSE(x) CloseSocket(x)
941#elif defined(MSDOS) /* Watt-32 */
942# define CURL_SCLOSE(x) close_s(x)
943#elif defined(USE_LWIPSOCK)
944# define CURL_SCLOSE(x) lwip_close(x)
945#else
946# define CURL_SCLOSE(x) close(x)
947#endif
949/*
950 * Stack-independent version of fcntl() on sockets:
951 */
952#ifdef USE_LWIPSOCK
953# define sfcntl lwip_fcntl
954#else
955# define sfcntl fcntl
956#endif
958/*
959 * 'bool' stuff compatible with HP-UX headers.
960 */
961#if defined(__hpux) && !defined(HAVE_BOOL_T)
962typedef int bool;
963# define false 0
964# define true 1
965# define HAVE_BOOL_T
966#endif
968/*
969 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
970 * On non-C99 platforms there is no bool, so define an enum for that.
971 * On C99 platforms 'false' and 'true' also exist. Enum uses a
972 * global namespace though, so use bool_false and bool_true.
973 */
974#ifndef HAVE_BOOL_T
975/* This replacement type does not preserve C99 bool's normalization semantics:
976 converting a non-zero value to C99 bool results in 1. This is significant
977 when the value is assigned to a bit-field. Make sure to normalize manually
978 in such cases. */
979typedef enum {
980 bool_false = 0,
981 bool_true = 1
982} bool;
984/*
985 * Use a define to let 'true' and 'false' use those enums. There
986 * are currently no use of true and false in libcurl proper, but
987 * there are some in the examples. This will cater for any later
988 * code happening to use true and false.
989 */
990# define false bool_false
991# define true bool_true
992# define HAVE_BOOL_T
993#endif
995/* the type we use for storing a single boolean bit */
996typedef unsigned int curl_bit;
997#define BIT(x) curl_bit x:1
999/*
1000 * Redefine TRUE and FALSE too, to catch current use. With this
1001 * change, 'bool found = 1' will give a warning on MIPSPro, but
1002 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
1003 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
1004 */
1005#ifndef TRUE
1006#define TRUE true
1007#endif
1008#ifndef FALSE
1009#define FALSE false
1010#endif
1012#include "curl_ctype.h"
1014#if defined(DEBUGBUILD) && defined(NDEBUG)
1015#error "Debug-enabled builds cannot be combined with NDEBUG"
1016#endif
1018/*
1019 * Macro used to include code only in debug builds.
1020 */
1021#ifdef DEBUGBUILD
1022#define DEBUGF(x) x
1023#else
1024#define DEBUGF(x) do {} while(0)
1025#endif
1027/*
1028 * Macro used to include assertion code only in debug builds.
1029 */
1030#undef DEBUGASSERT
1031#ifdef DEBUGBUILD
1032#ifdef CURL_DEBUGASSERT
1033/* External assertion handler for custom integrations */
1034#define DEBUGASSERT(x) CURL_DEBUGASSERT(x)
1035#else
1036#define DEBUGASSERT(x) assert(x)
1037#endif
1038#else
1039#define DEBUGASSERT(x) do {} while(0)
1040#endif
1042/* Macro to configure Visual Studio debug CRT to output errors to stderr and
1043 the debugger, replacing the interactive GUI dialog. */
1044#if defined(_MSC_VER) && defined(_DEBUG) && defined(CURL_DEBUG_MSVC_CRTDBG)
1045#include <crtdbg.h> /* for _CrtSetReportFile(), _CRT* macros */
1046#define CURL_MSVC_CRTDBG_INIT() \
1047 do { \
1048 _set_error_mode(_OUT_TO_STDERR); /* needs stdlib.h */ \
1049 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); \
1050 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); \
1051 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); \
1052 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); \
1053 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); \
1054 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); \
1055 } while(0)
1056#else
1057#define CURL_MSVC_CRTDBG_INIT() do {} while(0)
1058#endif
1060#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
1061#include <tlhelp32.h>
1062/* Print the list of all loaded modules with full paths. */
1063#define CURL_DUMP_MODULE_PATHS(printf_f) \
1064 do { \
1065 HANDLE hnd = INVALID_HANDLE_VALUE; \
1066 MODULEENTRY32 mod = { 0 }; \
1067 \
1068 mod.dwSize = sizeof(MODULEENTRY32); \
1069 \
1070 do { \
1071 hnd = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0); \
1072 } while(hnd == INVALID_HANDLE_VALUE && \
1073 GetLastError() == ERROR_BAD_LENGTH); \
1074 \
1075 if(hnd == INVALID_HANDLE_VALUE) \
1076 goto error; \
1077 \
1078 if(!Module32First(hnd, &mod)) \
1079 goto error; \
1080 \
1081 do { \
1082 char buffer[sizeof(mod.szExePath) * 2]; \
1083 char *path; /* points to stack allocated buffer */ \
1084 if(sizeof(*mod.szExePath) > 1) { /* _UNICODE */ \
1085 /* sizeof(mod.szExePath) is the max total bytes of */ \
1086 /* wchars. the max total bytes of multibyte chars is */ \
1087 /* not more than twice that. */ \
1088 if(!WideCharToMultiByte(CP_ACP, 0, (WCHAR *)mod.szExePath, -1, \
1089 buffer, sizeof(buffer), NULL, NULL)) \
1090 goto error; \
1091 path = (char *)buffer; \
1092 } \
1093 else \
1094 path = (char *)mod.szExePath; \
1095 (printf_f)("%s\n", path); \
1096 } while(Module32Next(hnd, &mod)); \
1097 \
1098error: \
1099 if(hnd != INVALID_HANDLE_VALUE) \
1100 CloseHandle(hnd); \
1101 } while(0)
1102#else
1103#define CURL_DUMP_MODULE_PATHS(printf_f) do {} while(0)
1104#endif
1106/*
1107 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
1108 * (or equivalent) on this platform to hide platform details to code using it.
1109 */
1110#ifdef USE_WINSOCK
1111#define SOCKERRNO ((int)WSAGetLastError())
1112#define SET_SOCKERRNO(x) WSASetLastError((int)(x))
1113#else
1114#define SOCKERRNO errno
1115#define SET_SOCKERRNO(x) (errno = (x))
1116#endif
1118/*
1119 * Portable error number symbolic names defined to Winsock error codes.
1120 */
1121#ifdef USE_WINSOCK
1122#define SOCKEACCES WSAEACCES
1123#define SOCKEADDRINUSE WSAEADDRINUSE
1124#define SOCKEADDRNOTAVAIL WSAEADDRNOTAVAIL
1125#define SOCKEAFNOSUPPORT WSAEAFNOSUPPORT
1126#define SOCKEBADF WSAEBADF
1127#define SOCKECONNREFUSED WSAECONNREFUSED
1128#define SOCKECONNRESET WSAECONNRESET
1129#define SOCKEINPROGRESS WSAEINPROGRESS
1130#define SOCKEINTR WSAEINTR
1131#define SOCKEINVAL WSAEINVAL
1132#define SOCKEISCONN WSAEISCONN
1133#define SOCKEMSGSIZE WSAEMSGSIZE
1134/* Use literal value to work around clang-tidy <=20 misreporting
1135 'readability-uppercase-literal-suffix' with mingw-w64 headers */
1136#define SOCKENOMEM 8L /* WSA_NOT_ENOUGH_MEMORY */
1137#define SOCKETIMEDOUT WSAETIMEDOUT
1138#define SOCKEWOULDBLOCK WSAEWOULDBLOCK
1139#else
1140#define SOCKEACCES EACCES
1141#define SOCKEADDRINUSE EADDRINUSE
1142#define SOCKEADDRNOTAVAIL EADDRNOTAVAIL
1143#define SOCKEAFNOSUPPORT EAFNOSUPPORT
1144#define SOCKEBADF EBADF
1145#define SOCKECONNREFUSED ECONNREFUSED
1146#define SOCKECONNRESET ECONNRESET
1147#define SOCKEINPROGRESS EINPROGRESS
1148#define SOCKEINTR EINTR
1149#define SOCKEINVAL EINVAL
1150#define SOCKEISCONN EISCONN
1151#define SOCKEMSGSIZE EMSGSIZE
1152#define SOCKENOMEM ENOMEM
1153#ifdef ETIMEDOUT
1154#define SOCKETIMEDOUT ETIMEDOUT
1155#endif
1156#define SOCKEWOULDBLOCK EWOULDBLOCK
1157#endif
1159/* The socket error may be EWOULDBLOCK or on some systems EAGAIN when
1160 it returned due to its inability to send/read data without blocking.
1161 We treat both error codes the same here. */
1162#if !defined(USE_WINSOCK) && EAGAIN != SOCKEWOULDBLOCK
1163#define SOCK_EAGAIN(e) ((e) == SOCKEWOULDBLOCK || (e) == EAGAIN)
1164#else
1165#define SOCK_EAGAIN(e) ((e) == SOCKEWOULDBLOCK)
1166#endif
1168/*
1169 * Macro argv_item_t hides platform details to code using it.
1170 */
1171#ifdef __VMS
1172#define argv_item_t __char_ptr32
1173#elif defined(_UNICODE)
1174#define argv_item_t wchar_t *
1175#else
1176#define argv_item_t char *
1177#endif
1179/*
1180 * We use this ZERO_NULL to avoid picky compiler warnings,
1181 * when assigning a NULL pointer to a function pointer var.
1182 */
1183#define ZERO_NULL 0
1185/*
1186 * Macros and functions to safely suppress warnings
1187 */
1188#include "curlx/warnless.h"
1190#ifdef _WIN32
1191# undef read
1192# define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count))
1193# undef write
1194# define write(fd, buf, count) (ssize_t)_write(fd, buf, curlx_uztoui(count))
1195/* Avoid VS2005+ _CRT_NONSTDC_NO_DEPRECATE warnings about non-portable funcs */
1196# undef fileno
1197# define fileno(fh) _fileno(fh)
1198# undef unlink
1199# define unlink(fn) _unlink(fn)
1200# undef isatty
1201# define isatty(fd) _isatty(fd)
1202#endif
1204/*
1205 * Definition of our NOP statement Object-like macro
1206 */
1207#ifndef Curl_nop_stmt
1208#define Curl_nop_stmt do {} while(0)
1209#endif
1211/*
1212 * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
1213 */
1214#if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
1215# if defined(SOCKET) || defined(USE_WINSOCK)
1216# error "Winsock and lwIP TCP/IP stack definitions shall not coexist"
1217# endif
1218#endif
1220/*
1221 * shutdown() flags for systems that do not define them
1222 */
1223#ifndef SHUT_RD
1224#define SHUT_RD 0x00
1225#endif
1227#ifndef SHUT_WR
1228#define SHUT_WR 0x01
1229#endif
1231#ifndef SHUT_RDWR
1232#define SHUT_RDWR 0x02
1233#endif
1235/* Define S_ISREG if not defined by system headers, e.g. MSVC */
1236#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
1237#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
1238#endif
1240/* Define S_ISDIR if not defined by system headers, e.g. MSVC */
1241#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
1242#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1243#endif
1245/* For MSVC (all versions as of VS2022) */
1246#ifndef STDIN_FILENO
1247#define STDIN_FILENO fileno(stdin)
1248#endif
1249#ifndef STDOUT_FILENO
1250#define STDOUT_FILENO fileno(stdout)
1251#endif
1252#ifndef STDERR_FILENO
1253#define STDERR_FILENO fileno(stderr)
1254#endif
1256/* Since O_BINARY is used in bitmasks, setting it to zero makes it usable in
1257 source code but yet it does not ruin anything */
1258#ifdef _O_BINARY /* for _WIN32 || MSDOS */
1259#define CURL_O_BINARY _O_BINARY
1260#elif defined(O_BINARY) /* __CYGWIN__ */
1261#define CURL_O_BINARY O_BINARY
1262#else
1263#define CURL_O_BINARY 0
1264#endif
1266/* Requires io.h when available */
1267#ifdef MSDOS
1268#define CURL_BINMODE(stream) (void)setmode(fileno(stream), CURL_O_BINARY)
1269#elif defined(_WIN32) || defined(__CYGWIN__)
1270#define CURL_BINMODE(stream) (void)_setmode(fileno(stream), CURL_O_BINARY)
1271#else
1272#define CURL_BINMODE(stream) (void)(stream)
1273#endif
1275/* In Windows the default file mode is text but an application can override it.
1276 Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 */
1277#if defined(_WIN32) || defined(MSDOS)
1278#define FOPEN_READTEXT "rt"
1279#define FOPEN_WRITETEXT "wt"
1280#define FOPEN_APPENDTEXT "at"
1281#elif defined(__CYGWIN__)
1282/* Cygwin has specific behavior we need to address when _WIN32 is not defined.
1283 https://cygwin.com/cygwin-ug-net/using-textbinary.html
1284 For write we want our output to have line endings of LF and be compatible
1285 with other Cygwin utilities. For read we want to handle input that may have
1286 line endings either CRLF or LF so 't' is appropriate. */
1287#define FOPEN_READTEXT "rt"
1288#define FOPEN_WRITETEXT "w"
1289#define FOPEN_APPENDTEXT "a"
1290#else
1291#define FOPEN_READTEXT "r"
1292#define FOPEN_WRITETEXT "w"
1293#define FOPEN_APPENDTEXT "a"
1294#endif
1296/* for systems that do not detect this in configure */
1297#ifndef CURL_SA_FAMILY_T
1298# ifdef USE_WINSOCK
1299# define CURL_SA_FAMILY_T ADDRESS_FAMILY
1300# elif defined(HAVE_SA_FAMILY_T)
1301# define CURL_SA_FAMILY_T sa_family_t
1302# elif defined(__AMIGA__)
1303# define CURL_SA_FAMILY_T unsigned char
1304# else
1305/* use a sensible default */
1306# define CURL_SA_FAMILY_T unsigned short
1307# endif
1308#endif
1310/* Some convenience macros to get the larger/smaller value out of two given.
1311 We prefix with CURL to prevent name collisions. */
1312#define CURLMAX(x, y) ((x) > (y) ? (x) : (y))
1313#define CURLMIN(x, y) ((x) < (y) ? (x) : (y))
1315/* Convenience macro to provide the length of a string literal size without
1316 the null-terminator. Equivalent to strlen() for constant strings. */
1317#define CURL_CSTRLEN(x) (sizeof(x) - 1)
1319/* A convenience macro to provide both the string literal and the length of
1320 the string literal in one go, useful for functions that take "string,len"
1321 as their argument */
1322#define STRCONST(x) x, CURL_CSTRLEN(x)
1324#define CURL_ARRAYSIZE(A) (sizeof(A) / sizeof((A)[0]))
1326/* Buffer size for error messages retrieved via
1327 curlx_strerror() and Curl_sspi_strerror() */
1328#define STRERROR_LEN 256
1330#ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS /* only if not already done */
1331/*
1332 * The following memory function replacement typedef's are COPIED from
1333 * curl/curl.h and MUST match the originals. We copy them to avoid having to
1334 * include curl/curl.h here. We avoid that include since it includes stdio.h
1335 * and other headers that may get messed up with defines done here.
1336 */
1337typedef void *(*curl_malloc_callback)(size_t size);
1338typedef void (*curl_free_callback)(void *ptr);
1339typedef void *(*curl_realloc_callback)(void *ptr, size_t size);
1340typedef char *(*curl_strdup_callback)(const char *str);
1341typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size);
1342#define CURL_DID_MEMORY_FUNC_TYPEDEFS
1343#endif
1345extern curl_malloc_callback Curl_cmalloc;
1346extern curl_free_callback Curl_cfree;
1347extern curl_realloc_callback Curl_crealloc;
1348extern curl_strdup_callback Curl_cstrdup;
1349extern curl_calloc_callback Curl_ccalloc;
1351/*
1352 * curlx_safefree() defined as a macro to allow MemoryTracking feature
1353 * to log free() calls at same location where curlx_safefree() is used.
1354 * This macro also assigns NULL to given pointer when free'd.
1355 */
1356#define curlx_safefree(ptr) \
1357 do { \
1358 curlx_free(ptr); \
1359 (ptr) = NULL; \
1360 } while(0)
1362#include <curl/curl.h> /* for CURL_EXTERN, curl_socket_t, mprintf.h */
1364#ifdef DEBUGBUILD
1365#define CURL_MEMDEBUG
1366#endif
1368#ifdef CURL_MEMDEBUG
1369#ifdef __clang__
1370# define ALLOC_FUNC __attribute__((__malloc__))
1371# if __clang_major__ >= 4
1372# define ALLOC_SIZE(s) __attribute__((__alloc_size__(s)))
1373# define ALLOC_SIZE2(n, s) __attribute__((__alloc_size__(n, s)))
1374# else
1375# define ALLOC_SIZE(s)
1376# define ALLOC_SIZE2(n, s)
1377# endif
1378#elif defined(__GNUC__) && __GNUC__ >= 3
1379# define ALLOC_FUNC __attribute__((__malloc__))
1380# define ALLOC_SIZE(s) __attribute__((__alloc_size__(s)))
1381# define ALLOC_SIZE2(n, s) __attribute__((__alloc_size__(n, s)))
1382#elif defined(_MSC_VER)
1383# define ALLOC_FUNC __declspec(restrict)
1384# define ALLOC_SIZE(s)
1385# define ALLOC_SIZE2(n, s)
1386#else
1387# define ALLOC_FUNC
1388# define ALLOC_SIZE(s)
1389# define ALLOC_SIZE2(n, s)
1390#endif
1392extern FILE *curl_dbg_logfile;
1394/* memory functions */
1395CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source);
1396CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1)
1397 void *curl_dbg_malloc(size_t wantedsize, int line, const char *source);
1398CURL_EXTERN ALLOC_FUNC ALLOC_SIZE2(1, 2)
1399 void *curl_dbg_calloc(size_t wanted_elements, size_t wanted_size,
1400 int line, const char *source);
1401CURL_EXTERN ALLOC_SIZE(2)
1402 void *curl_dbg_realloc(void *ptr, size_t wantedsize, int line,
1403 const char *source);
1404CURL_EXTERN ALLOC_FUNC
1405 char *curl_dbg_strdup(const char *str, int line, const char *source);
1406#if defined(_WIN32) && defined(UNICODE)
1407CURL_EXTERN ALLOC_FUNC
1408 wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source);
1409#endif
1411CURL_EXTERN void curl_dbg_memdebug(const char *logname);
1412CURL_EXTERN void curl_dbg_memlimit(long limit);
1413CURL_EXTERN void curl_dbg_log(const char *format, ...) CURL_PRINTF(1, 2);
1415/* file descriptor manipulators */
1416CURL_EXTERN curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
1417 int line, const char *source);
1418CURL_EXTERN void curl_dbg_mark_sclose(curl_socket_t sockfd,
1419 int line, const char *source);
1420CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd,
1421 int line, const char *source);
1422CURL_EXTERN curl_socket_t curl_dbg_accept(curl_socket_t s,
1423 void *saddr, void *saddrlen,
1424 int line, const char *source);
1425#ifdef HAVE_ACCEPT4
1426CURL_EXTERN curl_socket_t curl_dbg_accept4(curl_socket_t s, void *saddr,
1427 void *saddrlen, int flags,
1428 int line, const char *source);
1429#endif
1430#ifdef HAVE_SOCKETPAIR
1431CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol,
1432 curl_socket_t socket_vector[2],
1433 int line, const char *source);
1434#endif
1436/* FILE functions */
1437CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
1438CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fopen(const char *file, const char *mode,
1439 int line, const char *source);
1440CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_freopen(const char *file,
1441 const char *mode, FILE *fh,
1442 int line, const char *source);
1443CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
1444 int line, const char *source);
1446#define sclose(sockfd) curl_dbg_sclose(sockfd, __LINE__, __FILE__)
1447#define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd, __LINE__, __FILE__)
1449#define CURL_GETADDRINFO(host, serv, hint, res) \
1450 curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
1451#define CURL_FREEADDRINFO(data) \
1452 curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
1453#define CURL_SOCKET(domain, type, protocol) \
1454 curl_dbg_socket((int)(domain), type, protocol, __LINE__, __FILE__)
1455#ifdef HAVE_SOCKETPAIR
1456#define CURL_SOCKETPAIR(domain, type, protocol, socket_vector) \
1457 curl_dbg_socketpair((int)(domain), type, protocol, socket_vector, \
1458 __LINE__, __FILE__)
1459#endif
1460#define CURL_ACCEPT(sock, addr, len) \
1461 curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
1462#ifdef HAVE_ACCEPT4
1463#define CURL_ACCEPT4(sock, addr, len, flags) \
1464 curl_dbg_accept4(sock, addr, len, flags, __LINE__, __FILE__)
1465#endif
1467#else /* !CURL_MEMDEBUG */
1469#define sclose(x) CURL_SCLOSE(x)
1470#define fake_sclose(x) Curl_nop_stmt
1472#define CURL_GETADDRINFO getaddrinfo
1473#define CURL_FREEADDRINFO freeaddrinfo
1474#define CURL_SOCKET socket
1475#ifdef HAVE_SOCKETPAIR
1476#define CURL_SOCKETPAIR socketpair
1477#endif
1478#define CURL_ACCEPT accept
1479#ifdef HAVE_ACCEPT4
1480#define CURL_ACCEPT4 accept4
1481#endif
1483#endif /* CURL_MEMDEBUG */
1485/* Allocator macros */
1487#ifdef _WIN32
1488#define CURLX_STRDUP_LOW _strdup
1489#else
1490#define CURLX_STRDUP_LOW strdup
1491#endif
1493#ifdef CURL_MEMDEBUG
1495#define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
1496#define curlx_malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
1497#define curlx_calloc(nbelem, size) \
1498 curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
1499#define curlx_realloc(ptr, size) \
1500 curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
1501#define curlx_free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
1503#ifdef _WIN32
1504#ifdef UNICODE
1505#define curlx_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
1506#else
1507#define curlx_tcsdup curlx_strdup
1508#endif
1509#endif /* _WIN32 */
1511#else /* !CURL_MEMDEBUG */
1513#ifdef BUILDING_LIBCURL
1514#define curlx_strdup Curl_cstrdup
1515#define curlx_malloc Curl_cmalloc
1516#define curlx_calloc Curl_ccalloc
1517#define curlx_realloc Curl_crealloc
1518#define curlx_free Curl_cfree
1519#else /* !BUILDING_LIBCURL */
1520#define curlx_strdup CURLX_STRDUP_LOW
1521#define curlx_malloc malloc
1522#define curlx_calloc calloc
1523#define curlx_realloc realloc
1524#define curlx_free free
1525#endif /* BUILDING_LIBCURL */
1527#ifdef _WIN32
1528#ifdef UNICODE
1529#define curlx_tcsdup curlx_wcsdup
1530#else
1531#define curlx_tcsdup curlx_strdup
1532#endif
1533#endif /* _WIN32 */
1535#endif /* CURL_MEMDEBUG */
1537/* Some versions of the Android NDK is missing the declaration */
1538#if defined(HAVE_GETPWUID_R) && \
1539 defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
1540struct passwd;
1541int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
1542 size_t buflen, struct passwd **result);
1543#endif
1545#ifdef UNITTESTS
1546#define UNITTEST
1547#else
1548#define UNITTEST static
1549#endif
1551#ifdef USE_NGHTTP2
1552#define USE_HTTP2
1553#endif
1555#if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || defined(USE_QUICHE)
1557#ifdef CURL_WITH_MULTI_SSL
1558#error "MultiSSL combined with QUIC is not supported"
1559#endif
1561#define USE_HTTP3
1562#endif
1564/* WebAssembly builds have TCP_NODELAY, but runtime support is missing. */
1565#ifndef __EMSCRIPTEN__
1566#define CURL_TCP_NODELAY_SUPPORTED
1567#endif
1569/* Certain Windows implementations are not aligned with what curl expects,
1570 so always use the local one on this platform. E.g. the mingw-w64
1571 implementation can return wrong results for non-ASCII inputs. */
1572#if defined(HAVE_BASENAME) && defined(_WIN32)
1573#undef HAVE_BASENAME
1574#endif
1576#if defined(USE_UNIX_SOCKETS) && defined(_WIN32)
1577/* Offered by mingw-w64 v10+, MS SDK 10.0.16299.0/VS2017 15.4+ */
1578#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR >= 10)
1579# include <afunix.h>
1580#elif !defined(UNIX_PATH_MAX) /* Replicate logic present in afunix.h */
1581# define UNIX_PATH_MAX 108
1582/* !checksrc! disable TYPEDEFSTRUCT 1 */
1583typedef struct sockaddr_un {
1584 CURL_SA_FAMILY_T sun_family;
1585 char sun_path[UNIX_PATH_MAX];
1586} SOCKADDR_UN, *PSOCKADDR_UN;
1587#endif
1588#endif
1590#ifdef USE_OPENSSL
1591/* OpenSSL 3 marks these functions deprecated but we have no replacements (yet)
1592 so tell the compiler to not warn for them:
1593 - EVP_PKEY_get1_RSA, RSA_flags, RSA_free (auto-skipped for OpenSSL built
1594 with no-deprecated) */
1595# define OPENSSL_SUPPRESS_DEPRECATED
1596# ifdef _WIN32
1597/* Silence LibreSSL warnings about wincrypt.h collision. Works in 3.8.2+ */
1598# ifndef LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING
1599# define LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING
1600# endif
1601# endif
1602#endif
1604#ifdef CURL_INLINE
1605/* 'CURL_INLINE' defined, use as-is */
1606#elif defined(inline)
1607# define CURL_INLINE inline /* 'inline' defined, assumed correct */
1608#elif defined(__cplusplus)
1609/* The code is compiled with C++ compiler.
1610 C++ always supports 'inline'. */
1611# define CURL_INLINE inline /* 'inline' keyword supported */
1612#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
1613/* C99 (and later) supports 'inline' keyword */
1614# define CURL_INLINE inline /* 'inline' keyword supported */
1615#elif defined(__GNUC__) && __GNUC__ >= 3
1616/* GCC supports '__inline__' as an extension */
1617# define CURL_INLINE __inline__
1618#elif defined(_MSC_VER)
1619# define CURL_INLINE __inline
1620#else
1621/* Probably 'inline' is not supported by compiler.
1622 Define to the empty string to be on the safe side. */
1623# define CURL_INLINE /* empty */
1624#endif
1626/* Detect if compiler supports C99 variadic macros */
1627#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
1628 defined(_MSC_VER)
1629#define CURL_HAVE_MACRO_VARARG
1630#endif
1632#if !defined(CURL_HAVE_MACRO_VARARG) || \
1633 (defined(CURL_HAVE_MACRO_VARARG) && !defined(CURL_DISABLE_VERBOSE_STRINGS))
1634#define CURLVERBOSE
1635#define VERBOSE(x) x
1636#define NOVERBOSE(x) Curl_nop_stmt
1637#else
1638#define VERBOSE(x) Curl_nop_stmt
1639#define NOVERBOSE(x) x
1640#endif
1642/* For FreeBSD it is included from curl/curl.h */
1643#if defined(__DragonFly__) || defined(__OpenBSD__) || defined(__NetBSD__)
1644#include <sys/param.h> /* for __DragonFly_version, OpenBSD,
1645 __NetBSD_Version__ */
1646#endif
1648/* NetBSD before 6.1 did not set SS_NBIO for SOCK_NONBLOCK. */
1649#if defined(SOCK_NONBLOCK) && \
1650 (!defined(__NetBSD__) || (__NetBSD_Version__ >= 601000000))
1651#define CURL_USE_SOCK_NONBLOCK
1652#endif
1654#ifndef _CURL_LOCAL_MEMZERO /* to be removed after a couple of releases */
1655#ifdef _WIN32
1656#if defined(_MSC_VER) && defined(NTDDI_VERSION) && \
1657 (NTDDI_VERSION >= 0x0A000010) /* MS SDK 10.0.26100.0+ */
1658#pragma comment(lib, "volatileaccessu.lib")
1659#define curlx_memzero_low(buf, size) SecureZeroMemory2(buf, size)
1660#else
1661#define curlx_memzero_low(buf, size) SecureZeroMemory(buf, size)
1662#endif
1663#elif defined(HAVE_MEMSET_S)
1664#define curlx_memzero_low(buf, size) (void)memset_s(buf, size, 0, size)
1665#elif defined(HAVE_MEMSET_EXPLICIT)
1666#define curlx_memzero_low(buf, size) (void)memset_explicit(buf, 0, size)
1667#elif defined(__CYGWIN__) || \
1668 (defined(__NEWLIB__) && !defined(__CLIB2__)) || \
1669 (defined(__GLIBC__) && \
1670 (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))) || \
1671 (defined(__DragonFly__) && __DragonFly_version >= 500600 /* 5.6+ */) || \
1672 (defined(__FreeBSD__) && __FreeBSD_version >= 1100037 /* 11.0+ */) || \
1673 (defined(__OpenBSD__) && OpenBSD >= 201405 /* 5.5+ */)
1674#define curlx_memzero_low(buf, size) explicit_bzero(buf, size)
1675#elif defined(__NetBSD__) && __NetBSD_Version__ >= 702000000 /* 7.2+ */
1676#define curlx_memzero_low(buf, size) (void)explicit_memset(buf, 0, size)
1677#endif
1678#endif /* !_CURL_LOCAL_MEMZERO */
1680#ifndef curlx_memzero_low
1681#define USE_CURLX_MEMZERO
1682void curlx_memzero_low(void *buf, size_t size);
1683#endif
1684void curlx_memzero(void *buf, size_t size);
1685void curlx_strzero(void *buf);
1687#endif /* HEADER_CURL_SETUP_H */
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=19 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch20017 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=17644 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=1fce4a1355f86a8563429b1af81472d41d0f1ff6 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=17644 git.pkt.payload.max=17623 git.sideband.band1.bytes=17622 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e14ca7eca8a140
- Request
- b6739472…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format