Coverage Report

Created: 2026-10-22 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/curl_setup.h
Line
Count
Source
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
 ***************************************************************************/
26
27
#if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES)
28
#define CURL_NO_OLDIES
29
#endif
30
31
/* Set default _WIN32_WINNT */
32
#ifdef __MINGW32__
33
#include <_mingw.h>
34
#endif
35
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
55
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
77
78
#if defined(__MINGW32__) && \
79
  (!defined(__MINGW64_VERSION_MAJOR) || (__MINGW64_VERSION_MAJOR < 3))
80
#error "mingw-w64 3.0 or greater required"
81
#endif
82
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
88
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 */
96
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
109
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
120
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
127
128
/*
129
 * Include configuration script results or hand-crafted
130
 * configuration file for platforms which lack config tool.
131
 */
132
133
#ifdef HAVE_CONFIG_H
134
135
#include "curl_config.h"
136
137
#else /* HAVE_CONFIG_H */
138
139
#ifdef _WIN32
140
#  include "config-win32.h"
141
#endif
142
143
#ifdef macintosh
144
#  include "config-mac.h"
145
#endif
146
147
#ifdef __OS400__
148
#  include "config-os400.h"
149
#endif
150
151
#endif /* HAVE_CONFIG_H */
152
153
#ifdef _WIN32
154
#  if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
155
#    error The minimum build target is Windows Vista (0x0600)
156
#  endif
157
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
164
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
/* ================================================================ */
173
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
179
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
189
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
200
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
207
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
/* ================================================================ */
212
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
217
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
262
263
/* ================================================================ */
264
/* No system header file shall be included in this file before this */
265
/* point.                                                           */
266
/* ================================================================ */
267
268
/*
269
 * OS/400 setup file includes some system headers.
270
 */
271
#ifdef __OS400__
272
#  include "setup-os400.h"
273
#endif
274
275
/*
276
 * VMS setup file includes some system headers.
277
 */
278
#ifdef __VMS
279
#  include "setup-vms.h"
280
#endif
281
282
/*
283
 * Windows setup file includes some system headers.
284
 */
285
#ifdef _WIN32
286
#  include "setup-win32.h"
287
#endif
288
289
#include <curl/system.h>
290
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
314
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)
321
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
332
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
346
347
/* Override default printf mask check rules in "curl/mprintf.h" */
348
#define CURL_TEMP_PRINTF CURL_PRINTF
349
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
362
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
375
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
384
385
#ifdef USE_LWIPSOCK
386
#  include <lwip/init.h>
387
#  include <lwip/sockets.h>
388
#  include <lwip/netdb.h>
389
#endif
390
391
#ifdef macintosh
392
#  include <extra/stricmp.h>
393
#  include <extra/strdup.h>
394
#endif
395
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
440
441
/* Whether to use eventfd() */
442
#if defined(HAVE_EVENTFD) && defined(HAVE_SYS_EVENTFD_H)
443
#define USE_EVENTFD
444
#endif
445
446
#ifdef SO_NOSIGPIPE
447
#define USE_SO_NOSIGPIPE
448
#endif
449
450
#include <stdio.h>
451
#include <assert.h>
452
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
458
459
#include <stdint.h>
460
#define HAVE_UINTPTR_T  /* assume uintptr_t is provided by stdint.h */
461
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
468
469
/* Disable uintptr_t for targets known to miss it from stdint.h */
470
#ifdef __OS400__
471
#undef HAVE_UINTPTR_T
472
#endif
473
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>
479
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
0
#  define curl_lseek                      lseek
498
#  define LSEEK_ERROR                     ((off_t)-1)
499
#endif
500
501
#ifndef SIZEOF_TIME_T
502
/* assume default size of time_t to be 32 bits */
503
#define SIZEOF_TIME_T 4
504
#endif
505
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
515
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
527
528
/*
529
 * Default sizeof(off_t) in case it has not been defined in config file.
530
 */
531
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
554
555
#if SIZEOF_CURL_OFF_T < 8
556
#error "too small curl_off_t"
557
#else
558
   /* assume SIZEOF_CURL_OFF_T == 8 */
559
5.24M
#  define CURL_OFF_T_MAX 0x7FFFFFFFFFFFFFFF
560
#endif
561
1.59M
#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - 1)
562
563
10
#define FMT_OFF_T  CURL_FORMAT_CURL_OFF_T
564
#define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU
565
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
1.07k
#  define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
580
#  define TIME_T_MIN (-TIME_T_MAX - 1)
581
#  endif
582
#endif
583
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
592
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
601
602
#if SIZEOF_LONG > SIZEOF_SIZE_T
603
#error "unexpected: 'long' is larger than 'size_t'"
604
#endif
605
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
616
617
/* Below we define some functions. They should
618
   4. set the SIGALRM signal timeout
619
   5. set dir/file naming defines
620
 */
621
622
#ifdef _WIN32
623
624
#  define DIR_CHAR      "\\"
625
626
#else /* _WIN32 */
627
628
#  ifdef MSDOS  /* Watt-32 */
629
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
636
637
#  endif /* MSDOS */
638
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
643
644
0
#  define DIR_CHAR      "/"
645
646
#endif /* _WIN32 */
647
648
/* We want to use mutex when available. */
649
#if defined(HAVE_THREADS_POSIX) || defined(_WIN32)
650
#define USE_MUTEX
651
#endif
652
653
/* threaded resolver is the only feature requiring threads. */
654
#ifdef USE_RESOLV_THREADED
655
#define USE_THREADS
656
#endif
657
658
/* ---------------------------------------------------------------- */
659
/*             resolver specialty compile-time defines              */
660
/*         CURLRES_* defines to use in the host*.c sources          */
661
/* ---------------------------------------------------------------- */
662
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
674
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
685
686
/* ---------------------------------------------------------------- */
687
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
693
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
697
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
702
703
#if defined(USE_OPENSSL) && defined(USE_WOLFSSL)
704
#ifndef OPENSSL_COEXIST
705
#define OPENSSL_COEXIST
706
#endif
707
#endif
708
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
713
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
719
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
725
726
/* Single point where USE_NTLM definition might be defined */
727
#ifdef CURL_ENABLE_NTLM
728
#  if (defined(USE_OPENSSL) && defined(HAVE_DES_ECB_ENCRYPT)) ||   \
729
  defined(USE_GNUTLS) ||                                           \
