blob: bc36c8ef7ddb93e1d6f6edf4b2a01067048517af [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2014, 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 https://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/* tests for gethostbyaddr_r or gethostbyname_r */
75#if defined(HAVE_GETHOSTBYADDR_R_5_REENTRANT) || \
76 defined(HAVE_GETHOSTBYADDR_R_7_REENTRANT) || \
77 defined(HAVE_GETHOSTBYADDR_R_8_REENTRANT) || \
78 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) || \
79 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
80 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
81# define _REENTRANT
82 /* no idea whether _REENTRANT is always set, just invent a new flag */
83# define TEST_GETHOSTBYFOO_REENTRANT
84#endif
85#if defined(HAVE_GETHOSTBYADDR_R_5) || \
86 defined(HAVE_GETHOSTBYADDR_R_7) || \
87 defined(HAVE_GETHOSTBYADDR_R_8) || \
88 defined(HAVE_GETHOSTBYNAME_R_3) || \
89 defined(HAVE_GETHOSTBYNAME_R_5) || \
90 defined(HAVE_GETHOSTBYNAME_R_6) || \
91 defined(TEST_GETHOSTBYFOO_REENTRANT)
92#include <sys/types.h>
93#include <netdb.h>
94int main(void)
95{
96 char *address = "example.com";
97 int length = 0;
98 int type = 0;
99 struct hostent h;
100 int rc = 0;
101#if defined(HAVE_GETHOSTBYADDR_R_5) || \
102 defined(HAVE_GETHOSTBYADDR_R_5_REENTRANT) || \
103 \
104 defined(HAVE_GETHOSTBYNAME_R_3) || \
105 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
106 struct hostent_data hdata;
107#elif defined(HAVE_GETHOSTBYADDR_R_7) || \
108 defined(HAVE_GETHOSTBYADDR_R_7_REENTRANT) || \
109 defined(HAVE_GETHOSTBYADDR_R_8) || \
110 defined(HAVE_GETHOSTBYADDR_R_8_REENTRANT) || \
111 \
112 defined(HAVE_GETHOSTBYNAME_R_5) || \
113 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
114 defined(HAVE_GETHOSTBYNAME_R_6) || \
115 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
116 char buffer[8192];
117 int h_errnop;
118 struct hostent *hp;
119#endif
120
121#ifndef gethostbyaddr_r
122 (void)gethostbyaddr_r;
123#endif
124
125#if defined(HAVE_GETHOSTBYADDR_R_5) || \
126 defined(HAVE_GETHOSTBYADDR_R_5_REENTRANT)
127 rc = gethostbyaddr_r(address, length, type, &h, &hdata);
128#elif defined(HAVE_GETHOSTBYADDR_R_7) || \
129 defined(HAVE_GETHOSTBYADDR_R_7_REENTRANT)
130 hp = gethostbyaddr_r(address, length, type, &h, buffer, 8192, &h_errnop);
131 (void)hp;
132#elif defined(HAVE_GETHOSTBYADDR_R_8) || \
133 defined(HAVE_GETHOSTBYADDR_R_8_REENTRANT)
134 rc = gethostbyaddr_r(address, length, type, &h, buffer, 8192, &hp, &h_errnop);
135#endif
136
137#if defined(HAVE_GETHOSTBYNAME_R_3) || \
138 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
139 rc = gethostbyname_r(address, &h, &hdata);
140#elif defined(HAVE_GETHOSTBYNAME_R_5) || \
141 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT)
142 rc = gethostbyname_r(address, &h, buffer, 8192, &h_errnop);
143 (void)hp; /* not used for test */
144#elif defined(HAVE_GETHOSTBYNAME_R_6) || \
145 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
146 rc = gethostbyname_r(address, &h, buffer, 8192, &hp, &h_errnop);
147#endif
148
149 (void)length;
150 (void)type;
151 (void)rc;
152 return 0;
153}
154#endif
155
156#ifdef HAVE_SOCKLEN_T
157#ifdef _WIN32
158#include <ws2tcpip.h>
159#else
160#include <sys/types.h>
161#include <sys/socket.h>
162#endif
163int
164main ()
165{
166if ((socklen_t *) 0)
167 return 0;
168if (sizeof (socklen_t))
169 return 0;
170 ;
171 return 0;
172}
173#endif
174#ifdef HAVE_IN_ADDR_T
175#include <sys/types.h>
176#include <sys/socket.h>
177#include <arpa/inet.h>
178
179int
180main ()
181{
182if ((in_addr_t *) 0)
183 return 0;
184if (sizeof (in_addr_t))
185 return 0;
186 ;
187 return 0;
188}
189#endif
190
191#ifdef HAVE_BOOL_T
192#ifdef HAVE_SYS_TYPES_H
193#include <sys/types.h>
194#endif
195#ifdef HAVE_STDBOOL_H
196#include <stdbool.h>
197#endif
198int
199main ()
200{
201if (sizeof (bool *) )
202 return 0;
203 ;
204 return 0;
205}
206#endif
207
208#ifdef STDC_HEADERS
209#include <stdlib.h>
210#include <stdarg.h>
211#include <string.h>
212#include <float.h>
213int main() { return 0; }
214#endif
215#ifdef RETSIGTYPE_TEST
216#include <sys/types.h>
217#include <signal.h>
218#ifdef signal
219# undef signal
220#endif
221#ifdef __cplusplus
222extern "C" void (*signal (int, void (*)(int)))(int);
223#else
224void (*signal ()) ();
225#endif
226
227int
228main ()
229{
230 return 0;
231}
232#endif
233#ifdef HAVE_INET_NTOA_R_DECL
234#include <arpa/inet.h>
235
236typedef void (*func_type)();
237
238int main()
239{
240#ifndef inet_ntoa_r
241 func_type func;
242 func = (func_type)inet_ntoa_r;
243#endif
244 return 0;
245}
246#endif
247#ifdef HAVE_INET_NTOA_R_DECL_REENTRANT
248#define _REENTRANT
249#include <arpa/inet.h>
250
251typedef void (*func_type)();
252
253int main()
254{
255#ifndef inet_ntoa_r
256 func_type func;
257 func = (func_type)&inet_ntoa_r;
258#endif
259 return 0;
260}
261#endif
262#ifdef HAVE_GETADDRINFO
263#include <netdb.h>
264#include <sys/types.h>
265#include <sys/socket.h>
266
267int main(void) {
268 struct addrinfo hints, *ai;
269 int error;
270
271 memset(&hints, 0, sizeof(hints));
272 hints.ai_family = AF_UNSPEC;
273 hints.ai_socktype = SOCK_STREAM;
274#ifndef getaddrinfo
275 (void)getaddrinfo;
276#endif
277 error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
278 if (error) {
279 return 1;
280 }
281 return 0;
282}
283#endif
284#ifdef HAVE_FILE_OFFSET_BITS
285#ifdef _FILE_OFFSET_BITS
286#undef _FILE_OFFSET_BITS
287#endif
288#define _FILE_OFFSET_BITS 64
289#include <sys/types.h>
290 /* Check that off_t can represent 2**63 - 1 correctly.
291 We can't simply define LARGE_OFF_T to be 9223372036854775807,
292 since some C++ compilers masquerading as C compilers
293 incorrectly reject 9223372036854775807. */
294#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
295 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
296 && LARGE_OFF_T % 2147483647 == 1)
297 ? 1 : -1];
298int main () { ; return 0; }
299#endif
300#ifdef HAVE_IOCTLSOCKET
301/* includes start */
302#ifdef HAVE_WINDOWS_H
303# ifndef WIN32_LEAN_AND_MEAN
304# define WIN32_LEAN_AND_MEAN
305# endif
306# include <windows.h>
307# ifdef HAVE_WINSOCK2_H
308# include <winsock2.h>
309# else
310# ifdef HAVE_WINSOCK_H
311# include <winsock.h>
312# endif
313# endif
314#endif
315
316int
317main ()
318{
319
320/* ioctlsocket source code */
321 int socket;
322 unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
323
324 ;
325 return 0;
326}
327
328#endif
329#ifdef HAVE_IOCTLSOCKET_CAMEL
330/* includes start */
331#ifdef HAVE_WINDOWS_H
332# ifndef WIN32_LEAN_AND_MEAN
333# define WIN32_LEAN_AND_MEAN
334# endif
335# include <windows.h>
336# ifdef HAVE_WINSOCK2_H
337# include <winsock2.h>
338# else
339# ifdef HAVE_WINSOCK_H
340# include <winsock.h>
341# endif
342# endif
343#endif
344
345int
346main ()
347{
348
349/* IoctlSocket source code */
350 if(0 != IoctlSocket(0, 0, 0))
351 return 1;
352 ;
353 return 0;
354}
355#endif
356#ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
357/* includes start */
358#ifdef HAVE_WINDOWS_H
359# ifndef WIN32_LEAN_AND_MEAN
360# define WIN32_LEAN_AND_MEAN
361# endif
362# include <windows.h>
363# ifdef HAVE_WINSOCK2_H
364# include <winsock2.h>
365# else
366# ifdef HAVE_WINSOCK_H
367# include <winsock.h>
368# endif
369# endif
370#endif
371
372int
373main ()
374{
375
376/* IoctlSocket source code */
377 long flags = 0;
378 if(0 != ioctlsocket(0, FIONBIO, &flags))
379 return 1;
380 ;
381 return 0;
382}
383#endif
384#ifdef HAVE_IOCTLSOCKET_FIONBIO
385/* includes start */
386#ifdef HAVE_WINDOWS_H
387# ifndef WIN32_LEAN_AND_MEAN
388# define WIN32_LEAN_AND_MEAN
389# endif
390# include <windows.h>
391# ifdef HAVE_WINSOCK2_H
392# include <winsock2.h>
393# else
394# ifdef HAVE_WINSOCK_H
395# include <winsock.h>
396# endif
397# endif
398#endif
399
400int
401main ()
402{
403
404 int flags = 0;
405 if(0 != ioctlsocket(0, FIONBIO, &flags))
406 return 1;
407
408 ;
409 return 0;
410}
411#endif
412#ifdef HAVE_IOCTL_FIONBIO
413/* headers for FIONBIO test */
414/* includes start */
415#ifdef HAVE_SYS_TYPES_H
416# include <sys/types.h>
417#endif
418#ifdef HAVE_UNISTD_H
419# include <unistd.h>
420#endif
421#ifdef HAVE_SYS_SOCKET_H
422# include <sys/socket.h>
423#endif
424#ifdef HAVE_SYS_IOCTL_H
425# include <sys/ioctl.h>
426#endif
427#ifdef HAVE_STROPTS_H
428# include <stropts.h>
429#endif
430
431int
432main ()
433{
434
435 int flags = 0;
436 if(0 != ioctl(0, FIONBIO, &flags))
437 return 1;
438
439 ;
440 return 0;
441}
442#endif
443#ifdef HAVE_IOCTL_SIOCGIFADDR
444/* headers for FIONBIO test */
445/* includes start */
446#ifdef HAVE_SYS_TYPES_H
447# include <sys/types.h>
448#endif
449#ifdef HAVE_UNISTD_H
450# include <unistd.h>
451#endif
452#ifdef HAVE_SYS_SOCKET_H
453# include <sys/socket.h>
454#endif
455#ifdef HAVE_SYS_IOCTL_H
456# include <sys/ioctl.h>
457#endif
458#ifdef HAVE_STROPTS_H
459# include <stropts.h>
460#endif
461#include <net/if.h>
462
463int
464main ()
465{
466 struct ifreq ifr;
467 if(0 != ioctl(0, SIOCGIFADDR, &ifr))
468 return 1;
469
470 ;
471 return 0;
472}
473#endif
474#ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
475/* includes start */
476#ifdef HAVE_WINDOWS_H
477# ifndef WIN32_LEAN_AND_MEAN
478# define WIN32_LEAN_AND_MEAN
479# endif
480# include <windows.h>
481# ifdef HAVE_WINSOCK2_H
482# include <winsock2.h>
483# else
484# ifdef HAVE_WINSOCK_H
485# include <winsock.h>
486# endif
487# endif
488#endif
489/* includes start */
490#ifdef HAVE_SYS_TYPES_H
491# include <sys/types.h>
492#endif
493#ifdef HAVE_SYS_SOCKET_H
494# include <sys/socket.h>
495#endif
496/* includes end */
497
498int
499main ()
500{
501 if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
502 return 1;
503 ;
504 return 0;
505}
506#endif
507#ifdef HAVE_GLIBC_STRERROR_R
508#include <string.h>
509#include <errno.h>
510int
511main () {
512 char buffer[1024]; /* big enough to play with */
513 char *string =
514 strerror_r(EACCES, buffer, sizeof(buffer));
515 /* this should've returned a string */
516 if(!string || !string[0])
517 return 99;
518 return 0;
519}
520#endif
521#ifdef HAVE_POSIX_STRERROR_R
522#include <string.h>
523#include <errno.h>
524int
525main () {
526 char buffer[1024]; /* big enough to play with */
527 int error =
528 strerror_r(EACCES, buffer, sizeof(buffer));
529 /* This should've returned zero, and written an error string in the
530 buffer.*/
531 if(!buffer[0] || error)
532 return 99;
533 return 0;
534}
535#endif
536#ifdef HAVE_FSETXATTR_6
537#include <sys/xattr.h> /* header from libc, not from libattr */
538int
539main() {
540 fsetxattr(0, 0, 0, 0, 0, 0);
541 return 0;
542}
543#endif
544#ifdef HAVE_FSETXATTR_5
545#include <sys/xattr.h> /* header from libc, not from libattr */
546int
547main() {
548 fsetxattr(0, 0, 0, 0, 0);
549 return 0;
550}
551#endif