headers: surround GCC attribute names with double underscores
[platform/upstream/curl.git] / lib / 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 - 2012, 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 http://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 /*
26  * Define WIN32 when build target is Win32 API
27  */
28
29 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && \
30     !defined(__SYMBIAN32__)
31 #define WIN32
32 #endif
33
34 /*
35  * Include configuration script results or hand-crafted
36  * configuration file for platforms which lack config tool.
37  */
38
39 #ifdef HAVE_CONFIG_H
40
41 #include "curl_config.h"
42
43 #else /* HAVE_CONFIG_H */
44
45 #ifdef _WIN32_WCE
46 #  include "config-win32ce.h"
47 #else
48 #  ifdef WIN32
49 #    include "config-win32.h"
50 #  endif
51 #endif
52
53 #if defined(macintosh) && defined(__MRC__)
54 #  include "config-mac.h"
55 #endif
56
57 #ifdef __riscos__
58 #  include "config-riscos.h"
59 #endif
60
61 #ifdef __AMIGA__
62 #  include "config-amigaos.h"
63 #endif
64
65 #ifdef __SYMBIAN32__
66 #  include "config-symbian.h"
67 #endif
68
69 #ifdef __OS400__
70 #  include "config-os400.h"
71 #endif
72
73 #ifdef TPF
74 #  include "config-tpf.h"
75 #endif
76
77 #ifdef __VXWORKS__
78 #  include "config-vxworks.h"
79 #endif
80
81 #endif /* HAVE_CONFIG_H */
82
83 /* ================================================================ */
84 /* Definition of preprocessor macros/symbols which modify compiler  */
85 /* behavior or generated code characteristics must be done here,   */
86 /* as appropriate, before any system header file is included. It is */
87 /* also possible to have them defined in the config file included   */
88 /* before this point. As a result of all this we frown inclusion of */
89 /* system header files in our config files, avoid this at any cost. */
90 /* ================================================================ */
91
92 /*
93  * AIX 4.3 and newer needs _THREAD_SAFE defined to build
94  * proper reentrant code. Others may also need it.
95  */
96
97 #ifdef NEED_THREAD_SAFE
98 #  ifndef _THREAD_SAFE
99 #    define _THREAD_SAFE
100 #  endif
101 #endif
102
103 /*
104  * Tru64 needs _REENTRANT set for a few function prototypes and
105  * things to appear in the system header files. Unixware needs it
106  * to build proper reentrant code. Others may also need it.
107  */
108
109 #ifdef NEED_REENTRANT
110 #  ifndef _REENTRANT
111 #    define _REENTRANT
112 #  endif
113 #endif
114
115 /* ================================================================ */
116 /*  If you need to include a system header file for your platform,  */
117 /*  please, do it beyond the point further indicated in this file.  */
118 /* ================================================================ */
119
120 /*
121  * libcurl's external interface definitions are also used internally,
122  * and might also include required system header files to define them.
123  */
124
125 #include <curl/curlbuild.h>
126
127 /*
128  * Compile time sanity checks must also be done when building the library.
129  */
130
131 #include <curl/curlrules.h>
132
133 /*
134  * Ensure that no one is using the old SIZEOF_CURL_OFF_T macro
135  */
136
137 #ifdef SIZEOF_CURL_OFF_T
138 #  error "SIZEOF_CURL_OFF_T shall not be defined!"
139    Error Compilation_aborted_SIZEOF_CURL_OFF_T_shall_not_be_defined
140 #endif
141
142 /*
143  * Set up internal curl_off_t formatting string directives for
144  * exclusive use with libcurl's internal *printf functions.
145  */
146
147 #ifdef FORMAT_OFF_T
148 #  error "FORMAT_OFF_T shall not be defined before this point!"
149    Error Compilation_aborted_FORMAT_OFF_T_already_defined
150 #endif
151
152 #ifdef FORMAT_OFF_TU
153 #  error "FORMAT_OFF_TU shall not be defined before this point!"
154    Error Compilation_aborted_FORMAT_OFF_TU_already_defined
155 #endif
156
157 #if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
158 #  define FORMAT_OFF_T  "lld"
159 #  define FORMAT_OFF_TU "llu"
160 #else
161 #  define FORMAT_OFF_T  "ld"
162 #  define FORMAT_OFF_TU "lu"
163 #endif
164
165 /*
166  * Disable other protocols when http is the only one desired.
167  */
168
169 #ifdef HTTP_ONLY
170 #  ifndef CURL_DISABLE_TFTP
171 #    define CURL_DISABLE_TFTP
172 #  endif
173 #  ifndef CURL_DISABLE_FTP
174 #    define CURL_DISABLE_FTP
175 #  endif
176 #  ifndef CURL_DISABLE_LDAP
177 #    define CURL_DISABLE_LDAP
178 #  endif
179 #  ifndef CURL_DISABLE_TELNET
180 #    define CURL_DISABLE_TELNET
181 #  endif
182 #  ifndef CURL_DISABLE_DICT
183 #    define CURL_DISABLE_DICT
184 #  endif
185 #  ifndef CURL_DISABLE_FILE
186 #    define CURL_DISABLE_FILE
187 #  endif
188 #  ifndef CURL_DISABLE_RTSP
189 #    define CURL_DISABLE_RTSP
190 #  endif
191 #endif
192
193 /*
194  * When http is disabled rtsp is not supported.
195  */
196
197 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
198 #  define CURL_DISABLE_RTSP
199 #endif
200
201 /* ================================================================ */
202 /* No system header file shall be included in this file before this */
203 /* point. The only allowed ones are those included from curlbuild.h */
204 /* ================================================================ */
205
206 /*
207  * OS/400 setup file includes some system headers.
208  */
209
210 #ifdef __OS400__
211 #  include "setup-os400.h"
212 #endif
213
214 /*
215  * Include header files for windows builds before redefining anything.
216  * Use this preprocessor block only to include or exclude windows.h,
217  * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
218  * to any other further and independent block.  Under Cygwin things work
219  * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
220  * never be included when __CYGWIN__ is defined.  configure script takes
221  * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
222  * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
223  */
224
225 #ifdef HAVE_WINDOWS_H
226 #  ifndef WIN32_LEAN_AND_MEAN
227 #    define WIN32_LEAN_AND_MEAN
228 #  endif
229 #  include <windows.h>
230 #  ifdef HAVE_WINSOCK2_H
231 #    include <winsock2.h>
232 #    ifdef HAVE_WS2TCPIP_H
233 #       include <ws2tcpip.h>
234 #    endif
235 #  else
236 #    ifdef HAVE_WINSOCK_H
237 #      include <winsock.h>
238 #    endif
239 #  endif
240 #endif
241
242 /*
243  * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
244  * define USE_WINSOCK to 1 if we have and use WINSOCK  API, else
245  * undefine USE_WINSOCK.
246  */
247
248 #undef USE_WINSOCK
249
250 #ifdef HAVE_WINSOCK2_H
251 #  define USE_WINSOCK 2
252 #else
253 #  ifdef HAVE_WINSOCK_H
254 #    define USE_WINSOCK 1
255 #  endif
256 #endif
257
258 #ifdef USE_LWIPSOCK
259 #  include <lwip/init.h>
260 #  include <lwip/sockets.h>
261 #  include <lwip/netdb.h>
262 #endif
263
264 #ifdef HAVE_EXTRA_STRICMP_H
265 #  include <extra/stricmp.h>
266 #endif
267
268 #ifdef HAVE_EXTRA_STRDUP_H
269 #  include <extra/strdup.h>
270 #endif
271
272 #ifdef TPF
273 #  include <strings.h>    /* for bzero, strcasecmp, and strncasecmp */
274 #  include <string.h>     /* for strcpy and strlen */
275 #  include <stdlib.h>     /* for rand and srand */
276 #  include <sys/socket.h> /* for select and ioctl*/
277 #  include <netdb.h>      /* for in_addr_t definition */
278 #  include <tpf/sysapi.h> /* for tpf_process_signals */
279    /* change which select is used for libcurl */
280 #  define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
281 #endif
282
283 #ifdef __VXWORKS__
284 #  include <sockLib.h>    /* for generic BSD socket functions */
285 #  include <ioLib.h>      /* for basic I/O interface functions */
286 #endif
287
288 #ifdef __AMIGA__
289 #  ifndef __ixemul__
290 #    include <exec/types.h>
291 #    include <exec/execbase.h>
292 #    include <proto/exec.h>
293 #    include <proto/dos.h>
294 #    define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
295 #  endif
296 #endif
297
298 #include <stdio.h>
299 #ifdef HAVE_ASSERT_H
300 #include <assert.h>
301 #endif
302
303 #ifdef __TANDEM /* for nsr-tandem-nsk systems */
304 #include <floss.h>
305 #endif
306
307 #ifndef STDC_HEADERS /* no standard C headers! */
308 #include <curl/stdcheaders.h>
309 #endif
310
311 #ifdef __POCC__
312 #  include <sys/types.h>
313 #  include <unistd.h>
314 #  define sys_nerr EILSEQ
315 #endif
316
317 /*
318  * Salford-C kludge section (mostly borrowed from wxWidgets).
319  */
320 #ifdef __SALFORDC__
321   #pragma suppress 353             /* Possible nested comments */
322   #pragma suppress 593             /* Define not used */
323   #pragma suppress 61              /* enum has no name */
324   #pragma suppress 106             /* unnamed, unused parameter */
325   #include <clib.h>
326 #endif
327
328 /*
329  * Large file (>2Gb) support using WIN32 functions.
330  */
331
332 #ifdef USE_WIN32_LARGE_FILES
333 #  include <io.h>
334 #  include <sys/types.h>
335 #  include <sys/stat.h>
336 #  undef  lseek
337 #  define lseek(fdes,offset,whence)  _lseeki64(fdes, offset, whence)
338 #  define fstat(fdes,stp)            _fstati64(fdes, stp)
339 #  define stat(fname,stp)            _stati64(fname, stp)
340 #  define struct_stat                struct _stati64
341 #  define LSEEK_ERROR                (__int64)-1
342 #endif
343
344 /*
345  * Small file (<2Gb) support using WIN32 functions.
346  */
347
348 #ifdef USE_WIN32_SMALL_FILES
349 #  include <io.h>
350 #  include <sys/types.h>
351 #  include <sys/stat.h>
352 #  undef  lseek
353 #  define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
354 #  define fstat(fdes,stp)            _fstat(fdes, stp)
355 #  define stat(fname,stp)            _stat(fname, stp)
356 #  define struct_stat                struct _stat
357 #  define LSEEK_ERROR                (long)-1
358 #endif
359
360 #ifndef struct_stat
361 #  define struct_stat struct stat
362 #endif
363
364 #ifndef LSEEK_ERROR
365 #  define LSEEK_ERROR (off_t)-1
366 #endif
367
368 /*
369  * Default sizeof(off_t) in case it hasn't been defined in config file.
370  */
371
372 #ifndef SIZEOF_OFF_T
373 #  if defined(__VMS) && !defined(__VAX)
374 #    if defined(_LARGEFILE)
375 #      define SIZEOF_OFF_T 8
376 #    endif
377 #  elif defined(__OS400__) && defined(__ILEC400__)
378 #    if defined(_LARGE_FILES)
379 #      define SIZEOF_OFF_T 8
380 #    endif
381 #  elif defined(__MVS__) && defined(__IBMC__)
382 #    if defined(_LP64) || defined(_LARGE_FILES)
383 #      define SIZEOF_OFF_T 8
384 #    endif
385 #  elif defined(__370__) && defined(__IBMC__)
386 #    if defined(_LP64) || defined(_LARGE_FILES)
387 #      define SIZEOF_OFF_T 8
388 #    endif
389 #  endif
390 #  ifndef SIZEOF_OFF_T
391 #    define SIZEOF_OFF_T 4
392 #  endif
393 #endif
394
395 /*
396  * Arg 2 type for gethostname in case it hasn't been defined in config file.
397  */
398
399 #ifndef GETHOSTNAME_TYPE_ARG2
400 #  ifdef USE_WINSOCK
401 #    define GETHOSTNAME_TYPE_ARG2 int
402 #  else
403 #    define GETHOSTNAME_TYPE_ARG2 size_t
404 #  endif
405 #endif
406
407 /* Below we define some functions. They should
408
409    4. set the SIGALRM signal timeout
410    5. set dir/file naming defines
411    */
412
413 #ifdef WIN32
414
415 #  define DIR_CHAR      "\\"
416 #  define DOT_CHAR      "_"
417
418 #else /* WIN32 */
419
420 #  ifdef MSDOS  /* Watt-32 */
421
422 #    include <sys/ioctl.h>
423 #    define select(n,r,w,x,t) select_s(n,r,w,x,t)
424 #    define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
425 #    include <tcp.h>
426 #    ifdef word
427 #      undef word
428 #    endif
429 #    ifdef byte
430 #      undef byte
431 #    endif
432
433 #  endif /* MSDOS */
434
435 #  ifdef __minix
436      /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
437      extern char * strtok_r(char *s, const char *delim, char **last);
438      extern struct tm * gmtime_r(const time_t * const timep, struct tm *tmp);
439 #  endif
440
441 #  define DIR_CHAR      "/"
442 #  ifndef DOT_CHAR
443 #    define DOT_CHAR      "."
444 #  endif
445
446 #  ifdef MSDOS
447 #    undef DOT_CHAR
448 #    define DOT_CHAR      "_"
449 #  endif
450
451 #  ifndef fileno /* sunos 4 have this as a macro! */
452      int fileno( FILE *stream);
453 #  endif
454
455 #endif /* WIN32 */
456
457 /*
458  * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
459  * defined in ws2tcpip.h as well as to provide IPv6 support.
460  */
461
462 #if defined(_MSC_VER) && !defined(__POCC__)
463 #  if !defined(HAVE_WS2TCPIP_H) || \
464      ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
465 #    undef HAVE_GETADDRINFO_THREADSAFE
466 #    undef HAVE_FREEADDRINFO
467 #    undef HAVE_GETADDRINFO
468 #    undef HAVE_GETNAMEINFO
469 #    undef ENABLE_IPV6
470 #  endif
471 #endif
472
473 /* ---------------------------------------------------------------- */
474 /*             resolver specialty compile-time defines              */
475 /*         CURLRES_* defines to use in the host*.c sources          */
476 /* ---------------------------------------------------------------- */
477
478 /*
479  * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
480  */
481
482 #if defined(__LCC__) && defined(WIN32)
483 #  undef USE_THREADS_POSIX
484 #  undef USE_THREADS_WIN32
485 #endif
486
487 /*
488  * MSVC threads support requires a multi-threaded runtime library.
489  * _beginthreadex() is not available in single-threaded ones.
490  */
491
492 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
493 #  undef USE_THREADS_POSIX
494 #  undef USE_THREADS_WIN32
495 #endif
496
497 /*
498  * Mutually exclusive CURLRES_* definitions.
499  */
500
501 #ifdef USE_ARES
502 #  define CURLRES_ASYNCH
503 #  define CURLRES_ARES
504 /* now undef the stock libc functions just to avoid them being used */
505 #  undef HAVE_GETADDRINFO
506 #  undef HAVE_GETHOSTBYNAME
507 #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
508 #  define CURLRES_ASYNCH
509 #  define CURLRES_THREADED
510 #else
511 #  define CURLRES_SYNCH
512 #endif
513
514 #ifdef ENABLE_IPV6
515 #  define CURLRES_IPV6
516 #else
517 #  define CURLRES_IPV4
518 #endif
519
520 /* ---------------------------------------------------------------- */
521
522 /*
523  * When using WINSOCK, TELNET protocol requires WINSOCK2 API.
524  */
525
526 #if defined(USE_WINSOCK) && (USE_WINSOCK != 2)
527 #  define CURL_DISABLE_TELNET 1
528 #endif
529
530 /*
531  * msvc 6.0 does not have struct sockaddr_storage and
532  * does not define IPPROTO_ESP in winsock2.h. But both
533  * are available if PSDK is properly installed.
534  */
535
536 #if defined(_MSC_VER) && !defined(__POCC__)
537 #  if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
538 #    undef HAVE_STRUCT_SOCKADDR_STORAGE
539 #  endif
540 #endif
541
542 /*
543  * Intentionally fail to build when using msvc 6.0 without PSDK installed.
544  * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
545  * in lib/config-win32.h although absolutely discouraged and unsupported.
546  */
547
548 #if defined(_MSC_VER) && !defined(__POCC__)
549 #  if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
550 #    if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
551 #      error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
552              "Windows Server 2003 PSDK"
553 #    else
554 #      define CURL_DISABLE_LDAP 1
555 #    endif
556 #  endif
557 #endif
558
559 #ifdef NETWARE
560 int netware_init(void);
561 #ifndef __NOVELL_LIBC__
562 #include <sys/bsdskt.h>
563 #include <sys/timeval.h>
564 #endif
565 #endif
566
567 #if defined(HAVE_LIBIDN) && defined(HAVE_TLD_H)
568 /* The lib was present and the tld.h header (which is missing in libidn 0.3.X
569    but we only work with libidn 0.4.1 or later) */
570 #define USE_LIBIDN
571 #endif
572
573 #ifndef SIZEOF_TIME_T
574 /* assume default size of time_t to be 32 bit */
575 #define SIZEOF_TIME_T 4
576 #endif
577
578 #define LIBIDN_REQUIRED_VERSION "0.4.1"
579
580 #if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || \
581     defined(USE_QSOSSL) || defined(USE_POLARSSL) || defined(USE_AXTLS) || \
582     defined(USE_CYASSL)
583 #define USE_SSL    /* SSL support has been enabled */
584 #endif
585
586 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
587 #define USE_HTTP_NEGOTIATE
588 #endif
589
590 /* Single point where USE_NTLM definition might be done */
591 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM)
592 #if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI) || \
593    defined(USE_GNUTLS) || defined(USE_NSS)
594 #define USE_NTLM
595 #endif
596 #endif
597
598 /* non-configure builds may define CURL_WANTS_CA_BUNDLE_ENV */
599 #if defined(CURL_WANTS_CA_BUNDLE_ENV) && !defined(CURL_CA_BUNDLE)
600 #define CURL_CA_BUNDLE getenv("CURL_CA_BUNDLE")
601 #endif
602
603 /* Define S_ISREG if not defined by system headers, f.e. MSVC */
604 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
605 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
606 #endif
607
608 /* Provide a mechanism to silence picky compilers, such as gcc 4.6+.
609    Parameters should of course normally not be unused, but for example when we
610    have multiple implementations of the same interface it may happen. */
611 #ifndef __GNUC__
612 #define UNUSED_PARAM /*NOTHING*/
613 #else
614 #define UNUSED_PARAM __attribute__((__unused__))
615 #endif
616
617 /*
618  * Include macros and defines that should only be processed once.
619  */
620
621 #ifndef __SETUP_ONCE_H
622 #include "setup_once.h"
623 #endif
624
625 /*
626  * Definition of our NOP statement Object-like macro
627  */
628
629 #ifndef Curl_nop_stmt
630 #  define Curl_nop_stmt do { } WHILE_FALSE
631 #endif
632
633 /*
634  * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
635  */
636
637 #if defined(__LWIP_OPT_H__)
638 #  if defined(SOCKET) || \
639      defined(USE_WINSOCK) || \
640      defined(HAVE_WINSOCK_H) || \
641      defined(HAVE_WINSOCK2_H) || \
642      defined(HAVE_WS2TCPIP_H)
643 #    error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
644 #  endif
645 #endif
646
647 /*
648  * Portable symbolic names for Winsock shutdown() mode flags.
649  */
650
651 #ifdef USE_WINSOCK
652 #  define SHUT_RD   0x00
653 #  define SHUT_WR   0x01
654 #  define SHUT_RDWR 0x02
655 #endif
656
657 #endif /* HEADER_CURL_SETUP_H */