730
  (defined(USE_MBEDTLS) && defined(HAVE_MBEDTLS_DES_CRYPT_ECB)) || \
731
  defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) ||         \
732
  (defined(USE_WOLFSSL) && defined(HAVE_WC_DES_ECBENCRYPT))
733
#    define USE_CURL_NTLM_CORE
734
#  endif
735
#  if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI)
736
#    define USE_NTLM
737
#  endif
738
#endif
739
740
#if defined(USE_LIBSSH2) || defined(USE_LIBSSH)
741
#define USE_SSH
742
#endif
743
744
/* GCC <4.6 does not support '#pragma GCC diagnostic push' and does not support
745
   'pragma GCC diagnostic' inside functions.
746
   Use CURL_HAVE_DIAG to guard the above in the curl codebase, instead of
747
   defined(__GNUC__) || defined(__clang__).
748
 */
749
#if defined(__clang__) || (defined(__GNUC__) && \
750
  ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))))
751
#define CURL_HAVE_DIAG
752
#endif
753
754
/*
755
 * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
756
 * Parameters should of course normally not be unused, but for example when
757
 * we have multiple implementations of the same interface it may happen.
758
 */
759
#if defined(__GNUC__) && ((__GNUC__ >= 3) || \
760
  ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
761
#  define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
762
#elif defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 9040001)
763
#  define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
764
#else
765
#  define WARN_UNUSED_RESULT
766
#endif
767
768
/* noreturn attribute */
769
770
#ifndef CURL_NORETURN
771
#if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \
772
  defined(__IAR_SYSTEMS_ICC__)
773
#  define CURL_NORETURN  __attribute__((__noreturn__))
774
#elif defined(_MSC_VER)
775
#  define CURL_NORETURN  __declspec(noreturn)
776
#else
777
#  define CURL_NORETURN
778
#endif
779
#endif
780
781
/* fallthrough attribute */
782
783
#ifndef FALLTHROUGH
784
#if (defined(__GNUC__) && __GNUC__ >= 7) ||     \
785
  (defined(__clang__) && __clang_major__ >= 10)
786
1.33M
#  define FALLTHROUGH()  __attribute__((fallthrough))
787
#else
788
#  define FALLTHROUGH()  do {} while(0)
789
#endif
790
#endif
791
792
/*
793
 * Inclusion of common header files.
794
 */
795
796
#include <stdlib.h>
797
#include <string.h>
798
#include <stdarg.h>
799
#include <time.h>
800
#include <errno.h>
801
802
#include <sys/stat.h>
803
804
#if !defined(_WIN32) || defined(__MINGW32__)
805
#include <sys/time.h>
806
#endif
807
808
#ifdef HAVE_IO_H
809
#include <io.h>
810
#endif
811
812
#ifdef HAVE_FCNTL_H
813
#include <fcntl.h>
814
#endif
815
816
#if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T)
817
#include <stdbool.h>
818
#endif
819
820
#ifdef HAVE_UNISTD_H
821
#include <unistd.h>
822
#endif
823
824
/* Macro to strip 'const' without triggering a compiler warning.
825
   Use it for APIs that do not or cannot support the const qualifier. */
826
#ifdef HAVE_UINTPTR_T
827
1.69M
#define CURL_UNCONST(p) ((void *)(uintptr_t)(const void *)(p))
828
#else
829
#define CURL_UNCONST(p) ((void *)(p))  /* Fall back to simple cast */
830
#endif
831
832
#ifdef USE_SCHANNEL
833
/* Must set this before <schannel.h> is included directly or indirectly by
834
   another Windows header. */
835
#  define SCHANNEL_USE_BLACKLISTS  /* for SCH_CREDENTIALS */
836
#  include <subauth.h>  /* for [P]UNICODE_STRING in SCH_CREDENTIALS */
837
#endif
838
839
#ifdef __hpux
840
#  if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
841
#    ifdef _APP32_64BIT_OFF_T
842
#      define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T
843
#      undef _APP32_64BIT_OFF_T
844
#    else
845
#      undef OLD_APP32_64BIT_OFF_T
846
#    endif
847
#  endif
848
#endif
849
850
#ifndef _WIN32
851
#include <sys/socket.h>  /* also for MSG_NOSIGNAL */
852
#endif
853
854
#include "functypes.h"
855
856
#ifdef __hpux
857
#  if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
858
#    ifdef OLD_APP32_64BIT_OFF_T
859
#      define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T
860
#      undef OLD_APP32_64BIT_OFF_T
861
#    endif
862
#  endif
863
#endif
864
865
/*
866
 * Definition of timeval struct for platforms that do not have it.
867
 */
868
#ifndef HAVE_STRUCT_TIMEVAL
869
struct timeval {
870
  long tv_sec;
871
  long tv_usec;
872
};
873
#endif
874
875
/*
876
 * If we have the MSG_NOSIGNAL define, make sure we use
877
 * it as the fourth argument of function send()
878
 */
879
#ifdef MSG_NOSIGNAL
880
52.2k
#define SEND_4TH_ARG MSG_NOSIGNAL
881
#else
882
#define SEND_4TH_ARG 0
883
#endif
884
885
#ifdef __minix
886
/* Minix does not support recv on TCP sockets */
887
#define sread(x, y, z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
888
                                     (RECV_TYPE_ARG2)(y), \
889
                                     (RECV_TYPE_ARG3)(z))
890
891
#elif defined(HAVE_RECV)
892
/*
893
 * The definitions for the return type and arguments types
894
 * of functions recv() and send() belong and come from the
895
 * configuration file. Do not define them in any other place.
896
 *
897
 * HAVE_RECV is defined if you have a function named recv()
898
 * which is used to read incoming data from sockets. If your
899
 * function has another name then do not define HAVE_RECV.
900
 *
901
 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
902
 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
903
 * be defined.
904
 *
905
 * HAVE_SEND is defined if you have a function named send()
906
 * which is used to write outgoing data on a connected socket.
907
 * If yours has another name then do not define HAVE_SEND.
908
 *
909
 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_TYPE_ARG2,
910
 * SEND_TYPE_ARG3, SEND_TYPE_ARG4 and SEND_TYPE_RETV must also
911
 * be defined. SEND_NONCONST_ARG2 must also be defined if ARG2
912
 * does not accept const.
913
 */
