1/***************************************************************************
2 *                                  _   _ ____  _
3 *  Project                     ___| | | |  _ \| |
4 *                             / __| | | | |_) | |
5 *                            | (__| |_| |  _ <| |___
6 *                             \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22#ifdef TIME_WITH_SYS_TIME
23/* Time with sys/time test */
24
25#include <sys/types.h>
26#include <sys/time.h>
27#include <time.h>
28
29int
30main ()
31{
32if ((struct tm *) 0)
33return 0;
34  ;
35  return 0;
36}
37
38#endif
39
40#ifdef HAVE_FCNTL_O_NONBLOCK
41
42/* headers for FCNTL_O_NONBLOCK test */
43#include <sys/types.h>
44#include <unistd.h>
45#include <fcntl.h>
46/* */
47#if defined(sun) || defined(__sun__) || \
48    defined(__SUNPRO_C) || defined(__SUNPRO_CC)
49# if defined(__SVR4) || defined(__srv4__)
50#  define PLATFORM_SOLARIS
51# else
52#  define PLATFORM_SUNOS4
53# endif
54#endif
55#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
56# define PLATFORM_AIX_V3
57#endif
58/* */
59#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
60#error "O_NONBLOCK does not work on this platform"
61#endif
62
63int
64main ()
65{
66      /* O_NONBLOCK source test */
67      int flags = 0;
68      if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
69          return 1;
70      return 0;
71}
72#endif
73
74#ifdef HAVE_GETHOSTBYADDR_R_5
75#include <sys/types.h>
76#include <netdb.h>
77int
78main ()
79{
80
81char * address;
82int length;
83int type;
84struct hostent h;
85struct hostent_data hdata;
86int rc;
87#ifndef gethostbyaddr_r
88  (void)gethostbyaddr_r;
89#endif
90rc = gethostbyaddr_r(address, length, type, &h, &hdata);
91  ;
92  return 0;
93}
94#endif
95#ifdef HAVE_GETHOSTBYADDR_R_5_REENTRANT
96#define _REENTRANT
97#include <sys/types.h>
98#include <netdb.h>
99int
100main ()
101{
102
103char * address;
104int length;q
105int type;
106struct hostent h;
107struct hostent_data hdata;
108int rc;
109#ifndef gethostbyaddr_r
110  (void)gethostbyaddr_r;
111#endif
112rc = gethostbyaddr_r(address, length, type, &h, &hdata);
113  ;
114  return 0;
115}
116#endif
117#ifdef HAVE_GETHOSTBYADDR_R_7
118#include <sys/types.h>
119#include <netdb.h>
120int
121main ()
122{
123
124char * address;
125int length;
126int type;
127struct hostent h;
128char buffer[8192];
129int h_errnop;
130struct hostent * hp;
131
132#ifndef gethostbyaddr_r
133  (void)gethostbyaddr_r;
134#endif
135hp = gethostbyaddr_r(address, length, type, &h,
136                     buffer, 8192, &h_errnop);
137  ;
138  return 0;
139}
140#endif
141#ifdef HAVE_GETHOSTBYADDR_R_7_REENTRANT
142#define _REENTRANT
143#include <sys/types.h>
144#include <netdb.h>
145int
146main ()
147{
148
149char * address;
150int length;
151int type;
152struct hostent h;
153char buffer[8192];
154int h_errnop;
155struct hostent * hp;
156
157#ifndef gethostbyaddr_r
158  (void)gethostbyaddr_r;
159#endif
160hp = gethostbyaddr_r(address, length, type, &h,
161                     buffer, 8192, &h_errnop);
162  ;
163  return 0;
164}
165#endif
166#ifdef HAVE_GETHOSTBYADDR_R_8
167#include <sys/types.h>
168#include <netdb.h>
169int
170main ()
171{
172
173char * address;
174int length;
175int type;
176struct hostent h;
177char buffer[8192];
178int h_errnop;
179struct hostent * hp;
180int rc;
181
182#ifndef gethostbyaddr_r
183  (void)gethostbyaddr_r;
184#endif
185rc = gethostbyaddr_r(address, length, type, &h,
186                     buffer, 8192, &hp, &h_errnop);
187  ;
188  return 0;
189}
190#endif
191#ifdef HAVE_GETHOSTBYADDR_R_8_REENTRANT
192#define _REENTRANT
193#include <sys/types.h>
194#include <netdb.h>
195int
196main ()
197{
198
199char * address;
200int length;
201int type;
202struct hostent h;
203char buffer[8192];
204int h_errnop;
205struct hostent * hp;
206int rc;
207
208#ifndef gethostbyaddr_r
209  (void)gethostbyaddr_r;
210#endif
211rc = gethostbyaddr_r(address, length, type, &h,
212                     buffer, 8192, &hp, &h_errnop);
213  ;
214  return 0;
215}
216#endif
217#ifdef HAVE_GETHOSTBYNAME_R_3
218#include <string.h>
219#include <sys/types.h>
220#include <netdb.h>
221#undef NULL
222#define NULL (void *)0
223
224int
225main ()
226{
227
228struct hostent_data data;
229#ifndef gethostbyname_r
230  (void)gethostbyname_r;
231#endif
232gethostbyname_r(NULL, NULL, NULL);
233  ;
234  return 0;
235}
236#endif
237#ifdef HAVE_GETHOSTBYNAME_R_3_REENTRANT
238#define _REENTRANT
239#include <string.h>
240#include <sys/types.h>
241#include <netdb.h>
242#undef NULL
243#define NULL (void *)0
244
245int
246main ()
247{
248
249struct hostent_data data;
250#ifndef gethostbyname_r
251  (void)gethostbyname_r;
252#endif
253gethostbyname_r(NULL, NULL, NULL);
254  ;
255  return 0;
256}
257#endif
258#ifdef HAVE_GETHOSTBYNAME_R_5
259#include <sys/types.h>
260#include <netinet/in.h>
261#include <netdb.h>
262#undef NULL
263#define NULL (void *)0
264
265int
266main ()
267{
268#ifndef gethostbyname_r
269  (void)gethostbyname_r;
270#endif
271gethostbyname_r(NULL, NULL, NULL, 0, NULL);
272  ;
273  return 0;
274}
275#endif
276#ifdef HAVE_GETHOSTBYNAME_R_5_REENTRANT
277#define _REENTRANT
278#include <sys/types.h>
279#include <netdb.h>
280#undef NULL
281#define NULL (void *)0
282
283int
284main ()
285{
286
287#ifndef gethostbyname_r
288  (void)gethostbyname_r;
289#endif
290gethostbyname_r(NULL, NULL, NULL, 0, NULL);
291  ;
292  return 0;
293}
294#endif
295#ifdef HAVE_GETHOSTBYNAME_R_6
296#include <sys/types.h>
297#include <netdb.h>
298#undef NULL
299#define NULL (void *)0
300
301int
302main ()
303{
304
305#ifndef gethostbyname_r
306  (void)gethostbyname_r;
307#endif
308gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
309  ;
310  return 0;
311}
312#endif
313#ifdef HAVE_GETHOSTBYNAME_R_6_REENTRANT
314#define _REENTRANT
315#include <sys/types.h>
316#include <netdb.h>
317#undef NULL
318#define NULL (void *)0
319
320int
321main ()
322{
323
324#ifndef gethostbyname_r
325  (void)gethostbyname_r;
326#endif
327gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
328  ;
329  return 0;
330}
331#endif
332#ifdef HAVE_SOCKLEN_T
333#ifdef _WIN32
334#include <ws2tcpip.h>
335#else
336#include <sys/types.h>
337#include <sys/socket.h>
338#endif
339int
340main ()
341{
342if ((socklen_t *) 0)
343  return 0;
344if (sizeof (socklen_t))
345  return 0;
346  ;
347  return 0;
348}
349#endif
350#ifdef HAVE_IN_ADDR_T
351#include <sys/types.h>
352#include <sys/socket.h>
353#include <arpa/inet.h>
354
355int
356main ()
357{
358if ((in_addr_t *) 0)
359  return 0;
360if (sizeof (in_addr_t))
361  return 0;
362  ;
363  return 0;
364}
365#endif
366
367#ifdef HAVE_BOOL_T
368#ifdef HAVE_SYS_TYPES_H
369#include <sys/types.h>
370#endif
371#ifdef HAVE_STDBOOL_H
372#include <stdbool.h>
373#endif
374int
375main ()
376{
377if (sizeof (bool *) )
378  return 0;
379  ;
380  return 0;
381}
382#endif
383
384#ifdef STDC_HEADERS
385#include <stdlib.h>
386#include <stdarg.h>
387#include <string.h>
388#include <float.h>
389int main() { return 0; }
390#endif
391#ifdef RETSIGTYPE_TEST
392#include <sys/types.h>
393#include <signal.h>
394#ifdef signal
395# undef signal
396#endif
397#ifdef __cplusplus
398extern "C" void (*signal (int, void (*)(int)))(int);
399#else
400void (*signal ()) ();
401#endif
402
403int
404main ()
405{
406  return 0;
407}
408#endif
409#ifdef HAVE_INET_NTOA_R_DECL
410#include <arpa/inet.h>
411
412typedef void (*func_type)();
413
414int main()
415{
416#ifndef inet_ntoa_r
417  func_type func;
418  func = (func_type)inet_ntoa_r;
419#endif
420  return 0;
421}
422#endif
423#ifdef HAVE_INET_NTOA_R_DECL_REENTRANT
424#define _REENTRANT
425#include <arpa/inet.h>
426
427typedef void (*func_type)();
428
429int main()
430{
431#ifndef inet_ntoa_r
432  func_type func;
433  func = (func_type)&inet_ntoa_r;
434#endif
435  return 0;
436}
437#endif
438#ifdef HAVE_GETADDRINFO
439#include <netdb.h>
440#include <sys/types.h>
441#include <sys/socket.h>
442
443int main(void) {
444    struct addrinfo hints, *ai;
445    int error;
446
447    memset(&hints, 0, sizeof(hints));
448    hints.ai_family = AF_UNSPEC;
449    hints.ai_socktype = SOCK_STREAM;
450#ifndef getaddrinfo
451    (void)getaddrinfo;
452#endif
453    error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
454    if (error) {
455        return 1;
456    }
457    return 0;
458}
459#endif
460#ifdef HAVE_FILE_OFFSET_BITS
461#ifdef _FILE_OFFSET_BITS
462#undef _FILE_OFFSET_BITS
463#endif
464#define _FILE_OFFSET_BITS 64
465#include <sys/types.h>
466 /* Check that off_t can represent 2**63 - 1 correctly.
467    We can't simply define LARGE_OFF_T to be 9223372036854775807,
468    since some C++ compilers masquerading as C compilers
469    incorrectly reject 9223372036854775807.  */
470#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
471  int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
472                       && LARGE_OFF_T % 2147483647 == 1)
473                      ? 1 : -1];
474int main () { ; return 0; }
475#endif
476#ifdef HAVE_IOCTLSOCKET
477/* includes start */
478#ifdef HAVE_WINDOWS_H
479#  ifndef WIN32_LEAN_AND_MEAN
480#    define WIN32_LEAN_AND_MEAN
481#  endif
482#  include <windows.h>
483#  ifdef HAVE_WINSOCK2_H
484#    include <winsock2.h>
485#  else
486#    ifdef HAVE_WINSOCK_H
487#      include <winsock.h>
488#    endif
489#  endif
490#endif
491
492int
493main ()
494{
495
496/* ioctlsocket source code */
497 int socket;
498 unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
499
500  ;
501  return 0;
502}
503
504#endif
505#ifdef HAVE_IOCTLSOCKET_CAMEL
506/* includes start */
507#ifdef HAVE_WINDOWS_H
508#  ifndef WIN32_LEAN_AND_MEAN
509#    define WIN32_LEAN_AND_MEAN
510#  endif
511#  include <windows.h>
512#  ifdef HAVE_WINSOCK2_H
513#    include <winsock2.h>
514#  else
515#    ifdef HAVE_WINSOCK_H
516#      include <winsock.h>
517#    endif
518#  endif
519#endif
520
521int
522main ()
523{
524
525/* IoctlSocket source code */
526    if(0 != IoctlSocket(0, 0, 0))
527      return 1;
528  ;
529  return 0;
530}
531#endif
532#ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
533/* includes start */
534#ifdef HAVE_WINDOWS_H
535#  ifndef WIN32_LEAN_AND_MEAN
536#    define WIN32_LEAN_AND_MEAN
537#  endif
538#  include <windows.h>
539#  ifdef HAVE_WINSOCK2_H
540#    include <winsock2.h>
541#  else
542#    ifdef HAVE_WINSOCK_H
543#      include <winsock.h>
544#    endif
545#  endif
546#endif
547
548int
549main ()
550{
551
552/* IoctlSocket source code */
553        long flags = 0;
554        if(0 != ioctlsocket(0, FIONBIO, &flags))
555          return 1;
556  ;
557  return 0;
558}
559#endif
560#ifdef HAVE_IOCTLSOCKET_FIONBIO
561/* includes start */
562#ifdef HAVE_WINDOWS_H
563#  ifndef WIN32_LEAN_AND_MEAN
564#    define WIN32_LEAN_AND_MEAN
565#  endif
566#  include <windows.h>
567#  ifdef HAVE_WINSOCK2_H
568#    include <winsock2.h>
569#  else
570#    ifdef HAVE_WINSOCK_H
571#      include <winsock.h>
572#    endif
573#  endif
574#endif
575
576int
577main ()
578{
579
580        int flags = 0;
581        if(0 != ioctlsocket(0, FIONBIO, &flags))
582          return 1;
583
584  ;
585  return 0;
586}
587#endif
588#ifdef HAVE_IOCTL_FIONBIO
589/* headers for FIONBIO test */
590/* includes start */
591#ifdef HAVE_SYS_TYPES_H
592#  include <sys/types.h>
593#endif
594#ifdef HAVE_UNISTD_H
595#  include <unistd.h>
596#endif
597#ifdef HAVE_SYS_SOCKET_H
598#  include <sys/socket.h>
599#endif
600#ifdef HAVE_SYS_IOCTL_H
601#  include <sys/ioctl.h>
602#endif
603#ifdef HAVE_STROPTS_H
604#  include <stropts.h>
605#endif
606
607int
608main ()
609{
610
611        int flags = 0;
612        if(0 != ioctl(0, FIONBIO, &flags))
613          return 1;
614
615  ;
616  return 0;
617}
618#endif
619#ifdef HAVE_IOCTL_SIOCGIFADDR
620/* headers for FIONBIO test */
621/* includes start */
622#ifdef HAVE_SYS_TYPES_H
623#  include <sys/types.h>
624#endif
625#ifdef HAVE_UNISTD_H
626#  include <unistd.h>
627#endif
628#ifdef HAVE_SYS_SOCKET_H
629#  include <sys/socket.h>
630#endif
631#ifdef HAVE_SYS_IOCTL_H
632#  include <sys/ioctl.h>
633#endif
634#ifdef HAVE_STROPTS_H
635#  include <stropts.h>
636#endif
637#include <net/if.h>
638
639int
640main ()
641{
642        struct ifreq ifr;
643        if(0 != ioctl(0, SIOCGIFADDR, &ifr))
644          return 1;
645
646  ;
647  return 0;
648}
649#endif
650#ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
651/* includes start */
652#ifdef HAVE_WINDOWS_H
653#  ifndef WIN32_LEAN_AND_MEAN
654#    define WIN32_LEAN_AND_MEAN
655#  endif
656#  include <windows.h>
657#  ifdef HAVE_WINSOCK2_H
658#    include <winsock2.h>
659#  else
660#    ifdef HAVE_WINSOCK_H
661#      include <winsock.h>
662#    endif
663#  endif
664#endif
665/* includes start */
666#ifdef HAVE_SYS_TYPES_H
667#  include <sys/types.h>
668#endif
669#ifdef HAVE_SYS_SOCKET_H
670#  include <sys/socket.h>
671#endif
672/* includes end */
673
674int
675main ()
676{
677        if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
678          return 1;
679  ;
680  return 0;
681}
682#endif
683#ifdef HAVE_GLIBC_STRERROR_R
684#include <string.h>
685#include <errno.h>
686int
687main () {
688  char buffer[1024]; /* big enough to play with */
689  char *string =
690    strerror_r(EACCES, buffer, sizeof(buffer));
691    /* this should've returned a string */
692    if(!string || !string[0])
693      return 99;
694    return 0;
695}
696#endif
697#ifdef HAVE_POSIX_STRERROR_R
698#include <string.h>
699#include <errno.h>
700int
701main () {
702  char buffer[1024]; /* big enough to play with */
703  int error =
704    strerror_r(EACCES, buffer, sizeof(buffer));
705    /* This should've returned zero, and written an error string in the
706       buffer.*/
707    if(!buffer[0] || error)
708      return 99;
709    return 0;
710}
711#endif
712