vauth/cleartext: fix integer overflow check
[platform/upstream/curl.git] / lib / curl_setup.h
1 #ifndef HEADER_CURL_SETUP_H
2 #define HEADER_CURL_SETUP_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2018, 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.haxx.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  ***************************************************************************/
24
25 #if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES)
26 #define CURL_NO_OLDIES
27 #endif
28
29 /*
30  * Define WIN32 when build target is Win32 API
31  */
32
33 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && \
34     !defined(__SYMBIAN32__)
35 #define WIN32
36 #endif
37
38 #ifdef WIN32
39 /*
40  * Don't include unneeded stuff in Windows headers to avoid compiler
41  * warnings and macro clashes.
42  * Make sure to define this macro before including any Windows headers.
43  */
44 #  ifndef WIN32_LEAN_AND_MEAN
45 #    define WIN32_LEAN_AND_MEAN
46 #  endif
47 #endif
48
49 /*
50  * Include configuration script results or hand-crafted
51  * configuration file for platforms which lack config tool.
52  */
53
54 #ifdef HAVE_CONFIG_H
55
56 #include "curl_config.h"
57
58 #else /* HAVE_CONFIG_H */
59
60 #ifdef _WIN32_WCE
61 #  include "config-win32ce.h"
62 #else
63 #  ifdef WIN32
64 #    include "config-win32.h"
65 #  endif
66 #endif
67
68 #if defined(macintosh) && defined(__MRC__)
69 #  include "config-mac.h"
70 #endif
71
72 #ifdef __riscos__
73 #  include "config-riscos.h"
74 #endif
75
76 #ifdef __AMIGA__
77 #  include "config-amigaos.h"
78 #endif
79
80 #ifdef __SYMBIAN32__
81 #  include "config-symbian.h"
82 #endif
83
84 #ifdef __OS400__
85 #  include "config-os400.h"
86 #endif
87
88 #ifdef TPF
89 #  include "config-tpf.h"
90 #endif
91
92 #ifdef __VXWORKS__
93 #  include "config-vxworks.h"
94 #endif
95
96 #endif /* HAVE_CONFIG_H */
97
98 /* ================================================================ */
99 /* Definition of preprocessor macros/symbols which modify compiler  */
100 /* behavior or generated code characteristics must be done here,   */
101 /* as appropriate, before any system header file is included. It is */
102 /* also possible to have them defined in the config file included   */
103 /* before this point. As a result of all this we frown inclusion of */
104 /* system header files in our config files, avoid this at any cost. */
105 /* ================================================================ */
106
107 /*
108  * AIX 4.3 and newer needs _THREAD_SAFE defined to build
109  * proper reentrant code. Others may also need it.
110  */
111
112 #ifdef NEED_THREAD_SAFE
113 #  ifndef _THREAD_SAFE
114 #    define _THREAD_SAFE
115 #  endif
116 #endif
117
118 /*
119  * Tru64 needs _REENTRANT set for a few function prototypes and
120  * things to appear in the system header files. Unixware needs it
121  * to build proper reentrant code. Others may also need it.
122  */
123
124 #ifdef NEED_REENTRANT
125 #  ifndef _REENTRANT
126 #    define _REENTRANT
127 #  endif
128 #endif
129
130 /* Solaris needs this to get a POSIX-conformant getpwuid_r */
131 #if defined(sun) || defined(__sun)
132 #  ifndef _POSIX_PTHREAD_SEMANTICS
133 #    define _POSIX_PTHREAD_SEMANTICS 1
134 #  endif
135 #endif
136
137 /* ================================================================ */
138 /*  If you need to include a system header file for your platform,  */
139 /*  please, do it beyond the point further indicated in this file.  */
140 /* ================================================================ */
141
142 #include <curl/curl.h>
143
144 #define CURL_SIZEOF_CURL_OFF_T SIZEOF_CURL_OFF_T
145
146 /*
147  * Disable other protocols when http is the only one desired.
148  */
149
150 #ifdef HTTP_ONLY
151 #  ifndef CURL_DISABLE_TFTP
152 #    define CURL_DISABLE_TFTP
153 #  endif
154 #  ifndef CURL_DISABLE_FTP
155 #    define CURL_DISABLE_FTP
156 #  endif
157 #  ifndef CURL_DISABLE_LDAP
158 #    define CURL_DISABLE_LDAP
159 #  endif
160 #  ifndef CURL_DISABLE_TELNET
161 #    define CURL_DISABLE_TELNET
162 #  endif
163 #  ifndef CURL_DISABLE_DICT
164 #    define CURL_DISABLE_DICT
165 #  endif
166 #  ifndef CURL_DISABLE_FILE
167 #    define CURL_DISABLE_FILE
168 #  endif
169 #  ifndef CURL_DISABLE_RTSP
170 #    define CURL_DISABLE_RTSP
171 #  endif
172 #  ifndef CURL_DISABLE_POP3
173 #    define CURL_DISABLE_POP3
174 #  endif
175 #  ifndef CURL_DISABLE_IMAP
176 #    define CURL_DISABLE_IMAP
177 #  endif
178 #  ifndef CURL_DISABLE_SMTP
179 #    define CURL_DISABLE_SMTP
180 #  endif
181 #  ifndef CURL_DISABLE_GOPHER
182 #    define CURL_DISABLE_GOPHER
183 #  endif
184 #  ifndef CURL_DISABLE_SMB
185 #    define CURL_DISABLE_SMB
186 #  endif
187 #endif
188
189 /*
190  * When http is disabled rtsp is not supported.
191  */
192
193 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
194 #  define CURL_DISABLE_RTSP
195 #endif
196
197 /* ================================================================ */
198 /* No system header file shall be included in this file before this */
199 /* point. The only allowed ones are those included from curl/system.h */
200 /* ================================================================ */
201
202 /*
203  * OS/400 setup file includes some system headers.
204  */
205
206 #ifdef __OS400__
207 #  include "setup-os400.h"
208 #endif
209
210 /*
211  * VMS setup file includes some system headers.
212  */
213
214 #ifdef __VMS
215 #  include "setup-vms.h"
216 #endif
217
218 /*
219  * Use getaddrinfo to resolve the IPv4 address literal. If the current network
220  * interface doesn’t support IPv4, but supports IPv6, NAT64, and DNS64,
221  * performing this task will result in a synthesized IPv6 address.
222  */
223 #ifdef  __APPLE__
224 #define USE_RESOLVE_ON_IPS 1
225 #endif
226
227 /*
228  * Include header files for windows builds before redefining anything.
229  * Use this preprocessor block only to include or exclude windows.h,
230  * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
231  * to any other further and independent block.  Under Cygwin things work
232  * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
233  * never be included when __CYGWIN__ is defined.  configure script takes
234  * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
235  * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
236  */
237
238 #ifdef HAVE_WINDOWS_H
239 #  if defined(UNICODE) && !defined(_UNICODE)
240 #    define _UNICODE
241 #  endif
242 #  if defined(_UNICODE) && !defined(UNICODE)
243 #    define UNICODE
244 #  endif
245 #  include <windows.h>
246 #  ifdef HAVE_WINSOCK2_H
247 #    include <winsock2.h>
248 #    ifdef HAVE_WS2TCPIP_H
249 #      include <ws2tcpip.h>
250 #    endif
251 #  else
252 #    ifdef HAVE_WINSOCK_H
253 #      include <winsock.h>
254 #    endif
255 #  endif
256 #  include <tchar.h>
257 #  ifdef UNICODE
258      typedef wchar_t *(*curl_wcsdup_callback)(const wchar_t *str);
259 #  endif
260 #endif
261
262 /*
263  * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
264  * define USE_WINSOCK to 1 if we have and use WINSOCK  API, else
265  * undefine USE_WINSOCK.
266  */
267
268 #undef USE_WINSOCK
269
270 #ifdef HAVE_WINSOCK2_H
271 #  define USE_WINSOCK 2
272 #else
273 #  ifdef HAVE_WINSOCK_H
274 #    define USE_WINSOCK 1
275 #  endif
276 #endif
277
278 #ifdef USE_LWIPSOCK
279 #  include <lwip/init.h>
280 #  include <lwip/sockets.h>
281 #  include <lwip/netdb.h>
282 #endif
283
284 #ifdef HAVE_EXTRA_STRICMP_H
285 #  include <extra/stricmp.h>
286 #endif
287
288 #ifdef HAVE_EXTRA_STRDUP_H
289 #  include <extra/strdup.h>
290 #endif
291
292 #ifdef TPF
293 #  include <strings.h>    /* for bzero, strcasecmp, and strncasecmp */
294 #  include <string.h>     /* for strcpy and strlen */
295 #  include <stdlib.h>     /* for rand and srand */
296 #  include <sys/socket.h> /* for select and ioctl*/
297 #  include <netdb.h>      /* for in_addr_t definition */
298 #  include <tpf/sysapi.h> /* for tpf_process_signals */
299    /* change which select is used for libcurl */
300 #  define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
301 #endif
302
303 #ifdef __VXWORKS__
304 #  include <sockLib.h>    /* for generic BSD socket functions */
305 #  include <ioLib.h>      /* for basic I/O interface functions */
306 #endif
307
308 #ifdef __AMIGA__
309 #  ifndef __ixemul__
310 #    include <exec/types.h>
311 #    include <exec/execbase.h>
312 #    include <proto/exec.h>
313 #    include <proto/dos.h>
314 #    define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
315 #  endif
316 #endif
317
318 #include <stdio.h>
319 #ifdef HAVE_ASSERT_H
320 #include <assert.h>
321 #endif
322
323 #ifdef __TANDEM /* for nsr-tandem-nsk systems */
324 #include <floss.h>
325 #endif
326
327 #ifndef STDC_HEADERS /* no standard C headers! */
328 #include <curl/stdcheaders.h>
329 #endif
330
331 #ifdef __POCC__
332 #  include <sys/types.h>
333 #  include <unistd.h>
334 #  define sys_nerr EILSEQ
335 #endif
336
337 /*
338  * Salford-C kludge section (mostly borrowed from wxWidgets).
339  */
340 #ifdef __SALFORDC__
341   #pragma suppress 353             /* Possible nested comments */
342   #pragma suppress 593             /* Define not used */
343   #pragma suppress 61              /* enum has no name */
344   #pragma suppress 106             /* unnamed, unused parameter */
345   #include <clib.h>
346 #endif
347
348 /*
349  * Large file (>2Gb) support using WIN32 functions.
350  */
351
352 #ifdef USE_WIN32_LARGE_FILES
353 #  include <io.h>
354 #  include <sys/types.h>
355 #  include <sys/stat.h>
356 #  undef  lseek
357 #  define lseek(fdes,offset,whence)  _lseeki64(fdes, offset, whence)
358 #  undef  fstat
359 #  define fstat(fdes,stp)            _fstati64(fdes, stp)
360 #  undef  stat
361 #  define stat(fname,stp)            _stati64(fname, stp)
362 #  define struct_stat                struct _stati64
363 #  define LSEEK_ERROR                (__int64)-1
364 #endif
365
366 /*
367  * Small file (<2Gb) support using WIN32 functions.
368  */
369
370 #ifdef USE_WIN32_SMALL_FILES
371 #  include <io.h>
372 #  include <sys/types.h>
373 #  include <sys/stat.h>
374 #  ifndef _WIN32_WCE
375 #    undef  lseek
376 #    define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
377 #    define fstat(fdes,stp)            _fstat(fdes, stp)
378 #    define stat(fname,stp)            _stat(fname, stp)
379 #    define struct_stat                struct _stat
380 #  endif
381 #  define LSEEK_ERROR                (long)-1
382 #endif
383
384 #ifndef struct_stat
385 #  define struct_stat struct stat
386 #endif
387
388 #ifndef LSEEK_ERROR
389 #  define LSEEK_ERROR (off_t)-1
390 #endif
391
392 #ifndef SIZEOF_TIME_T
393 /* assume default size of time_t to be 32 bit */
394 #define SIZEOF_TIME_T 4
395 #endif
396
397 /*
398  * Default sizeof(off_t) in case it hasn't been defined in config file.
399  */
400
401 #ifndef SIZEOF_OFF_T
402 #  if defined(__VMS) && !defined(__VAX)
403 #    if defined(_LARGEFILE)
404 #      define SIZEOF_OFF_T 8
405 #    endif
406 #  elif defined(__OS400__) && defined(__ILEC400__)
407 #    if defined(_LARGE_FILES)
408 #      define SIZEOF_OFF_T 8
409 #    endif
410 #  elif defined(__MVS__) && defined(__IBMC__)
411 #    if defined(_LP64) || defined(_LARGE_FILES)
412 #      define SIZEOF_OFF_T 8
413 #    endif
414 #  elif defined(__370__) && defined(__IBMC__)
415 #    if defined(_LP64) || defined(_LARGE_FILES)
416 #      define SIZEOF_OFF_T 8
417 #    endif
418 #  endif
419 #  ifndef SIZEOF_OFF_T
420 #    define SIZEOF_OFF_T 4
421 #  endif
422 #endif
423
424 #if (SIZEOF_CURL_OFF_T == 4)
425 #  define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
426 #else
427    /* assume CURL_SIZEOF_CURL_OFF_T == 8 */
428 #  define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
429 #endif
430 #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
431
432 #if (SIZEOF_TIME_T == 4)
433 #  ifdef HAVE_TIME_T_UNSIGNED
434 #  define TIME_T_MAX UINT_MAX
435 #  define TIME_T_MIN 0
436 #  else
437 #  define TIME_T_MAX INT_MAX
438 #  define TIME_T_MIN INT_MIN
439 #  endif
440 #else
441 #  ifdef HAVE_TIME_T_UNSIGNED
442 #  define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
443 #  define TIME_T_MIN 0
444 #  else
445 #  define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
446 #  define TIME_T_MIN (-TIME_T_MAX - 1)
447 #  endif
448 #endif
449
450 #ifndef SIZE_T_MAX
451 /* some limits.h headers have this defined, some don't */
452 #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
453 #define SIZE_T_MAX 18446744073709551615U
454 #else
455 #define SIZE_T_MAX 4294967295U
456 #endif
457 #endif
458
459 /*
460  * Arg 2 type for gethostname in case it hasn't been defined in config file.
461  */
462
463 #ifndef GETHOSTNAME_TYPE_ARG2
464 #  ifdef USE_WINSOCK
465 #    define GETHOSTNAME_TYPE_ARG2 int
466 #  else
467 #    define GETHOSTNAME_TYPE_ARG2 size_t
468 #  endif
469 #endif
470
471 /* Below we define some functions. They should
472
473    4. set the SIGALRM signal timeout
474    5. set dir/file naming defines
475    */
476
477 #ifdef WIN32
478
479 #  define DIR_CHAR      "\\"
480 #  define DOT_CHAR      "_"
481
482 #else /* WIN32 */
483
484 #  ifdef MSDOS  /* Watt-32 */
485
486 #    include <sys/ioctl.h>
487 #    define select(n,r,w,x,t) select_s(n,r,w,x,t)
488 #    define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
489 #    include <tcp.h>
490 #    ifdef word
491 #      undef word
492 #    endif
493 #    ifdef byte
494 #      undef byte
495 #    endif
496
497 #  endif /* MSDOS */
498
499 #  ifdef __minix
500      /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
501      extern char *strtok_r(char *s, const char *delim, char **last);
502      extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
503 #  endif
504
505 #  define DIR_CHAR      "/"
506 #  ifndef DOT_CHAR
507 #    define DOT_CHAR      "."
508 #  endif
509
510 #  ifdef MSDOS
511 #    undef DOT_CHAR
512 #    define DOT_CHAR      "_"
513 #  endif
514
515 #  ifndef fileno /* sunos 4 have this as a macro! */
516      int fileno(FILE *stream);
517 #  endif
518
519 #endif /* WIN32 */
520
521 /*
522  * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
523  * defined in ws2tcpip.h as well as to provide IPv6 support.
524  * Does not apply if lwIP is used.
525  */
526
527 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(USE_LWIPSOCK)
528 #  if !defined(HAVE_WS2TCPIP_H) || \
529      ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
530 #    undef HAVE_GETADDRINFO_THREADSAFE
531 #    undef HAVE_FREEADDRINFO
532 #    undef HAVE_GETADDRINFO
533 #    undef HAVE_GETNAMEINFO
534 #    undef ENABLE_IPV6
535 #  endif
536 #endif
537
538 /* ---------------------------------------------------------------- */
539 /*             resolver specialty compile-time defines              */
540 /*         CURLRES_* defines to use in the host*.c sources          */
541 /* ---------------------------------------------------------------- */
542
543 /*
544  * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
545  */
546
547 #if defined(__LCC__) && defined(WIN32)
548 #  undef USE_THREADS_POSIX
549 #  undef USE_THREADS_WIN32
550 #endif
551
552 /*
553  * MSVC threads support requires a multi-threaded runtime library.
554  * _beginthreadex() is not available in single-threaded ones.
555  */
556
557 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
558 #  undef USE_THREADS_POSIX
559 #  undef USE_THREADS_WIN32
560 #endif
561
562 /*
563  * Mutually exclusive CURLRES_* definitions.
564  */
565
566 #ifdef USE_ARES
567 #  define CURLRES_ASYNCH
568 #  define CURLRES_ARES
569 /* now undef the stock libc functions just to avoid them being used */
570 #  undef HAVE_GETADDRINFO
571 #  undef HAVE_FREEADDRINFO
572 #  undef HAVE_GETHOSTBYNAME
573 #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
574 #  define CURLRES_ASYNCH
575 #  define CURLRES_THREADED
576 #else
577 #  define CURLRES_SYNCH
578 #endif
579
580 #ifdef ENABLE_IPV6
581 #  define CURLRES_IPV6
582 #else
583 #  define CURLRES_IPV4
584 #endif
585
586 /* ---------------------------------------------------------------- */
587
588 /*
589  * When using WINSOCK, TELNET protocol requires WINSOCK2 API.
590  */
591
592 #if defined(USE_WINSOCK) && (USE_WINSOCK != 2)
593 #  define CURL_DISABLE_TELNET 1
594 #endif
595
596 /*
597  * msvc 6.0 does not have struct sockaddr_storage and
598  * does not define IPPROTO_ESP in winsock2.h. But both
599  * are available if PSDK is properly installed.
600  */
601
602 #if defined(_MSC_VER) && !defined(__POCC__)
603 #  if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
604 #    undef HAVE_STRUCT_SOCKADDR_STORAGE
605 #  endif
606 #endif
607
608 /*
609  * Intentionally fail to build when using msvc 6.0 without PSDK installed.
610  * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
611  * in lib/config-win32.h although absolutely discouraged and unsupported.
612  */
613
614 #if defined(_MSC_VER) && !defined(__POCC__)
615 #  if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
616 #    if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
617 #      error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
618              "Windows Server 2003 PSDK"
619 #    else
620 #      define CURL_DISABLE_LDAP 1
621 #    endif
622 #  endif
623 #endif
624
625 #ifdef NETWARE
626 int netware_init(void);
627 #ifndef __NOVELL_LIBC__
628 #include <sys/bsdskt.h>
629 #include <sys/timeval.h>
630 #endif
631 #endif
632
633 #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && !defined(USE_WIN32_IDN)
634 /* The lib and header are present */
635 #define USE_LIBIDN2
636 #endif
637
638 #if defined(USE_LIBIDN2) && defined(USE_WIN32_IDN)
639 #error "Both libidn2 and WinIDN are enabled, choose one."
640 #endif
641
642 #define LIBIDN_REQUIRED_VERSION "0.4.1"
643
644 #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_NSS) || \
645     defined(USE_POLARSSL) || defined(USE_AXTLS) || defined(USE_MBEDTLS) || \
646     defined(USE_CYASSL) || defined(USE_SCHANNEL) || \
647     defined(USE_DARWINSSL) || defined(USE_GSKIT)
648 #define USE_SSL    /* SSL support has been enabled */
649 #endif
650
651 /* Single point where USE_SPNEGO definition might be defined */
652 #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
653     (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
654 #define USE_SPNEGO
655 #endif
656
657 /* Single point where USE_KERBEROS5 definition might be defined */
658 #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
659     (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
660 #define USE_KERBEROS5
661 #endif
662
663 /* Single point where USE_NTLM definition might be defined */
664 #if !defined(CURL_DISABLE_NTLM) && !defined(CURL_DISABLE_CRYPTO_AUTH)
665 #if defined(USE_OPENSSL) || defined(USE_WINDOWS_SSPI) || \
666     defined(USE_GNUTLS) || defined(USE_NSS) || defined(USE_DARWINSSL) || \
667     defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
668     defined(USE_MBEDTLS)
669
670 #define USE_NTLM
671
672 #  if defined(USE_MBEDTLS)
673 /* Get definition of MBEDTLS_MD4_C */
674 #  include <mbedtls/md4.h>
675 #  endif
676
677 #endif
678 #endif
679
680 #ifdef CURL_WANTS_CA_BUNDLE_ENV
681 #error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
682 #endif
683
684 /*
685  * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
686  * Parameters should of course normally not be unused, but for example when
687  * we have multiple implementations of the same interface it may happen.
688  */
689
690 #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
691   ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
692 #  define UNUSED_PARAM __attribute__((__unused__))
693 #  define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
694 #else
695 #  define UNUSED_PARAM /*NOTHING*/
696 #  define WARN_UNUSED_RESULT
697 #endif
698
699 /*
700  * Include macros and defines that should only be processed once.
701  */
702
703 #ifndef HEADER_CURL_SETUP_ONCE_H
704 #include "curl_setup_once.h"
705 #endif
706
707 /*
708  * Definition of our NOP statement Object-like macro
709  */
710
711 #ifndef Curl_nop_stmt
712 #  define Curl_nop_stmt do { } WHILE_FALSE
713 #endif
714
715 /*
716  * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
717  */
718
719 #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
720 #  if defined(SOCKET) || \
721      defined(USE_WINSOCK) || \
722      defined(HAVE_WINSOCK_H) || \
723      defined(HAVE_WINSOCK2_H) || \
724      defined(HAVE_WS2TCPIP_H)
725 #    error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
726 #  endif
727 #endif
728
729 /*
730  * Portable symbolic names for Winsock shutdown() mode flags.
731  */
732
733 #ifdef USE_WINSOCK
734 #  define SHUT_RD   0x00
735 #  define SHUT_WR   0x01
736 #  define SHUT_RDWR 0x02
737 #endif
738
739 /* Define S_ISREG if not defined by system headers, f.e. MSVC */
740 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
741 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
742 #endif
743
744 /* Define S_ISDIR if not defined by system headers, f.e. MSVC */
745 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
746 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
747 #endif
748
749 /* In Windows the default file mode is text but an application can override it.
750 Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
751 */
752 #if defined(WIN32) || defined(MSDOS)
753 #define FOPEN_READTEXT "rt"
754 #define FOPEN_WRITETEXT "wt"
755 #define FOPEN_APPENDTEXT "at"
756 #elif defined(__CYGWIN__)
757 /* Cygwin has specific behavior we need to address when WIN32 is not defined.
758 https://cygwin.com/cygwin-ug-net/using-textbinary.html
759 For write we want our output to have line endings of LF and be compatible with
760 other Cygwin utilities. For read we want to handle input that may have line
761 endings either CRLF or LF so 't' is appropriate.
762 */
763 #define FOPEN_READTEXT "rt"
764 #define FOPEN_WRITETEXT "w"
765 #define FOPEN_APPENDTEXT "a"
766 #else
767 #define FOPEN_READTEXT "r"
768 #define FOPEN_WRITETEXT "w"
769 #define FOPEN_APPENDTEXT "a"
770 #endif
771
772 /* WinSock destroys recv() buffer when send() failed.
773  * Enabled automatically for Windows and for Cygwin as Cygwin sockets are
774  * wrappers for WinSock sockets. https://github.com/curl/curl/issues/657
775  * Define DONT_USE_RECV_BEFORE_SEND_WORKAROUND to force disable workaround.
776  */
777 #if !defined(DONT_USE_RECV_BEFORE_SEND_WORKAROUND)
778 #  if defined(WIN32) || defined(__CYGWIN__)
779 #    define USE_RECV_BEFORE_SEND_WORKAROUND
780 #  endif
781 #else  /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
782 #  ifdef USE_RECV_BEFORE_SEND_WORKAROUND
783 #    undef USE_RECV_BEFORE_SEND_WORKAROUND
784 #  endif
785 #endif /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
786
787 /* Detect Windows App environment which has a restricted access
788  * to the Win32 APIs. */
789 # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
790   defined(WINAPI_FAMILY)
791 #  include <winapifamily.h>
792 #  if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) &&  \
793      !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
794 #    define CURL_WINDOWS_APP
795 #  endif
796 # endif
797
798 #endif /* HEADER_CURL_SETUP_H */