914
915
815k
#define sread(x, y, z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
916
815k
                                     (RECV_TYPE_ARG2)(y), \
917
815k
                                     (RECV_TYPE_ARG3)(z), \
918
815k
                                     (RECV_TYPE_ARG4)(0))
919
#else /* HAVE_RECV */
920
#ifndef sread
921
#error "Missing definition of macro sread"
922
#endif
923
#endif /* HAVE_RECV */
924
925
#ifdef __minix
926
/* Minix does not support send on TCP sockets */
927
#define swrite(x, y, z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
928
                                       (SEND_TYPE_ARG2)CURL_UNCONST(y), \
929
                                       (SEND_TYPE_ARG3)(z))
930
#elif defined(HAVE_SEND)
931
#ifdef SEND_NONCONST_ARG2
932
#define swrite(x, y, z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
933
                                      (SEND_TYPE_ARG2)CURL_UNCONST(y), \
934
                                      (SEND_TYPE_ARG3)(z), \
935
                                      (SEND_TYPE_ARG4)(SEND_4TH_ARG))
936
#else
937
52.2k
#define swrite(x, y, z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
938
52.2k
                                      (const SEND_TYPE_ARG2)(y), \
939
52.2k
                                      (SEND_TYPE_ARG3)(z), \
940
52.2k
                                      (SEND_TYPE_ARG4)(SEND_4TH_ARG))
941
#endif /* SEND_NONCONST_ARG2 */
942
#else /* HAVE_SEND */
943
#ifndef swrite
944
#error "Missing definition of macro swrite"
945
#endif
946
#endif /* HAVE_SEND */
947
948
/*
949
 * Function-like macro definition used to close a socket.
950
 */
951
#ifdef HAVE_CLOSESOCKET
952
#  define CURL_SCLOSE(x)  closesocket(x)
953
#elif defined(HAVE_CLOSESOCKET_CAMEL)
954
#  define CURL_SCLOSE(x)  CloseSocket(x)
955
#elif defined(MSDOS)  /* Watt-32 */
956
#  define CURL_SCLOSE(x)  close_s(x)
957
#elif defined(USE_LWIPSOCK)
958
#  define CURL_SCLOSE(x)  lwip_close(x)
959
#else
960
46.0k
#  define CURL_SCLOSE(x)  close(x)
961
#endif
962
963
/*
964
 * Stack-independent version of fcntl() on sockets:
965
 */
966
#ifdef USE_LWIPSOCK
967
#  define sfcntl  lwip_fcntl
968
#else
969
22.6k
#  define sfcntl  fcntl
970
#endif
971
972
/*
973
 * 'bool' stuff compatible with HP-UX headers.
974
 */
975
#if defined(__hpux) && !defined(HAVE_BOOL_T)
976
typedef int bool;
977
#  define false 0
978
#  define true 1
979
#  define HAVE_BOOL_T
980
#endif
981
982
/*
983
 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
984
 * On non-C99 platforms there is no bool, so define an enum for that.
985
 * On C99 platforms 'false' and 'true' also exist. Enum uses a
986
 * global namespace though, so use bool_false and bool_true.
987
 */
988
#ifndef HAVE_BOOL_T
989
/* This replacement type does not preserve C99 bool's normalization semantics:
990
   converting a non-zero value to C99 bool results in 1. This is significant
991
   when the value is assigned to a bit-field. Make sure to normalize manually
992
   in such cases. */
993
typedef enum {
994
  bool_false = 0,
995
  bool_true = 1
996
} bool;
997
998
/*
999
 * Use a define to let 'true' and 'false' use those enums. There
1000
 * are currently no use of true and false in libcurl proper, but
1001
 * there are some in the examples. This will cater for any later
1002
 * code happening to use true and false.
1003
 */
1004
#  define false bool_false
1005
#  define true  bool_true
1006
#  define HAVE_BOOL_T
1007
#endif
1008
1009
/* the type we use for storing a single boolean bit */
1010
typedef unsigned int curl_bit;
1011
#define BIT(x) curl_bit x:1
1012
1013
/*
1014
 * Redefine TRUE and FALSE too, to catch current use. With this
1015
 * change, 'bool found = 1' will give a warning on MIPSPro, but
1016
 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
1017
 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
1018
 */
1019
#ifndef TRUE
1020
12.8M
#define TRUE true
1021
#endif
1022
#ifndef FALSE
1023
57.4M
#define FALSE false
1024
#endif
1025
1026
#include "curl_ctype.h"
1027
1028
#if defined(DEBUGBUILD) && defined(NDEBUG)
1029
#error "Debug-enabled builds cannot be combined with NDEBUG"
1030
#endif
1031
1032
/*
1033
 * Macro used to include code only in debug builds.
1034
 */
1035
#ifdef DEBUGBUILD
1036
666k
#define DEBUGF(x) x
1037
#else
1038
#define DEBUGF(x) do {} while(0)
1039
#endif
1040
1041
/*
1042
 * Macro used to include assertion code only in debug builds.
1043
 */
1044
#undef DEBUGASSERT
1045
#ifdef DEBUGBUILD
1046
#ifdef CURL_DEBUGASSERT
1047
/* External assertion handler for custom integrations */
1048
#define DEBUGASSERT(x) CURL_DEBUGASSERT(x)
1049
#else
1050
0
#define DEBUGASSERT(x) assert(x)
1051
#endif
1052
#else
1053
#define DEBUGASSERT(x) do {} while(0)
1054
#endif
1055
1056
/* Macro to configure Visual Studio debug CRT to output errors to stderr and
1057
   the debugger, replacing the interactive GUI dialog. */
