2
0

CurlTests.c 8.4 KB

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