CurlTests.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #ifdef TIME_WITH_SYS_TIME
  2. /* Time with sys/time test */
  3. #include <sys/types.h>
  4. #include <sys/time.h>
  5. #include <time.h>
  6. int
  7. main ()
  8. {
  9. if ((struct tm *) 0)
  10. return 0;
  11. ;
  12. return 0;
  13. }
  14. #endif
  15. #ifdef HAVE_FCNTL_O_NONBLOCK
  16. /* headers for FCNTL_O_NONBLOCK test */
  17. #include <sys/types.h>
  18. #include <unistd.h>
  19. #include <fcntl.h>
  20. /* */
  21. #if defined(sun) || defined(__sun__) || \
  22. defined(__SUNPRO_C) || defined(__SUNPRO_CC)
  23. # if defined(__SVR4) || defined(__srv4__)
  24. # define PLATFORM_SOLARIS
  25. # else
  26. # define PLATFORM_SUNOS4
  27. # endif
  28. #endif
  29. #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
  30. # define PLATFORM_AIX_V3
  31. #endif
  32. /* */
  33. #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
  34. #error "O_NONBLOCK does not work on this platform"
  35. #endif
  36. int
  37. main ()
  38. {
  39. /* O_NONBLOCK source test */
  40. int flags = 0;
  41. if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
  42. return 1;
  43. return 0;
  44. }
  45. #endif
  46. #ifdef HAVE_GETHOSTBYADDR_R_5
  47. #include <sys/types.h>
  48. #include <netdb.h>
  49. int
  50. main ()
  51. {
  52. char * address;
  53. int length;
  54. int type;
  55. struct hostent h;
  56. struct hostent_data hdata;
  57. int rc;
  58. #ifndef gethostbyaddr_r
  59. (void)gethostbyaddr_r;
  60. #endif
  61. rc = gethostbyaddr_r(address, length, type, &h, &hdata);
  62. ;
  63. return 0;
  64. }
  65. #endif
  66. #ifdef HAVE_GETHOSTBYADDR_R_5_REENTRANT
  67. #define _REENTRANT
  68. #include <sys/types.h>
  69. #include <netdb.h>
  70. int
  71. main ()
  72. {
  73. char * address;
  74. int length;q
  75. int type;
  76. struct hostent h;
  77. struct hostent_data hdata;
  78. int rc;
  79. #ifndef gethostbyaddr_r
  80. (void)gethostbyaddr_r;
  81. #endif
  82. rc = gethostbyaddr_r(address, length, type, &h, &hdata);
  83. ;
  84. return 0;
  85. }
  86. #endif
  87. #ifdef HAVE_GETHOSTBYADDR_R_7
  88. #include <sys/types.h>
  89. #include <netdb.h>
  90. int
  91. main ()
  92. {
  93. char * address;
  94. int length;
  95. int type;
  96. struct hostent h;
  97. char buffer[8192];
  98. int h_errnop;
  99. struct hostent * hp;
  100. #ifndef gethostbyaddr_r
  101. (void)gethostbyaddr_r;
  102. #endif
  103. hp = gethostbyaddr_r(address, length, type, &h,
  104. buffer, 8192, &h_errnop);
  105. ;
  106. return 0;
  107. }
  108. #endif
  109. #ifdef HAVE_GETHOSTBYADDR_R_7_REENTRANT
  110. #define _REENTRANT
  111. #include <sys/types.h>
  112. #include <netdb.h>
  113. int
  114. main ()
  115. {
  116. char * address;
  117. int length;
  118. int type;
  119. struct hostent h;
  120. char buffer[8192];
  121. int h_errnop;
  122. struct hostent * hp;
  123. #ifndef gethostbyaddr_r
  124. (void)gethostbyaddr_r;
  125. #endif
  126. hp = gethostbyaddr_r(address, length, type, &h,
  127. buffer, 8192, &h_errnop);
  128. ;
  129. return 0;
  130. }
  131. #endif
  132. #ifdef HAVE_GETHOSTBYADDR_R_8
  133. #include <sys/types.h>
  134. #include <netdb.h>
  135. int
  136. main ()
  137. {
  138. char * address;
  139. int length;
  140. int type;
  141. struct hostent h;
  142. char buffer[8192];
  143. int h_errnop;
  144. struct hostent * hp;
  145. int rc;
  146. #ifndef gethostbyaddr_r
  147. (void)gethostbyaddr_r;
  148. #endif
  149. rc = gethostbyaddr_r(address, length, type, &h,
  150. buffer, 8192, &hp, &h_errnop);
  151. ;
  152. return 0;
  153. }
  154. #endif
  155. #ifdef HAVE_GETHOSTBYADDR_R_8_REENTRANT
  156. #define _REENTRANT
  157. #include <sys/types.h>
  158. #include <netdb.h>
  159. int
  160. main ()
  161. {
  162. char * address;
  163. int length;
  164. int type;
  165. struct hostent h;
  166. char buffer[8192];
  167. int h_errnop;
  168. struct hostent * hp;
  169. int rc;
  170. #ifndef gethostbyaddr_r
  171. (void)gethostbyaddr_r;
  172. #endif
  173. rc = gethostbyaddr_r(address, length, type, &h,
  174. buffer, 8192, &hp, &h_errnop);
  175. ;
  176. return 0;
  177. }
  178. #endif
  179. #ifdef HAVE_GETHOSTBYNAME_R_3
  180. #include <string.h>
  181. #include <sys/types.h>
  182. #include <netdb.h>
  183. #undef NULL
  184. #define NULL (void *)0
  185. int
  186. main ()
  187. {
  188. struct hostent_data data;
  189. #ifndef gethostbyname_r
  190. (void)gethostbyname_r;
  191. #endif
  192. gethostbyname_r(NULL, NULL, NULL);
  193. ;
  194. return 0;
  195. }
  196. #endif
  197. #ifdef HAVE_GETHOSTBYNAME_R_3_REENTRANT
  198. #define _REENTRANT
  199. #include <string.h>
  200. #include <sys/types.h>
  201. #include <netdb.h>
  202. #undef NULL
  203. #define NULL (void *)0
  204. int
  205. main ()
  206. {
  207. struct hostent_data data;
  208. #ifndef gethostbyname_r
  209. (void)gethostbyname_r;
  210. #endif
  211. gethostbyname_r(NULL, NULL, NULL);
  212. ;
  213. return 0;
  214. }
  215. #endif
  216. #ifdef HAVE_GETHOSTBYNAME_R_5
  217. #include <sys/types.h>
  218. #include <netinet/in.h>
  219. #include <netdb.h>
  220. #undef NULL
  221. #define NULL (void *)0
  222. int
  223. main ()
  224. {
  225. #ifndef gethostbyname_r
  226. (void)gethostbyname_r;
  227. #endif
  228. gethostbyname_r(NULL, NULL, NULL, 0, NULL);
  229. ;
  230. return 0;
  231. }
  232. #endif
  233. #ifdef HAVE_GETHOSTBYNAME_R_5_REENTRANT
  234. #define _REENTRANT
  235. #include <sys/types.h>
  236. #include <netdb.h>
  237. #undef NULL
  238. #define NULL (void *)0
  239. int
  240. main ()
  241. {
  242. #ifndef gethostbyname_r
  243. (void)gethostbyname_r;
  244. #endif
  245. gethostbyname_r(NULL, NULL, NULL, 0, NULL);
  246. ;
  247. return 0;
  248. }
  249. #endif
  250. #ifdef HAVE_GETHOSTBYNAME_R_6
  251. #include <sys/types.h>
  252. #include <netdb.h>
  253. #undef NULL
  254. #define NULL (void *)0
  255. int
  256. main ()
  257. {
  258. #ifndef gethostbyname_r
  259. (void)gethostbyname_r;
  260. #endif
  261. gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
  262. ;
  263. return 0;
  264. }
  265. #endif
  266. #ifdef HAVE_GETHOSTBYNAME_R_6_REENTRANT
  267. #define _REENTRANT
  268. #include <sys/types.h>
  269. #include <netdb.h>
  270. #undef NULL
  271. #define NULL (void *)0
  272. int
  273. main ()
  274. {
  275. #ifndef gethostbyname_r
  276. (void)gethostbyname_r;
  277. #endif
  278. gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
  279. ;
  280. return 0;
  281. }
  282. #endif
  283. #ifdef HAVE_SOCKLEN_T
  284. #ifdef _WIN32
  285. #include <ws2tcpip.h>
  286. #else
  287. #include <sys/types.h>
  288. #include <sys/socket.h>
  289. #endif
  290. int
  291. main ()
  292. {
  293. if ((socklen_t *) 0)
  294. return 0;
  295. if (sizeof (socklen_t))
  296. return 0;
  297. ;
  298. return 0;
  299. }
  300. #endif
  301. #ifdef HAVE_IN_ADDR_T
  302. #include <sys/types.h>
  303. #include <sys/socket.h>
  304. #include <arpa/inet.h>
  305. int
  306. main ()
  307. {
  308. if ((in_addr_t *) 0)
  309. return 0;
  310. if (sizeof (in_addr_t))
  311. return 0;
  312. ;
  313. return 0;
  314. }
  315. #endif
  316. #ifdef HAVE_BOOL_T
  317. #ifdef HAVE_SYS_TYPES_H
  318. #include <sys/types.h>
  319. #endif
  320. #ifdef HAVE_STDBOOL_H
  321. #include <stdbool.h>
  322. #endif
  323. int
  324. main ()
  325. {
  326. if (sizeof (bool *) )
  327. return 0;
  328. ;
  329. return 0;
  330. }
  331. #endif
  332. #ifdef STDC_HEADERS
  333. #include <stdlib.h>
  334. #include <stdarg.h>
  335. #include <string.h>
  336. #include <float.h>
  337. int main() { return 0; }
  338. #endif
  339. #ifdef RETSIGTYPE_TEST
  340. #include <sys/types.h>
  341. #include <signal.h>
  342. #ifdef signal
  343. # undef signal
  344. #endif
  345. #ifdef __cplusplus
  346. extern "C" void (*signal (int, void (*)(int)))(int);
  347. #else
  348. void (*signal ()) ();
  349. #endif
  350. int
  351. main ()
  352. {
  353. return 0;
  354. }
  355. #endif
  356. #ifdef HAVE_INET_NTOA_R_DECL
  357. #include <arpa/inet.h>
  358. typedef void (*func_type)();
  359. int main()
  360. {
  361. #ifndef inet_ntoa_r
  362. func_type func;
  363. func = (func_type)inet_ntoa_r;
  364. #endif
  365. return 0;
  366. }
  367. #endif
  368. #ifdef HAVE_INET_NTOA_R_DECL_REENTRANT
  369. #define _REENTRANT
  370. #include <arpa/inet.h>
  371. typedef void (*func_type)();
  372. int main()
  373. {
  374. #ifndef inet_ntoa_r
  375. func_type func;
  376. func = (func_type)&inet_ntoa_r;
  377. #endif
  378. return 0;
  379. }
  380. #endif
  381. #ifdef HAVE_GETADDRINFO
  382. #include <netdb.h>
  383. #include <sys/types.h>
  384. #include <sys/socket.h>
  385. int main(void) {
  386. struct addrinfo hints, *ai;
  387. int error;
  388. memset(&hints, 0, sizeof(hints));
  389. hints.ai_family = AF_UNSPEC;
  390. hints.ai_socktype = SOCK_STREAM;
  391. #ifndef getaddrinfo
  392. (void)getaddrinfo;
  393. #endif
  394. error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
  395. if (error) {
  396. return 1;
  397. }
  398. return 0;
  399. }
  400. #endif
  401. #ifdef HAVE_FILE_OFFSET_BITS
  402. #ifdef _FILE_OFFSET_BITS
  403. #undef _FILE_OFFSET_BITS
  404. #endif
  405. #define _FILE_OFFSET_BITS 64
  406. #include <sys/types.h>
  407. /* Check that off_t can represent 2**63 - 1 correctly.
  408. We can't simply define LARGE_OFF_T to be 9223372036854775807,
  409. since some C++ compilers masquerading as C compilers
  410. incorrectly reject 9223372036854775807. */
  411. #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
  412. int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
  413. && LARGE_OFF_T % 2147483647 == 1)
  414. ? 1 : -1];
  415. int main () { ; return 0; }
  416. #endif
  417. #ifdef HAVE_IOCTLSOCKET
  418. /* includes start */
  419. #ifdef HAVE_WINDOWS_H
  420. # ifndef WIN32_LEAN_AND_MEAN
  421. # define WIN32_LEAN_AND_MEAN
  422. # endif
  423. # include <windows.h>
  424. # ifdef HAVE_WINSOCK2_H
  425. # include <winsock2.h>
  426. # else
  427. # ifdef HAVE_WINSOCK_H
  428. # include <winsock.h>
  429. # endif
  430. # endif
  431. #endif
  432. int
  433. main ()
  434. {
  435. /* ioctlsocket source code */
  436. int socket;
  437. unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
  438. ;
  439. return 0;
  440. }
  441. #endif
  442. #ifdef HAVE_IOCTLSOCKET_CAMEL
  443. /* includes start */
  444. #ifdef HAVE_WINDOWS_H
  445. # ifndef WIN32_LEAN_AND_MEAN
  446. # define WIN32_LEAN_AND_MEAN
  447. # endif
  448. # include <windows.h>
  449. # ifdef HAVE_WINSOCK2_H
  450. # include <winsock2.h>
  451. # else
  452. # ifdef HAVE_WINSOCK_H
  453. # include <winsock.h>
  454. # endif
  455. # endif
  456. #endif
  457. int
  458. main ()
  459. {
  460. /* IoctlSocket source code */
  461. if(0 != IoctlSocket(0, 0, 0))
  462. return 1;
  463. ;
  464. return 0;
  465. }
  466. #endif
  467. #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  468. /* includes start */
  469. #ifdef HAVE_WINDOWS_H
  470. # ifndef WIN32_LEAN_AND_MEAN
  471. # define WIN32_LEAN_AND_MEAN
  472. # endif
  473. # include <windows.h>
  474. # ifdef HAVE_WINSOCK2_H
  475. # include <winsock2.h>
  476. # else
  477. # ifdef HAVE_WINSOCK_H
  478. # include <winsock.h>
  479. # endif
  480. # endif
  481. #endif
  482. int
  483. main ()
  484. {
  485. /* IoctlSocket source code */
  486. long flags = 0;
  487. if(0 != ioctlsocket(0, FIONBIO, &flags))
  488. return 1;
  489. ;
  490. return 0;
  491. }
  492. #endif
  493. #ifdef HAVE_IOCTLSOCKET_FIONBIO
  494. /* includes start */
  495. #ifdef HAVE_WINDOWS_H
  496. # ifndef WIN32_LEAN_AND_MEAN
  497. # define WIN32_LEAN_AND_MEAN
  498. # endif
  499. # include <windows.h>
  500. # ifdef HAVE_WINSOCK2_H
  501. # include <winsock2.h>
  502. # else
  503. # ifdef HAVE_WINSOCK_H
  504. # include <winsock.h>
  505. # endif
  506. # endif
  507. #endif
  508. int
  509. main ()
  510. {
  511. int flags = 0;
  512. if(0 != ioctlsocket(0, FIONBIO, &flags))
  513. return 1;
  514. ;
  515. return 0;
  516. }
  517. #endif
  518. #ifdef HAVE_IOCTL_FIONBIO
  519. /* headers for FIONBIO test */
  520. /* includes start */
  521. #ifdef HAVE_SYS_TYPES_H
  522. # include <sys/types.h>
  523. #endif
  524. #ifdef HAVE_UNISTD_H
  525. # include <unistd.h>
  526. #endif
  527. #ifdef HAVE_SYS_SOCKET_H
  528. # include <sys/socket.h>
  529. #endif
  530. #ifdef HAVE_SYS_IOCTL_H
  531. # include <sys/ioctl.h>
  532. #endif
  533. #ifdef HAVE_STROPTS_H
  534. # include <stropts.h>
  535. #endif
  536. int
  537. main ()
  538. {
  539. int flags = 0;
  540. if(0 != ioctl(0, FIONBIO, &flags))
  541. return 1;
  542. ;
  543. return 0;
  544. }
  545. #endif
  546. #ifdef HAVE_IOCTL_SIOCGIFADDR
  547. /* headers for FIONBIO test */
  548. /* includes start */
  549. #ifdef HAVE_SYS_TYPES_H
  550. # include <sys/types.h>
  551. #endif
  552. #ifdef HAVE_UNISTD_H
  553. # include <unistd.h>
  554. #endif
  555. #ifdef HAVE_SYS_SOCKET_H
  556. # include <sys/socket.h>
  557. #endif
  558. #ifdef HAVE_SYS_IOCTL_H
  559. # include <sys/ioctl.h>
  560. #endif
  561. #ifdef HAVE_STROPTS_H
  562. # include <stropts.h>
  563. #endif
  564. #include <net/if.h>
  565. int
  566. main ()
  567. {
  568. struct ifreq ifr;
  569. if(0 != ioctl(0, SIOCGIFADDR, &ifr))
  570. return 1;
  571. ;
  572. return 0;
  573. }
  574. #endif
  575. #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
  576. /* includes start */
  577. #ifdef HAVE_WINDOWS_H
  578. # ifndef WIN32_LEAN_AND_MEAN
  579. # define WIN32_LEAN_AND_MEAN
  580. # endif
  581. # include <windows.h>
  582. # ifdef HAVE_WINSOCK2_H
  583. # include <winsock2.h>
  584. # else
  585. # ifdef HAVE_WINSOCK_H
  586. # include <winsock.h>
  587. # endif
  588. # endif
  589. #endif
  590. /* includes start */
  591. #ifdef HAVE_SYS_TYPES_H
  592. # include <sys/types.h>
  593. #endif
  594. #ifdef HAVE_SYS_SOCKET_H
  595. # include <sys/socket.h>
  596. #endif
  597. /* includes end */
  598. int
  599. main ()
  600. {
  601. if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
  602. return 1;
  603. ;
  604. return 0;
  605. }
  606. #endif
  607. #ifdef HAVE_GLIBC_STRERROR_R
  608. #include <string.h>
  609. #include <errno.h>
  610. int
  611. main () {
  612. char buffer[1024]; /* big enough to play with */
  613. char *string =
  614. strerror_r(EACCES, buffer, sizeof(buffer));
  615. /* this should've returned a string */
  616. if(!string || !string[0])
  617. return 99;
  618. return 0;
  619. }
  620. #endif
  621. #ifdef HAVE_POSIX_STRERROR_R
  622. #include <string.h>
  623. #include <errno.h>
  624. int
  625. main () {
  626. char buffer[1024]; /* big enough to play with */
  627. int error =
  628. strerror_r(EACCES, buffer, sizeof(buffer));
  629. /* This should've returned zero, and written an error string in the
  630. buffer.*/
  631. if(!buffer[0] || error)
  632. return 99;
  633. return 0;
  634. }
  635. #endif