1058
#if defined(_MSC_VER) && defined(_DEBUG) && defined(CURL_DEBUG_MSVC_CRTDBG)
1059
#include <crtdbg.h> /* for _CrtSetReportFile(), _CRT* macros */
1060
#define CURL_MSVC_CRTDBG_INIT()                                             \
1061
  do {                                                                      \
1062
    _set_error_mode(_OUT_TO_STDERR);  /* needs stdlib.h */                  \
1063
    _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); \
1064
    _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);                    \
1065
    _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);  \
1066
    _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);                     \
1067
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);   \
1068
    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);                      \
1069
  } while(0)
1070
#else
1071
#define CURL_MSVC_CRTDBG_INIT() do {} while(0)
1072
#endif
1073
1074
#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
1075
#include <tlhelp32.h>
1076
/* Print the list of all loaded modules with full paths. */
1077
#define CURL_DUMP_MODULE_PATHS(printf_f)                               \
1078
  do {                                                                 \
1079
    HANDLE hnd = INVALID_HANDLE_VALUE;                                 \
1080
    MODULEENTRY32 mod = { 0 };                                         \
1081
                                                                       \
1082
    mod.dwSize = sizeof(MODULEENTRY32);                                \
1083
                                                                       \
1084
    do {                                                               \
1085
      hnd = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);            \
1086
    } while(hnd == INVALID_HANDLE_VALUE &&                             \
1087
            GetLastError() == ERROR_BAD_LENGTH);                       \
1088
                                                                       \
1089
    if(hnd == INVALID_HANDLE_VALUE)                                    \
1090
      goto error;                                                      \
1091
                                                                       \
1092
    if(!Module32First(hnd, &mod))                                      \
1093
      goto error;                                                      \
1094
                                                                       \
1095
    do {                                                               \
1096
      char buffer[sizeof(mod.szExePath) * 2];                          \
1097
      char *path; /* points to stack allocated buffer */               \
1098
      if(sizeof(*mod.szExePath) > 1) {  /* _UNICODE */                 \
1099
        /* sizeof(mod.szExePath) is the max total bytes of   */        \
1100
        /* wchars. the max total bytes of multibyte chars is */        \
1101
        /* not more than twice that.                         */        \
1102
        if(!WideCharToMultiByte(CP_ACP, 0, (WCHAR *)mod.szExePath, -1, \
1103
                                buffer, sizeof(buffer), NULL, NULL))   \
1104
          goto error;                                                  \
1105
        path = (char *)buffer;                                         \
1106
      }                                                                \
1107
      else                                                             \
1108
        path = (char *)mod.szExePath;                                  \
1109
      (printf_f)("%s\n", path);                                        \
1110
    } while(Module32Next(hnd, &mod));                                  \
1111
                                                                       \
1112
error:                                                                 \
1113
    if(hnd != INVALID_HANDLE_VALUE)                                    \
1114
      CloseHandle(hnd);                                                \
1115
  } while(0)
1116
#else
1117
#define CURL_DUMP_MODULE_PATHS(printf_f) do {} while(0)
1118
#endif
1119
1120
/*
1121
 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
1122
 * (or equivalent) on this platform to hide platform details to code using it.
1123
 */
1124
#ifdef USE_WINSOCK
1125
#define SOCKERRNO         ((int)WSAGetLastError())
1126
#define SET_SOCKERRNO(x)  WSASetLastError((int)(x))
1127
#else
1128
37.2k
#define SOCKERRNO         errno
1129
5
#define SET_SOCKERRNO(x)  (errno = (x))
1130
#endif
1131
1132
/*
1133
 * Portable error number symbolic names defined to Winsock error codes.
1134
 */
1135
#ifdef USE_WINSOCK
1136
#define SOCKEACCES        WSAEACCES
1137
#define SOCKEADDRINUSE    WSAEADDRINUSE
1138
#define SOCKEADDRNOTAVAIL WSAEADDRNOTAVAIL
1139
#define SOCKEAFNOSUPPORT  WSAEAFNOSUPPORT
1140
#define SOCKEBADF         WSAEBADF
1141
#define SOCKECONNREFUSED  WSAECONNREFUSED
1142
#define SOCKECONNRESET    WSAECONNRESET
1143
#define SOCKEINPROGRESS   WSAEINPROGRESS
1144
#define SOCKEINTR         WSAEINTR
1145
#define SOCKEINVAL        WSAEINVAL
1146
#define SOCKEISCONN       WSAEISCONN
1147
#define SOCKEMSGSIZE      WSAEMSGSIZE
1148
/* Use literal value to work around clang-tidy <=20 misreporting
1149
   'readability-uppercase-literal-suffix' with mingw-w64 headers */
1150
#define SOCKENOMEM        8L  /* WSA_NOT_ENOUGH_MEMORY */
1151
#define SOCKETIMEDOUT     WSAETIMEDOUT
1152
#define SOCKEWOULDBLOCK   WSAEWOULDBLOCK
1153
#else
1154
0
#define SOCKEACCES        EACCES
1155
0
#define SOCKEADDRINUSE    EADDRINUSE
1156
0
#define SOCKEADDRNOTAVAIL EADDRNOTAVAIL
1157
0
#define SOCKEAFNOSUPPORT  EAFNOSUPPORT
1158
#define SOCKEBADF         EBADF
1159
#define SOCKECONNREFUSED  ECONNREFUSED
1160
0
#define SOCKECONNRESET    ECONNRESET
1161
28
#define SOCKEINPROGRESS   EINPROGRESS
1162
29.4k
#define SOCKEINTR         EINTR
1163
#define SOCKEINVAL        EINVAL
1164
5
#define SOCKEISCONN       EISCONN
1165
#define SOCKEMSGSIZE      EMSGSIZE
1166
0
#define SOCKENOMEM        ENOMEM
1167
#ifdef ETIMEDOUT
1168
517
#define SOCKETIMEDOUT     ETIMEDOUT
1169
#endif
1170
36.5k
#define SOCKEWOULDBLOCK   EWOULDBLOCK
1171
#endif
1172
1173
/* The socket error may be EWOULDBLOCK or on some systems EAGAIN when
1174
   it returned due to its inability to send/read data without blocking.
1175
   We treat both error codes the same here. */
