2
0

CurlTests.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. #ifdef _WIN32
  173. # include <winsock2.h>
  174. #endif
  175. int main(void)
  176. {
  177. /* IoctlSocket source code */
  178. if(0 != IoctlSocket(0, 0, 0))
  179. return 1;
  180. ;
  181. return 0;
  182. }
  183. #endif
  184. #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  185. /* includes start */
  186. #ifdef _WIN32
  187. # include <winsock2.h>
  188. #endif
  189. int main(void)
  190. {
  191. /* IoctlSocket source code */
  192. long flags = 0;
  193. if(0 != IoctlSocket(0, FIONBIO, &flags))
  194. return 1;
  195. ;
  196. return 0;
  197. }
  198. #endif
  199. #ifdef HAVE_IOCTLSOCKET_FIONBIO
  200. /* includes start */
  201. #ifdef _WIN32
  202. # include <winsock2.h>
  203. #endif
  204. int main(void)
  205. {
  206. unsigned long flags = 0;
  207. if(0 != ioctlsocket(0, FIONBIO, &flags))
  208. return 1;
  209. ;
  210. return 0;
  211. }
  212. #endif
  213. #ifdef HAVE_IOCTL_FIONBIO
  214. /* headers for FIONBIO test */
  215. /* includes start */
  216. #ifdef HAVE_SYS_TYPES_H
  217. # include <sys/types.h>
  218. #endif
  219. #ifdef HAVE_UNISTD_H
  220. # include <unistd.h>
  221. #endif
  222. #ifdef HAVE_SYS_SOCKET_H
  223. # include <sys/socket.h>
  224. #endif
  225. #ifdef HAVE_SYS_IOCTL_H
  226. # include <sys/ioctl.h>
  227. #endif
  228. #ifdef HAVE_STROPTS_H
  229. # include <stropts.h>
  230. #endif
  231. int main(void)
  232. {
  233. int flags = 0;
  234. if(0 != ioctl(0, FIONBIO, &flags))
  235. return 1;
  236. ;
  237. return 0;
  238. }
  239. #endif
  240. #ifdef HAVE_IOCTL_SIOCGIFADDR
  241. /* headers for FIONBIO test */
  242. /* includes start */
  243. #ifdef HAVE_SYS_TYPES_H
  244. # include <sys/types.h>
  245. #endif
  246. #ifdef HAVE_UNISTD_H
  247. # include <unistd.h>
  248. #endif
  249. #ifdef HAVE_SYS_SOCKET_H
  250. # include <sys/socket.h>
  251. #endif
  252. #ifdef HAVE_SYS_IOCTL_H
  253. # include <sys/ioctl.h>
  254. #endif
  255. #ifdef HAVE_STROPTS_H
  256. # include <stropts.h>
  257. #endif
  258. #include <net/if.h>
  259. int main(void)
  260. {
  261. struct ifreq ifr;
  262. if(0 != ioctl(0, SIOCGIFADDR, &ifr))
  263. return 1;
  264. ;
  265. return 0;
  266. }
  267. #endif
  268. #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
  269. /* includes start */
  270. #ifdef _WIN32
  271. # include <winsock2.h>
  272. #endif
  273. /* includes start */
  274. #ifdef HAVE_SYS_TYPES_H
  275. # include <sys/types.h>
  276. #endif
  277. #ifdef HAVE_SYS_SOCKET_H
  278. # include <sys/socket.h>
  279. #endif
  280. /* includes end */
  281. int main(void)
  282. {
  283. if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
  284. return 1;
  285. ;
  286. return 0;
  287. }
  288. #endif
  289. #ifdef HAVE_GLIBC_STRERROR_R
  290. #include <string.h>
  291. #include <errno.h>
  292. void check(char c) {}
  293. int main(void)
  294. {
  295. char buffer[1024];
  296. /* This will not compile if strerror_r does not return a char* */
  297. check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
  298. return 0;
  299. }
  300. #endif
  301. #ifdef HAVE_POSIX_STRERROR_R
  302. #include <string.h>
  303. #include <errno.h>
  304. /* Float, because a pointer cannot be implicitly cast to float */
  305. void check(float f) {}
  306. int main(void)
  307. {
  308. char buffer[1024];
  309. /* This will not compile if strerror_r does not return an int */
  310. check(strerror_r(EACCES, buffer, sizeof(buffer)));
  311. return 0;
  312. }
  313. #endif
  314. #ifdef HAVE_FSETXATTR_6
  315. #include <sys/xattr.h> /* header from libc, not from libattr */
  316. int main(void)
  317. {
  318. fsetxattr(0, 0, 0, 0, 0, 0);
  319. return 0;
  320. }
  321. #endif
  322. #ifdef HAVE_FSETXATTR_5
  323. #include <sys/xattr.h> /* header from libc, not from libattr */
  324. int main(void)
  325. {
  326. fsetxattr(0, 0, 0, 0, 0);
  327. return 0;
  328. }
  329. #endif
  330. #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
  331. #include <time.h>
  332. int main(void)
  333. {
  334. struct timespec ts = {0, 0};
  335. clock_gettime(CLOCK_MONOTONIC, &ts);
  336. return 0;
  337. }
  338. #endif
  339. #ifdef HAVE_BUILTIN_AVAILABLE
  340. int main(void)
  341. {
  342. if(__builtin_available(macOS 10.12, iOS 5.0, *)) {}
  343. return 0;
  344. }
  345. #endif
  346. #ifdef HAVE_ATOMIC
  347. /* includes start */
  348. #ifdef HAVE_SYS_TYPES_H
  349. # include <sys/types.h>
  350. #endif
  351. #ifdef HAVE_UNISTD_H
  352. # include <unistd.h>
  353. #endif
  354. #ifdef HAVE_STDATOMIC_H
  355. # include <stdatomic.h>
  356. #endif
  357. /* includes end */
  358. int main(void)
  359. {
  360. _Atomic int i = 1;
  361. i = 0; /* Force an atomic-write operation. */
  362. return i;
  363. }
  364. #endif
  365. #ifdef HAVE_WIN32_WINNT
  366. /* includes start */
  367. #ifdef _WIN32
  368. # ifndef NOGDI
  369. # define NOGDI
  370. # endif
  371. # include <windows.h>
  372. #endif
  373. /* includes end */
  374. #define enquote(x) #x
  375. #define expand(x) enquote(x)
  376. #pragma message("_WIN32_WINNT=" expand(_WIN32_WINNT))
  377. int main(void)
  378. {
  379. return 0;
  380. }
  381. #endif