CurlTests.c (8310B)
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 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) || \ 59 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) || \ 60 defined(HAVE_GETHOSTBYNAME_R_5) || \ 61 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \ 62 defined(HAVE_GETHOSTBYNAME_R_6) || \ 63 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT) 64 #include <sys/types.h> 65 #include <netdb.h> 66 int main(void) 67 { 68 const char *address = "example.com"; 69 struct hostent h; 70 int rc = 0; 71 #if defined(HAVE_GETHOSTBYNAME_R_3) || \ 72 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) 73 struct hostent_data hdata; 74 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \ 75 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \ 76 defined(HAVE_GETHOSTBYNAME_R_6) || \ 77 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT) 78 char buffer[8192]; 79 struct hostent *hp; 80 int h_errnop; 81 #endif 82 83 #if defined(HAVE_GETHOSTBYNAME_R_3) || \ 84 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) 85 rc = gethostbyname_r(address, &h, &hdata); 86 (void)hdata; 87 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \ 88 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) 89 rc = gethostbyname_r(address, &h, buffer, 8192, &h_errnop); 90 (void)hp; /* not used for test */ 91 (void)h_errnop; 92 #elif defined(HAVE_GETHOSTBYNAME_R_6) || \ 93 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT) 94 rc = gethostbyname_r(address, &h, buffer, 8192, &hp, &h_errnop); 95 (void)hp; 96 (void)h_errnop; 97 #endif 98 (void)h; 99 (void)rc; 100 return 0; 101 } 102 #endif 103 104 #ifdef HAVE_BOOL_T 105 #ifdef HAVE_SYS_TYPES_H 106 #include <sys/types.h> 107 #endif 108 #ifdef HAVE_STDBOOL_H 109 #include <stdbool.h> 110 #endif 111 int main(void) 112 { 113 return (int)sizeof(bool *); 114 } 115 #endif 116 117 #ifdef STDC_HEADERS 118 #include <stdlib.h> 119 #include <stdarg.h> 120 #include <string.h> 121 #include <float.h> 122 int main(void) { return 0; } 123 #endif 124 125 #ifdef HAVE_FILE_OFFSET_BITS 126 #include <sys/types.h> 127 /* Check that off_t can represent 2**63 - 1 correctly. 128 We cannot simply define LARGE_OFF_T to be 9223372036854775807, 129 since some C++ compilers masquerading as C compilers 130 incorrectly reject 9223372036854775807. */ 131 #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) 132 static int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && 133 LARGE_OFF_T % 2147483647 == 1) 134 ? 1 : -1]; 135 int main(void) 136 { 137 (void)off_t_is_large; 138 return 0; 139 } 140 #endif 141 142 #ifdef HAVE_IOCTLSOCKET 143 #ifdef _WIN32 144 # include <winsock2.h> 145 #endif 146 int main(void) 147 { 148 /* ioctlsocket source code */ 149 int socket = -1; 150 unsigned long flags = ioctlsocket(socket, FIONBIO, &flags); 151 (void)flags; 152 return 0; 153 } 154 155 #endif 156 157 #ifdef HAVE_IOCTLSOCKET_CAMEL 158 #include <proto/bsdsocket.h> 159 int main(void) 160 { 161 /* IoctlSocket source code */ 162 if(0 != IoctlSocket(0, 0, 0)) 163 return 1; 164 return 0; 165 } 166 #endif 167 168 #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO 169 #include <proto/bsdsocket.h> 170 #ifdef HAVE_SYS_IOCTL_H 171 # include <sys/ioctl.h> 172 #endif 173 int main(void) 174 { 175 /* IoctlSocket source code */ 176 long flags = 0; 177 if(0 != IoctlSocket(0, FIONBIO, &flags)) 178 return 1; 179 (void)flags; 180 return 0; 181 } 182 #endif 183 184 #ifdef HAVE_IOCTLSOCKET_FIONBIO 185 #ifdef _WIN32 186 # include <winsock2.h> 187 #endif 188 int main(void) 189 { 190 unsigned long flags = 0; 191 if(0 != ioctlsocket(0, FIONBIO, &flags)) 192 return 1; 193 (void)flags; 194 return 0; 195 } 196 #endif 197 198 #ifdef HAVE_IOCTL_FIONBIO 199 /* headers for FIONBIO test */ 200 #ifdef HAVE_SYS_TYPES_H 201 # include <sys/types.h> 202 #endif 203 #ifdef HAVE_UNISTD_H 204 # include <unistd.h> 205 #endif 206 #ifndef _WIN32 207 # include <sys/socket.h> 208 #endif 209 #ifdef HAVE_SYS_IOCTL_H 210 # include <sys/ioctl.h> 211 #endif 212 #ifdef HAVE_STROPTS_H 213 # include <stropts.h> 214 #endif 215 int main(void) 216 { 217 int flags = 0; 218 if(0 != ioctl(0, FIONBIO, &flags)) 219 return 1; 220 (void)flags; 221 return 0; 222 } 223 #endif 224 225 #ifdef HAVE_IOCTL_SIOCGIFADDR 226 /* headers for FIONBIO test */ 227 #ifdef HAVE_SYS_TYPES_H 228 # include <sys/types.h> 229 #endif 230 #ifdef HAVE_UNISTD_H 231 # include <unistd.h> 232 #endif 233 #ifndef _WIN32 234 # include <sys/socket.h> 235 #endif 236 #ifdef HAVE_SYS_IOCTL_H 237 # include <sys/ioctl.h> 238 #endif 239 #ifdef HAVE_STROPTS_H 240 # include <stropts.h> 241 #endif 242 #include <net/if.h> 243 int main(void) 244 { 245 struct ifreq ifr; 246 if(0 != ioctl(0, SIOCGIFADDR, &ifr)) 247 return 1; 248 (void)ifr; 249 return 0; 250 } 251 #endif 252 253 #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK 254 #ifdef _WIN32 255 # include <winsock2.h> 256 #endif 257 #ifdef HAVE_SYS_TYPES_H 258 # include <sys/types.h> 259 #endif 260 #ifndef _WIN32 261 # include <sys/socket.h> 262 #endif 263 int main(void) 264 { 265 if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0)) 266 return 1; 267 return 0; 268 } 269 #endif 270 271 #ifdef HAVE_GLIBC_STRERROR_R 272 #include <string.h> 273 #include <errno.h> 274 275 static void check(char c) { (void)c; } 276 277 int main(void) 278 { 279 char buffer[1024]; 280 /* This will not compile if strerror_r does not return a char* */ 281 /* !checksrc! disable ERRNOVAR 1 */ 282 check(strerror_r(EACCES, buffer, sizeof(buffer))[0]); 283 return 0; 284 } 285 #endif 286 287 #ifdef HAVE_POSIX_STRERROR_R 288 #include <string.h> 289 #include <errno.h> 290 291 /* Float, because a pointer cannot be implicitly cast to float */ 292 static void check(float f) { (void)f; } 293 294 int main(void) 295 { 296 char buffer[1024]; 297 /* This will not compile if strerror_r does not return an int */ 298 /* !checksrc! disable ERRNOVAR 1 */ 299 check(strerror_r(EACCES, buffer, sizeof(buffer))); 300 return 0; 301 } 302 #endif 303 304 #ifdef HAVE_FSETXATTR_6 305 #include <sys/xattr.h> /* header from libc, not from libattr */ 306 int main(void) 307 { 308 fsetxattr(0, 0, 0, 0, 0, 0); 309 return 0; 310 } 311 #endif 312 313 #ifdef HAVE_FSETXATTR_5 314 #include <sys/xattr.h> /* header from libc, not from libattr */ 315 int main(void) 316 { 317 fsetxattr(0, "", 0, 0, 0); 318 return 0; 319 } 320 #endif 321 322 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC 323 #include <time.h> 324 int main(void) 325 { 326 struct timespec ts; 327 (void)clock_gettime(CLOCK_MONOTONIC, &ts); 328 (void)ts; 329 return 0; 330 } 331 #endif 332 333 #ifdef HAVE_BUILTIN_AVAILABLE 334 int main(void) 335 { 336 if(__builtin_available(macOS 10.12, iOS 5.0, *)) {} 337 return 0; 338 } 339 #endif 340 341 #ifdef HAVE_ATOMIC 342 #ifdef HAVE_SYS_TYPES_H 343 # include <sys/types.h> 344 #endif 345 #ifdef HAVE_UNISTD_H 346 # include <unistd.h> 347 #endif 348 #ifdef HAVE_STDATOMIC_H 349 # include <stdatomic.h> 350 #endif 351 int main(void) 352 { 353 _Atomic int i = 1; 354 i = 0; /* Force an atomic-write operation. */ 355 return i; 356 } 357 #endif 358 359 #ifdef HAVE_WIN32_WINNT 360 #ifdef _WIN32 361 # ifndef NOGDI 362 # define NOGDI 363 # endif 364 # include <windows.h> 365 #endif 366 367 #define enquote(x) #x 368 #define expand(x) enquote(x) 369 #pragma message("_WIN32_WINNT=" expand(_WIN32_WINNT)) 370 371 int main(void) 372 { 373 return 0; 374 } 375 #endif 376 377 #ifdef MINGW64_VERSION 378 #ifdef __MINGW32__ 379 # include <_mingw.h> 380 #endif 381 382 #define enquote(x) #x 383 #define expand(x) enquote(x) 384 #pragma message("MINGW64_VERSION=" \ 385 expand(__MINGW64_VERSION_MAJOR) "." \ 386 expand(__MINGW64_VERSION_MINOR)) 387 388 int main(void) 389 { 390 return 0; 391 } 392 #endif