• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 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.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  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 
25 #ifdef HAVE_FCNTL_O_NONBLOCK
26 /* headers for FCNTL_O_NONBLOCK test */
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 /* */
31 #if defined(sun) || defined(__sun__) || \
32     defined(__SUNPRO_C) || defined(__SUNPRO_CC)
33 # if defined(__SVR4) || defined(__srv4__)
34 #  define PLATFORM_SOLARIS
35 # else
36 #  define PLATFORM_SUNOS4
37 # endif
38 #endif
39 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
40 # define PLATFORM_AIX_V3
41 #endif
42 /* */
43 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3)
44 #error "O_NONBLOCK does not work on this platform"
45 #endif
46 
main(void)47 int main(void)
48 {
49   /* O_NONBLOCK source test */
50   int flags = 0;
51   if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
52     return 1;
53   return 0;
54 }
55 #endif
56 
57 /* tests for gethostbyname_r */
58 #if defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) || \
59     defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
60     defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
61 #   define _REENTRANT
62     /* no idea whether _REENTRANT is always set, just invent a new flag */
63 #   define TEST_GETHOSTBYFOO_REENTRANT
64 #endif
65 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
66     defined(HAVE_GETHOSTBYNAME_R_5) || \
67     defined(HAVE_GETHOSTBYNAME_R_6) || \
68     defined(TEST_GETHOSTBYFOO_REENTRANT)
69 #include <sys/types.h>
70 #include <netdb.h>
main(void)71 int main(void)
72 {
73   char *address = "example.com";
74   int length = 0;
75   int type = 0;
76   struct hostent h;
77   int rc = 0;
78 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
79     defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
80   struct hostent_data hdata;
81 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
82       defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
83       defined(HAVE_GETHOSTBYNAME_R_6) || \
84       defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
85   char buffer[8192];
86   int h_errnop;
87   struct hostent *hp;
88 #endif
89 
90 #if   defined(HAVE_GETHOSTBYNAME_R_3) || \
91       defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
92   rc = gethostbyname_r(address, &h, &hdata);
93 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
94       defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT)
95   rc = gethostbyname_r(address, &h, buffer, 8192, &h_errnop);
96   (void)hp; /* not used for test */
97 #elif defined(HAVE_GETHOSTBYNAME_R_6) || \
98       defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
99   rc = gethostbyname_r(address, &h, buffer, 8192, &hp, &h_errnop);
100 #endif
101 
102   (void)length;
103   (void)type;
104   (void)rc;
105   return 0;
106 }
107 #endif
108 
109 #ifdef HAVE_IN_ADDR_T
110 #include <sys/types.h>
111 #include <sys/socket.h>
112 #include <arpa/inet.h>
main(void)113 int main(void)
114 {
115   if((in_addr_t *) 0)
116     return 0;
117   if(sizeof(in_addr_t))
118     return 0;
119   ;
120   return 0;
121 }
122 #endif
123 
124 #ifdef HAVE_BOOL_T
125 #ifdef HAVE_SYS_TYPES_H
126 #include <sys/types.h>
127 #endif
128 #ifdef HAVE_STDBOOL_H
129 #include <stdbool.h>
130 #endif
main(void)131 int main(void)
132 {
133   if(sizeof(bool *))
134     return 0;
135   ;
136   return 0;
137 }
138 #endif
139 
140 #ifdef STDC_HEADERS
141 #include <stdlib.h>
142 #include <stdarg.h>
143 #include <string.h>
144 #include <float.h>
main(void)145 int main(void) { return 0; }
146 #endif
147 
148 #ifdef HAVE_FILE_OFFSET_BITS
149 #ifdef _FILE_OFFSET_BITS
150 #undef _FILE_OFFSET_BITS
151 #endif
152 #define _FILE_OFFSET_BITS 64
153 #include <sys/types.h>
154  /* Check that off_t can represent 2**63 - 1 correctly.
155     We can't simply define LARGE_OFF_T to be 9223372036854775807,
156     since some C++ compilers masquerading as C compilers
157     incorrectly reject 9223372036854775807.  */
158 #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
159   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
160                        && LARGE_OFF_T % 2147483647 == 1)
161                       ? 1 : -1];
main(void)162 int main(void) { ; return 0; }
163 #endif
164 
165 #ifdef HAVE_IOCTLSOCKET
166 /* includes start */
167 #ifdef _WIN32
168 #  ifndef WIN32_LEAN_AND_MEAN
169 #    define WIN32_LEAN_AND_MEAN
170 #  endif
171 #  include <winsock2.h>
172 #endif
main(void)173 int main(void)
174 {
175   /* ioctlsocket source code */
176   int socket;
177   unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
178   ;
179   return 0;
180 }
181 
182 #endif
183 
184 #ifdef HAVE_IOCTLSOCKET_CAMEL
185 /* includes start */
186 #ifdef _WIN32
187 #  ifndef WIN32_LEAN_AND_MEAN
188 #    define WIN32_LEAN_AND_MEAN
189 #  endif
190 #  include <winsock2.h>
191 #endif
main(void)192 int main(void)
193 {
194   /* IoctlSocket source code */
195   if(0 != IoctlSocket(0, 0, 0))
196     return 1;
197   ;
198   return 0;
199 }
200 #endif
201 
202 #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
203 /* includes start */
204 #ifdef _WIN32
205 #  ifndef WIN32_LEAN_AND_MEAN
206 #    define WIN32_LEAN_AND_MEAN
207 #  endif
208 #  include <winsock2.h>
209 #endif
main(void)210 int main(void)
211 {
212   /* IoctlSocket source code */
213   long flags = 0;
214   if(0 != IoctlSocket(0, FIONBIO, &flags))
215     return 1;
216   ;
217   return 0;
218 }
219 #endif
220 
221 #ifdef HAVE_IOCTLSOCKET_FIONBIO
222 /* includes start */
223 #ifdef _WIN32
224 #  ifndef WIN32_LEAN_AND_MEAN
225 #    define WIN32_LEAN_AND_MEAN
226 #  endif
227 #  include <winsock2.h>
228 #endif
main(void)229 int main(void)
230 {
231   int flags = 0;
232   if(0 != ioctlsocket(0, FIONBIO, &flags))
233     return 1;
234   ;
235   return 0;
236 }
237 #endif
238 
239 #ifdef HAVE_IOCTL_FIONBIO
240 /* headers for FIONBIO test */
241 /* includes start */
242 #ifdef HAVE_SYS_TYPES_H
243 #  include <sys/types.h>
244 #endif
245 #ifdef HAVE_UNISTD_H
246 #  include <unistd.h>
247 #endif
248 #ifdef HAVE_SYS_SOCKET_H
249 #  include <sys/socket.h>
250 #endif
251 #ifdef HAVE_SYS_IOCTL_H
252 #  include <sys/ioctl.h>
253 #endif
254 #ifdef HAVE_STROPTS_H
255 #  include <stropts.h>
256 #endif
main(void)257 int main(void)
258 {
259   int flags = 0;
260   if(0 != ioctl(0, FIONBIO, &flags))
261     return 1;
262   ;
263   return 0;
264 }
265 #endif
266 
267 #ifdef HAVE_IOCTL_SIOCGIFADDR
268 /* headers for FIONBIO test */
269 /* includes start */
270 #ifdef HAVE_SYS_TYPES_H
271 #  include <sys/types.h>
272 #endif
273 #ifdef HAVE_UNISTD_H
274 #  include <unistd.h>
275 #endif
276 #ifdef HAVE_SYS_SOCKET_H
277 #  include <sys/socket.h>
278 #endif
279 #ifdef HAVE_SYS_IOCTL_H
280 #  include <sys/ioctl.h>
281 #endif
282 #ifdef HAVE_STROPTS_H
283 #  include <stropts.h>
284 #endif
285 #include <net/if.h>
main(void)286 int main(void)
287 {
288   struct ifreq ifr;
289   if(0 != ioctl(0, SIOCGIFADDR, &ifr))
290     return 1;
291   ;
292   return 0;
293 }
294 #endif
295 
296 #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
297 /* includes start */
298 #ifdef _WIN32
299 #  ifndef WIN32_LEAN_AND_MEAN
300 #    define WIN32_LEAN_AND_MEAN
301 #  endif
302 #  include <winsock2.h>
303 #endif
304 /* includes start */
305 #ifdef HAVE_SYS_TYPES_H
306 #  include <sys/types.h>
307 #endif
308 #ifdef HAVE_SYS_SOCKET_H
309 #  include <sys/socket.h>
310 #endif
311 /* includes end */
main(void)312 int main(void)
313 {
314   if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
315     return 1;
316   ;
317   return 0;
318 }
319 #endif
320 
321 #ifdef HAVE_GLIBC_STRERROR_R
322 #include <string.h>
323 #include <errno.h>
324 
check(char c)325 void check(char c) {}
326 
main(void)327 int main(void)
328 {
329   char buffer[1024];
330   /* This will not compile if strerror_r does not return a char* */
331   check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
332   return 0;
333 }
334 #endif
335 
336 #ifdef HAVE_POSIX_STRERROR_R
337 #include <string.h>
338 #include <errno.h>
339 
340 /* float, because a pointer can't be implicitly cast to float */
check(float f)341 void check(float f) {}
342 
main(void)343 int main(void)
344 {
345   char buffer[1024];
346   /* This will not compile if strerror_r does not return an int */
347   check(strerror_r(EACCES, buffer, sizeof(buffer)));
348   return 0;
349 }
350 #endif
351 
352 #ifdef HAVE_FSETXATTR_6
353 #include <sys/xattr.h> /* header from libc, not from libattr */
main(void)354 int main(void)
355 {
356   fsetxattr(0, 0, 0, 0, 0, 0);
357   return 0;
358 }
359 #endif
360 
361 #ifdef HAVE_FSETXATTR_5
362 #include <sys/xattr.h> /* header from libc, not from libattr */
main(void)363 int main(void)
364 {
365   fsetxattr(0, 0, 0, 0, 0);
366   return 0;
367 }
368 #endif
369 
370 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
371 #include <time.h>
main(void)372 int main(void)
373 {
374   struct timespec ts = {0, 0};
375   clock_gettime(CLOCK_MONOTONIC, &ts);
376   return 0;
377 }
378 #endif
379 
380 #ifdef HAVE_BUILTIN_AVAILABLE
main(void)381 int main(void)
382 {
383   if(__builtin_available(macOS 10.12, *)) {}
384   return 0;
385 }
386 #endif
387 
388 #ifdef HAVE_ATOMIC
389 /* includes start */
390 #ifdef HAVE_SYS_TYPES_H
391 #  include <sys/types.h>
392 #endif
393 #ifdef HAVE_UNISTD_H
394 #  include <unistd.h>
395 #endif
396 #ifdef HAVE_STDATOMIC_H
397 #  include <stdatomic.h>
398 #endif
399 /* includes end */
400 
main(void)401 int main(void)
402 {
403   _Atomic int i = 1;
404   i = 0;  /* Force an atomic-write operation. */
405   return i;
406 }
407 #endif
408 
409 #ifdef HAVE_WIN32_WINNT
410 /* includes start */
411 #ifdef _WIN32
412 #  ifndef WIN32_LEAN_AND_MEAN
413 #    define WIN32_LEAN_AND_MEAN
414 #  endif
415 #  ifndef NOGDI
416 #    define NOGDI
417 #  endif
418 #  include <windows.h>
419 #endif
420 /* includes end */
421 
422 #define enquote(x) #x
423 #define expand(x) enquote(x)
424 #pragma message("_WIN32_WINNT=" expand(_WIN32_WINNT))
425 
main(void)426 int main(void)
427 {
428   return 0;
429 }
430 #endif
431