1176
#if !defined(USE_WINSOCK) && EAGAIN != SOCKEWOULDBLOCK
1177
#define SOCK_EAGAIN(e) ((e) == SOCKEWOULDBLOCK || (e) == EAGAIN)
1178
#else
1179
43.6k
#define SOCK_EAGAIN(e) ((e) == SOCKEWOULDBLOCK)
1180
#endif
1181
1182
/*
1183
 * Macro argv_item_t hides platform details to code using it.
1184
 */
1185
#ifdef __VMS
1186
#define argv_item_t  __char_ptr32
1187
#elif defined(_UNICODE)
1188
#define argv_item_t  wchar_t *
1189
#else
1190
#define argv_item_t  char *
1191
#endif
1192
1193
/*
1194
 * We use this ZERO_NULL to avoid picky compiler warnings,
1195
 * when assigning a NULL pointer to a function pointer var.
1196
 */
1197
192k
#define ZERO_NULL 0
1198
1199
/*
1200
 * Macros and functions to safely suppress warnings
1201
 */
1202
#include "curlx/warnless.h"
1203
1204
#ifdef _WIN32
1205
#  undef read
1206
#  define read(fd, buf, count)  (ssize_t)_read(fd, buf, curlx_uztoui(count))
1207
#  undef write
1208
#  define write(fd, buf, count) (ssize_t)_write(fd, buf, curlx_uztoui(count))
1209
/* Avoid VS2005+ _CRT_NONSTDC_NO_DEPRECATE warnings about non-portable funcs */
1210
#  undef fileno
1211
#  define fileno(fh) _fileno(fh)
1212
#  undef unlink
1213
#  define unlink(fn) _unlink(fn)
1214
#  undef isatty
1215
#  define isatty(fd) _isatty(fd)
1216
#endif
1217
1218
/*
1219
 * Definition of our NOP statement Object-like macro
1220
 */
1221
#ifndef Curl_nop_stmt
1222
497k
#define Curl_nop_stmt do {} while(0)
1223
#endif
1224
1225
/*
1226
 * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
1227
 */
1228
#if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
1229
#  if defined(SOCKET) || defined(USE_WINSOCK)
1230
#    error "Winsock and lwIP TCP/IP stack definitions shall not coexist"
1231
#  endif
1232
#endif
1233
1234
/*
1235
 * shutdown() flags for systems that do not define them
1236
 */
1237
#ifndef SHUT_RD
1238
#define SHUT_RD 0x00
1239
#endif
1240
1241
#ifndef SHUT_WR
1242
#define SHUT_WR 0x01
1243
#endif
1244
1245
#ifndef SHUT_RDWR
1246
#define SHUT_RDWR 0x02
1247
#endif
1248
1249
/* Define S_ISREG if not defined by system headers, e.g. MSVC */
1250
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
1251
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
1252
#endif
1253
1254
/* Define S_ISDIR if not defined by system headers, e.g. MSVC */
1255
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
1256
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1257
#endif
1258
1259
/* For MSVC (all versions as of VS2022) */
1260
#ifndef STDIN_FILENO
1261
#define STDIN_FILENO  fileno(stdin)
1262
#endif
1263
#ifndef STDOUT_FILENO
1264
#define STDOUT_FILENO  fileno(stdout)
1265
#endif
1266
#ifndef STDERR_FILENO
1267
#define STDERR_FILENO  fileno(stderr)
1268
#endif
1269
1270
/* Since O_BINARY is used in bitmasks, setting it to zero makes it usable in
1271
   source code but yet it does not ruin anything */
1272
#ifdef _O_BINARY  /* for _WIN32 || MSDOS */
1273
#define CURL_O_BINARY _O_BINARY
1274
#elif defined(O_BINARY)  /* __CYGWIN__ */
1275
#define CURL_O_BINARY O_BINARY
1276
#else
1277
0
#define CURL_O_BINARY 0
1278
#endif
1279
1280
/* Requires io.h when available */
1281
#ifdef MSDOS
1282
#define CURL_BINMODE(stream) (void)setmode(fileno(stream), CURL_O_BINARY)
1283
#elif defined(_WIN32) || defined(__CYGWIN__)
1284
#define CURL_BINMODE(stream) (void)_setmode(fileno(stream), CURL_O_BINARY)
1285
#else
1286
#define CURL_BINMODE(stream) (void)(stream)
1287
#endif
1288
1289
/* In Windows the default file mode is text but an application can override it.
1290
   Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 */
1291
#if defined(_WIN32) || defined(MSDOS)
1292
#define FOPEN_READTEXT   "rt"
1293
#define FOPEN_WRITETEXT  "wt"
1294
#define FOPEN_APPENDTEXT "at"
1295
#elif defined(__CYGWIN__)
1296
/* Cygwin has specific behavior we need to address when _WIN32 is not defined.
1297
   https://cygwin.com/cygwin-ug-net/using-textbinary.html
1298
   For write we want our output to have line endings of LF and be compatible
1299
   with other Cygwin utilities. For read we want to handle input that may have
1300
   line endings either CRLF or LF so 't' is appropriate. */
1301
#define FOPEN_READTEXT   "rt"
1302
#define FOPEN_WRITETEXT  "w"
1303
#define FOPEN_APPENDTEXT "a"
1304
#else
1305
#define FOPEN_READTEXT   "r"
1306
0
#define FOPEN_WRITETEXT  "w"
1307
#define FOPEN_APPENDTEXT "a"
1308
#endif
1309
1310
/* for systems that do not detect this in configure */
1311
#ifndef CURL_SA_FAMILY_T
1312
#  ifdef USE_WINSOCK
1313
#    define CURL_SA_FAMILY_T ADDRESS_FAMILY
1314
#  elif defined(HAVE_SA_FAMILY_T)
1315
0
#    define CURL_SA_FAMILY_T sa_family_t
1316
#  elif defined(__AMIGA__)
1317
#    define CURL_SA_FAMILY_T unsigned char
1318
#  else
1319
/* use a sensible default */
1320
#    define CURL_SA_FAMILY_T unsigned short
1321
#  endif
1322
#endif
1323
1324
/* Some convenience macros to get the larger/smaller value out of two given.
1325
   We prefix with CURL to prevent name collisions. */
1326
49.5k
#define CURLMAX(x, y) ((x) > (y) ? (x) : (y))
1327
1.17M
#define CURLMIN(x, y) ((x) < (y) ? (x) : (y))
1328
1329
/* Convenience macro to provide the length of a string literal size without
1330
   the null-terminator. Equivalent to strlen() for constant strings. */
1331
6.09M
#define CURL_CSTRLEN(x) (sizeof(x) - 1)
1332
1333
/* A convenience macro to provide both the string literal and the length of
1334
   the string literal in one go, useful for functions that take "string,len"
1335
   as their argument */
1336
5.98M
#define STRCONST(x) x, CURL_CSTRLEN(x)
1337
1338
2.38M
#define CURL_ARRAYSIZE(A) (sizeof(A) / sizeof((A)[0]))
1339
1340
/* Buffer size for error messages retrieved via
1341
   curlx_strerror() and Curl_sspi_strerror() */
1342
#define STRERROR_LEN 256
1343
1344
#ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS /* only if not already done */
1345
/*
1346
 * The following memory function replacement typedef's are COPIED from
1347
 * curl/curl.h and MUST match the originals. We copy them to avoid having to
1348
 * include curl/curl.h here. We avoid that include since it includes stdio.h
1349
 * and other headers that may get messed up with defines done here.
1350
 */
1351
typedef void *(*curl_malloc_callback)(size_t size);
1352
typedef void (*curl_free_callback)(void *ptr);
1353
typedef void *(*curl_realloc_callback)(void *ptr, size_t size);
1354
typedef char *(*curl_strdup_callback)(const char *str);
1355
typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size);
1356
#define CURL_DID_MEMORY_FUNC_TYPEDEFS
1357
#endif
1358
1359
extern curl_malloc_callback Curl_cmalloc;
1360
extern curl_free_callback Curl_cfree;
1361
extern curl_realloc_callback Curl_crealloc;
1362
extern curl_strdup_callback Curl_cstrdup;
1363
extern curl_calloc_callback Curl_ccalloc;
1364
1365
/*
1366
 * curlx_safefree() defined as a macro to allow MemoryTracking feature
1367
 * to log free() calls at same location where curlx_safefree() is used.
1368
 * This macro also assigns NULL to given pointer when free'd.
1369
 */
1370
#define curlx_safefree(ptr) \
1371
8.68M
  do {                      \
1372
8.63M
    curlx_free(ptr);        \
1373
8.63M
    (ptr) = NULL;           \
1374
8.63M
  } while(0)
1375
1376
#include <curl/curl.h> /* for CURL_EXTERN, curl_socket_t, mprintf.h */
1377
1378
#ifdef DEBUGBUILD
1379
#define CURL_MEMDEBUG
1380
#endif
1381
1382
#ifdef CURL_MEMDEBUG
1383
#ifdef __clang__
1384
#  define ALLOC_FUNC         __attribute__((__malloc__))
1385
#  if __clang_major__ >= 4
1386
#  define ALLOC_SIZE(s)      __attribute__((__alloc_size__(s)))
1387
#  define ALLOC_SIZE2(n, s)  __attribute__((__alloc_size__(n, s)))
1388
#  else
1389
#  define ALLOC_SIZE(s)
1390
#  define ALLOC_SIZE2(n, s)
1391
#  endif
1392
#elif defined(__GNUC__) && __GNUC__ >= 3
1393
#  define ALLOC_FUNC         __attribute__((__malloc__))
1394
#  define ALLOC_SIZE(s)      __attribute__((__alloc_size__(s)))
1395
#  define ALLOC_SIZE2(n, s)  __attribute__((__alloc_size__(n, s)))
1396
#elif defined(_MSC_VER)
1397
#  define ALLOC_FUNC         __declspec(restrict)
1398
#  define ALLOC_SIZE(s)
1399
#  define ALLOC_SIZE2(n, s)
1400
#else
1401
#  define ALLOC_FUNC
1402
#  define ALLOC_SIZE(s)
1403
#  define ALLOC_SIZE2(n, s)
1404
#endif
1405
1406
extern FILE *curl_dbg_logfile;
1407
1408
/* memory functions */
1409
CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source);
1410
CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1)
1411
  void *curl_dbg_malloc(size_t wantedsize, int line, const char *source);
1412
CURL_EXTERN ALLOC_FUNC ALLOC_SIZE2(1, 2)
1413
  void *curl_dbg_calloc(size_t wanted_elements, size_t wanted_size,
1414
                        int line, const char *source);
1415
CURL_EXTERN ALLOC_SIZE(2)
1416
  void *curl_dbg_realloc(void *ptr, size_t wantedsize, int line,
1417
                         const char *source);
1418
CURL_EXTERN ALLOC_FUNC
1419
  char *curl_dbg_strdup(const char *str, int line, const char *source);
1420
#if defined(_WIN32) && defined(UNICODE)
1421
CURL_EXTERN ALLOC_FUNC
1422
  wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source);
1423
#endif
1424
1425
CURL_EXTERN void curl_dbg_memdebug(const char *logname);
1426
CURL_EXTERN void curl_dbg_memlimit(long limit);
1427
CURL_EXTERN void curl_dbg_log(const char *format, ...) CURL_PRINTF(1, 2);
1428
1429
/* file descriptor manipulators */
1430
CURL_EXTERN curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
1431
                                          int line, const char *source);
1432
CURL_EXTERN void curl_dbg_mark_sclose(curl_socket_t sockfd,
1433
                                      int line, const char *source);
1434
CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd,
1435
                                int line, const char *source);
1436
CURL_EXTERN curl_socket_t curl_dbg_accept(curl_socket_t s,
1437
                                          void *saddr, void *saddrlen,
1438
                                          int line, const char *source);
1439
#ifdef HAVE_ACCEPT4
1440
CURL_EXTERN curl_socket_t curl_dbg_accept4(curl_socket_t s, void *saddr,
1441
                                           void *saddrlen, int flags,
1442
                                           int line, const char *source);
1443
#endif
1444
#ifdef HAVE_SOCKETPAIR
1445
CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol,
1446
                                    curl_socket_t socket_vector[2],
1447
                                    int line, const char *source);
1448
#endif
1449
1450
/* FILE functions */
1451
CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
1452
CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fopen(const char *file, const char *mode,
1453
                                            int line, const char *source);
1454
CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_freopen(const char *file,
1455
                                              const char *mode, FILE *fh,
1456
                                              int line, const char *source);
1457
CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
1458
                                             int line, const char *source);
1459
1460
46.0k
#define sclose(sockfd) curl_dbg_sclose(sockfd, __LINE__, __FILE__)
1461
#define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd, __LINE__, __FILE__)
1462
1463
#define CURL_GETADDRINFO(host, serv, hint, res) \
1464
116
  curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
1465
#define CURL_FREEADDRINFO(data) \
1466
0
  curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
1467
#define CURL_SOCKET(domain, type, protocol) \
1468
23.3k
  curl_dbg_socket((int)(domain), type, protocol, __LINE__, __FILE__)
1469
#ifdef HAVE_SOCKETPAIR
1470
#define CURL_SOCKETPAIR(domain, type, protocol, socket_vector) \
1471
  curl_dbg_socketpair((int)(domain), type, protocol, socket_vector, \
1472
                      __LINE__, __FILE__)
1473
#endif
1474
#define CURL_ACCEPT(sock, addr, len) \
1475
  curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
1476
#ifdef HAVE_ACCEPT4
1477
#define CURL_ACCEPT4(sock, addr, len, flags) \
1478
0
  curl_dbg_accept4(sock, addr, len, flags, __LINE__, __FILE__)
1479
#endif
1480
1481
#else /* !CURL_MEMDEBUG */
1482
1483
#define sclose(x) CURL_SCLOSE(x)
1484
#define fake_sclose(x) Curl_nop_stmt
1485
1486
#define CURL_GETADDRINFO getaddrinfo
1487
#define CURL_FREEADDRINFO freeaddrinfo
1488
#define CURL_SOCKET socket
1489
#ifdef HAVE_SOCKETPAIR
1490
#define CURL_SOCKETPAIR socketpair
1491
#endif
1492
#define CURL_ACCEPT accept
1493
#ifdef HAVE_ACCEPT4
1494
#define CURL_ACCEPT4 accept4
1495
#endif
1496
1497
#endif /* CURL_MEMDEBUG */
1498
1499
/* Allocator macros */
1500
1501
#ifdef _WIN32
1502
#define CURLX_STRDUP_LOW _strdup
1503
#else
1504
1
#define CURLX_STRDUP_LOW strdup
1505
#endif
1506
1507
#ifdef CURL_MEMDEBUG
1508
1509
267k
#define curlx_strdup(ptr)          curl_dbg_strdup(ptr, __LINE__, __FILE__)
1510
1.31M
#define curlx_malloc(size)         curl_dbg_malloc(size, __LINE__, __FILE__)
1511
#define curlx_calloc(nbelem, size) \
1512
1.57M
  curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
1513
#define curlx_realloc(ptr, size) \
1514
803k
  curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
1515
12.7M
#define curlx_free(ptr)            curl_dbg_free(ptr, __LINE__, __FILE__)
1516
1517
#ifdef _WIN32
1518
#ifdef UNICODE
1519
#define curlx_tcsdup(ptr)          curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
1520
#else
1521
#define curlx_tcsdup               curlx_strdup
1522
#endif
1523
#endif /* _WIN32 */
1524
1525
#else /* !CURL_MEMDEBUG */
1526
1527
#ifdef BUILDING_LIBCURL
1528
#define curlx_strdup               Curl_cstrdup
1529
#define curlx_malloc               Curl_cmalloc
1530
#define curlx_calloc               Curl_ccalloc
1531
#define curlx_realloc              Curl_crealloc
1532
#define curlx_free                 Curl_cfree
1533
#else /* !BUILDING_LIBCURL */
1534
#define curlx_strdup               CURLX_STRDUP_LOW
1535
#define curlx_malloc               malloc
1536
#define curlx_calloc               calloc
1537
#define curlx_realloc              realloc
1538
#define curlx_free                 free
1539
#endif /* BUILDING_LIBCURL */
1540
1541
#ifdef _WIN32
1542
#ifdef UNICODE
1543
#define curlx_tcsdup               curlx_wcsdup
1544
#else
1545
#define curlx_tcsdup               curlx_strdup
1546
#endif
1547
#endif /* _WIN32 */
1548
1549
#endif /* CURL_MEMDEBUG */
1550
1551
/* Some versions of the Android NDK is missing the declaration */
1552
#if defined(HAVE_GETPWUID_R) && \
1553
  defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
1554
struct passwd;
1555
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
1556
               size_t buflen, struct passwd **result);
1557
#endif
1558
1559
#ifdef UNITTESTS
1560
#define UNITTEST
1561
#else
1562
#define UNITTEST static
1563
#endif
1564
1565
#ifdef USE_NGHTTP2
1566
#define USE_HTTP2
1567
#endif
1568
1569
#if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || defined(USE_QUICHE)
1570
1571
#ifdef CURL_WITH_MULTI_SSL
1572
#error "MultiSSL combined with QUIC is not supported"
1573
#endif
1574
1575
#define USE_HTTP3
1576
#endif
1577
1578
/* WebAssembly builds have TCP_NODELAY, but runtime support is missing. */
1579
#ifndef __EMSCRIPTEN__
1580
#define CURL_TCP_NODELAY_SUPPORTED
1581
#endif
1582
1583
/* Certain Windows implementations are not aligned with what curl expects,
1584
   so always use the local one on this platform. E.g. the mingw-w64
1585
   implementation can return wrong results for non-ASCII inputs. */
1586
#if defined(HAVE_BASENAME) && defined(_WIN32)
1587
#undef HAVE_BASENAME
1588
#endif
1589
1590
#if defined(USE_UNIX_SOCKETS) && defined(_WIN32)
1591
/* Offered by mingw-w64 v10+, MS SDK 10.0.16299.0/VS2017 15.4+ */
1592
#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR >= 10)
1593
#  include <afunix.h>
1594
#elif !defined(UNIX_PATH_MAX) /* Replicate logic present in afunix.h */
1595
#  define UNIX_PATH_MAX 108
1596
/* !checksrc! disable TYPEDEFSTRUCT 1 */
1597
typedef struct sockaddr_un {
1598
  CURL_SA_FAMILY_T sun_family;
1599
  char sun_path[UNIX_PATH_MAX];
1600
} SOCKADDR_UN, *PSOCKADDR_UN;
1601
#endif
1602
#endif
1603
1604
#ifdef USE_OPENSSL
1605
/* OpenSSL 3 marks these functions deprecated but we have no replacements (yet)
1606
   so tell the compiler to not warn for them:
1607
   - DES_* (for NTLM)
1608
   - EVP_PKEY_get1_RSA, RSA_flags, RSA_free (auto-skipped for OpenSSL built
1609
     with no-deprecated) */
1610
#  define OPENSSL_SUPPRESS_DEPRECATED
1611
#  ifdef _WIN32
1612
/* Silence LibreSSL warnings about wincrypt.h collision. Works in 3.8.2+ */
1613
#    ifndef LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING
1614
#    define LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING
1615
#    endif
1616
#  endif
1617
#endif
1618
1619
#ifdef CURL_INLINE
1620
/* 'CURL_INLINE' defined, use as-is */
1621
#elif defined(inline)
1622
#  define CURL_INLINE inline /* 'inline' defined, assumed correct */
1623
#elif defined(__cplusplus)
1624
/* The code is compiled with C++ compiler.
1625
   C++ always supports 'inline'. */
1626
#  define CURL_INLINE inline /* 'inline' keyword supported */
1627
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
1628
/* C99 (and later) supports 'inline' keyword */
1629
#  define CURL_INLINE inline /* 'inline' keyword supported */
1630
#elif defined(__GNUC__) && __GNUC__ >= 3
1631
/* GCC supports '__inline__' as an extension */
1632
#  define CURL_INLINE __inline__
1633
#elif defined(_MSC_VER)
1634
#  define CURL_INLINE __inline
1635
#else
1636
/* Probably 'inline' is not supported by compiler.
1637
   Define to the empty string to be on the safe side. */
1638
#  define CURL_INLINE /* empty */
1639
#endif
1640
1641
/* Detect if compiler supports C99 variadic macros */
1642
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
1643
  defined(_MSC_VER)
1644
#define CURL_HAVE_MACRO_VARARG
1645
#endif
1646
1647
#if !defined(CURL_HAVE_MACRO_VARARG) || \
1648
  (defined(CURL_HAVE_MACRO_VARARG) && !defined(CURL_DISABLE_VERBOSE_STRINGS))
1649
#define CURLVERBOSE
1650
281k
#define VERBOSE(x) x
1651
497k
#define NOVERBOSE(x) Curl_nop_stmt
1652
#else
1653
#define VERBOSE(x) Curl_nop_stmt
1654
#define NOVERBOSE(x) x
1655
#endif
1656
1657
/* For FreeBSD it is included from curl/curl.h */
1658
#if defined(__DragonFly__) || defined(__OpenBSD__) || defined(__NetBSD__)
1659
#include <sys/param.h>  /* for __DragonFly_version, OpenBSD,
1660
                           __NetBSD_Version__ */
1661
#endif
1662
1663
/* NetBSD before 6.1 did not set SS_NBIO for SOCK_NONBLOCK. */
1664
#if defined(SOCK_NONBLOCK) && \
1665
  (!defined(__NetBSD__) || (__NetBSD_Version__ >= 601000000))
1666
#define CURL_USE_SOCK_NONBLOCK
1667
#endif
1668
1669
#ifndef _CURL_LOCAL_MEMZERO /* to be removed after a couple of releases */
1670
#ifdef _WIN32
1671
#if defined(_MSC_VER) && defined(NTDDI_VERSION) && \
1672
  (NTDDI_VERSION >= 0x0A000010) /* MS SDK 10.0.26100.0+ */
1673
#pragma comment(lib, "volatileaccessu.lib")
1674
#define curlx_memzero_low(buf, size)  SecureZeroMemory2(buf, size)
1675
#else
1676
#define curlx_memzero_low(buf, size)  SecureZeroMemory(buf, size)
1677
#endif
1678
#elif defined(HAVE_MEMSET_S)
1679
#define curlx_memzero_low(buf, size)  (void)memset_s(buf, size, 0, size)
1680
#elif defined(HAVE_MEMSET_EXPLICIT)
1681
#define curlx_memzero_low(buf, size)  (void)memset_explicit(buf, 0, size)
1682
#elif defined(__CYGWIN__) || \
1683
  (defined(__NEWLIB__) && !defined(__CLIB2__)) || \
1684
  (defined(__GLIBC__) && \
1685
    (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))) || \
1686
  (defined(__DragonFly__) && __DragonFly_version >= 500600 /* 5.6+ */) || \
1687
  (defined(__FreeBSD__) && __FreeBSD_version >= 1100037 /* 11.0+ */) || \
1688
  (defined(__OpenBSD__) && OpenBSD >= 201405 /* 5.5+ */)
1689
77.1k
#define curlx_memzero_low(buf, size)  explicit_bzero(buf, size)
1690
#elif defined(__NetBSD__) && __NetBSD_Version__ >= 702000000 /* 7.2+ */
1691
#define curlx_memzero_low(buf, size)  (void)explicit_memset(buf, 0, size)
1692
#endif
1693
#endif /* !_CURL_LOCAL_MEMZERO */
1694
1695
#ifndef curlx_memzero_low
1696
#define USE_CURLX_MEMZERO
1697
void curlx_memzero_low(void *buf, size_t size);
1698
#endif
1699
void curlx_memzero(void *buf, size_t size);
1700
void curlx_strzero(void *buf);
1701
1702
#endif /* HEADER_CURL_SETUP_H */