PageRenderTime 66ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/deps/c-ares/setup_once.h

http://github.com/zpao/spidernode
C Header | 488 lines | 277 code | 82 blank | 129 comment | 24 complexity | 6d332c4f60d0fc89bc8bf3e7145a995d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, JSON, BSD-2-Clause, BSD-3-Clause
  1. #ifndef __SETUP_ONCE_H
  2. #define __SETUP_ONCE_H
  3. /* Copyright (C) 2004 - 2010 by Daniel Stenberg et al
  4. *
  5. * Permission to use, copy, modify, and distribute this software and its
  6. * documentation for any purpose and without fee is hereby granted, provided
  7. * that the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of M.I.T. not be used in advertising or
  10. * publicity pertaining to distribution of the software without specific,
  11. * written prior permission. M.I.T. makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as is"
  13. * without express or implied warranty.
  14. */
  15. /********************************************************************
  16. * NOTICE *
  17. * ======== *
  18. * *
  19. * Content of header files lib/setup_once.h and ares/setup_once.h *
  20. * must be kept in sync. Modify the other one if you change this. *
  21. * *
  22. ********************************************************************/
  23. /*
  24. * Inclusion of common header files.
  25. */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <stdarg.h>
  30. #include <ctype.h>
  31. #include <errno.h>
  32. #ifdef HAVE_SYS_TYPES_H
  33. #include <sys/types.h>
  34. #endif
  35. #ifdef NEED_MALLOC_H
  36. #include <malloc.h>
  37. #endif
  38. #ifdef NEED_MEMORY_H
  39. #include <memory.h>
  40. #endif
  41. #ifdef HAVE_SYS_STAT_H
  42. #include <sys/stat.h>
  43. #endif
  44. #ifdef HAVE_SYS_TIME_H
  45. #include <sys/time.h>
  46. #ifdef TIME_WITH_SYS_TIME
  47. #include <time.h>
  48. #endif
  49. #else
  50. #ifdef HAVE_TIME_H
  51. #include <time.h>
  52. #endif
  53. #endif
  54. #ifdef WIN32
  55. #include <io.h>
  56. #include <fcntl.h>
  57. #endif
  58. #ifdef HAVE_STDBOOL_H
  59. #include <stdbool.h>
  60. #endif
  61. /*
  62. * Definition of timeval struct for platforms that don't have it.
  63. */
  64. #ifndef HAVE_STRUCT_TIMEVAL
  65. struct timeval {
  66. long tv_sec;
  67. long tv_usec;
  68. };
  69. #endif
  70. /*
  71. * If we have the MSG_NOSIGNAL define, make sure we use
  72. * it as the fourth argument of function send()
  73. */
  74. #ifdef HAVE_MSG_NOSIGNAL
  75. #define SEND_4TH_ARG MSG_NOSIGNAL
  76. #else
  77. #define SEND_4TH_ARG 0
  78. #endif
  79. #if defined(__minix)
  80. /* Minix doesn't support recv on TCP sockets */
  81. #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
  82. (RECV_TYPE_ARG2)(y), \
  83. (RECV_TYPE_ARG3)(z))
  84. #elif defined(HAVE_RECV)
  85. /*
  86. * The definitions for the return type and arguments types
  87. * of functions recv() and send() belong and come from the
  88. * configuration file. Do not define them in any other place.
  89. *
  90. * HAVE_RECV is defined if you have a function named recv()
  91. * which is used to read incoming data from sockets. If your
  92. * function has another name then don't define HAVE_RECV.
  93. *
  94. * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
  95. * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
  96. * be defined.
  97. *
  98. * HAVE_SEND is defined if you have a function named send()
  99. * which is used to write outgoing data on a connected socket.
  100. * If yours has another name then don't define HAVE_SEND.
  101. *
  102. * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
  103. * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
  104. * SEND_TYPE_RETV must also be defined.
  105. */
  106. #if !defined(RECV_TYPE_ARG1) || \
  107. !defined(RECV_TYPE_ARG2) || \
  108. !defined(RECV_TYPE_ARG3) || \
  109. !defined(RECV_TYPE_ARG4) || \
  110. !defined(RECV_TYPE_RETV)
  111. /* */
  112. Error Missing_definition_of_return_and_arguments_types_of_recv
  113. /* */
  114. #else
  115. #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
  116. (RECV_TYPE_ARG2)(y), \
  117. (RECV_TYPE_ARG3)(z), \
  118. (RECV_TYPE_ARG4)(0))
  119. #endif
  120. #else /* HAVE_RECV */
  121. #ifndef sread
  122. /* */
  123. Error Missing_definition_of_macro_sread
  124. /* */
  125. #endif
  126. #endif /* HAVE_RECV */
  127. #if defined(__minix)
  128. /* Minix doesn't support send on TCP sockets */
  129. #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
  130. (SEND_TYPE_ARG2)(y), \
  131. (SEND_TYPE_ARG3)(z))
  132. #elif defined(HAVE_SEND)
  133. #if !defined(SEND_TYPE_ARG1) || \
  134. !defined(SEND_QUAL_ARG2) || \
  135. !defined(SEND_TYPE_ARG2) || \
  136. !defined(SEND_TYPE_ARG3) || \
  137. !defined(SEND_TYPE_ARG4) || \
  138. !defined(SEND_TYPE_RETV)
  139. /* */
  140. Error Missing_definition_of_return_and_arguments_types_of_send
  141. /* */
  142. #else
  143. #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
  144. (SEND_TYPE_ARG2)(y), \
  145. (SEND_TYPE_ARG3)(z), \
  146. (SEND_TYPE_ARG4)(SEND_4TH_ARG))
  147. #endif
  148. #else /* HAVE_SEND */
  149. #ifndef swrite
  150. /* */
  151. Error Missing_definition_of_macro_swrite
  152. /* */
  153. #endif
  154. #endif /* HAVE_SEND */
  155. #if 0
  156. #if defined(HAVE_RECVFROM)
  157. /*
  158. * Currently recvfrom is only used on udp sockets.
  159. */
  160. #if !defined(RECVFROM_TYPE_ARG1) || \
  161. !defined(RECVFROM_TYPE_ARG2) || \
  162. !defined(RECVFROM_TYPE_ARG3) || \
  163. !defined(RECVFROM_TYPE_ARG4) || \
  164. !defined(RECVFROM_TYPE_ARG5) || \
  165. !defined(RECVFROM_TYPE_ARG6) || \
  166. !defined(RECVFROM_TYPE_RETV)
  167. /* */
  168. Error Missing_definition_of_return_and_arguments_types_of_recvfrom
  169. /* */
  170. #else
  171. #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
  172. (RECVFROM_TYPE_ARG2 *)(b), \
  173. (RECVFROM_TYPE_ARG3) (bl), \
  174. (RECVFROM_TYPE_ARG4) (0), \
  175. (RECVFROM_TYPE_ARG5 *)(f), \
  176. (RECVFROM_TYPE_ARG6 *)(fl))
  177. #endif
  178. #else /* HAVE_RECVFROM */
  179. #ifndef sreadfrom
  180. /* */
  181. Error Missing_definition_of_macro_sreadfrom
  182. /* */
  183. #endif
  184. #endif /* HAVE_RECVFROM */
  185. #ifdef RECVFROM_TYPE_ARG6_IS_VOID
  186. # define RECVFROM_ARG6_T int
  187. #else
  188. # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
  189. #endif
  190. #endif /* if 0 */
  191. /*
  192. * Function-like macro definition used to close a socket.
  193. */
  194. #if defined(HAVE_CLOSESOCKET)
  195. # define sclose(x) closesocket((x))
  196. #elif defined(HAVE_CLOSESOCKET_CAMEL)
  197. # define sclose(x) CloseSocket((x))
  198. #else
  199. # define sclose(x) close((x))
  200. #endif
  201. /*
  202. * Uppercase macro versions of ANSI/ISO is*() functions/macros which
  203. * avoid negative number inputs with argument byte codes > 127.
  204. */
  205. #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
  206. #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
  207. #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
  208. #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
  209. #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
  210. #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
  211. #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
  212. #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
  213. #define ISLOWER(x) (islower((int) ((unsigned char)x)))
  214. #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
  215. (((unsigned char)x) == '\t'))
  216. #define TOLOWER(x) (tolower((int) ((unsigned char)x)))
  217. /*
  218. * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
  219. * On non-C99 platforms there's no bool, so define an enum for that.
  220. * On C99 platforms 'false' and 'true' also exist. Enum uses a
  221. * global namespace though, so use bool_false and bool_true.
  222. */
  223. #ifndef HAVE_BOOL_T
  224. typedef enum {
  225. bool_false = 0,
  226. bool_true = 1
  227. } bool;
  228. /*
  229. * Use a define to let 'true' and 'false' use those enums. There
  230. * are currently no use of true and false in libcurl proper, but
  231. * there are some in the examples. This will cater for any later
  232. * code happening to use true and false.
  233. */
  234. # define false bool_false
  235. # define true bool_true
  236. # define HAVE_BOOL_T
  237. #endif
  238. /*
  239. * Redefine TRUE and FALSE too, to catch current use. With this
  240. * change, 'bool found = 1' will give a warning on MIPSPro, but
  241. * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
  242. * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
  243. */
  244. #ifndef TRUE
  245. #define TRUE true
  246. #endif
  247. #ifndef FALSE
  248. #define FALSE false
  249. #endif
  250. /*
  251. * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
  252. */
  253. #ifndef HAVE_SIG_ATOMIC_T
  254. typedef int sig_atomic_t;
  255. #define HAVE_SIG_ATOMIC_T
  256. #endif
  257. /*
  258. * Convenience SIG_ATOMIC_T definition
  259. */
  260. #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
  261. #define SIG_ATOMIC_T static sig_atomic_t
  262. #else
  263. #define SIG_ATOMIC_T static volatile sig_atomic_t
  264. #endif
  265. /*
  266. * Default return type for signal handlers.
  267. */
  268. #ifndef RETSIGTYPE
  269. #define RETSIGTYPE void
  270. #endif
  271. /*
  272. * Macro used to include code only in debug builds.
  273. */
  274. #ifdef DEBUGBUILD
  275. #define DEBUGF(x) x
  276. #else
  277. #define DEBUGF(x) do { } while (0)
  278. #endif
  279. /*
  280. * Macro used to include assertion code only in debug builds.
  281. */
  282. #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
  283. #define DEBUGASSERT(x) assert(x)
  284. #else
  285. #define DEBUGASSERT(x) do { } while (0)
  286. #endif
  287. /*
  288. * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
  289. * (or equivalent) on this platform to hide platform details to code using it.
  290. */
  291. #ifdef USE_WINSOCK
  292. #define SOCKERRNO ((int)WSAGetLastError())
  293. #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
  294. #else
  295. #define SOCKERRNO (errno)
  296. #define SET_SOCKERRNO(x) (errno = (x))
  297. #endif
  298. /*
  299. * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
  300. * (or equivalent) on this platform to hide platform details to code using it.
  301. */
  302. #ifdef WIN32
  303. #define ERRNO ((int)GetLastError())
  304. #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
  305. #else
  306. #define ERRNO (errno)
  307. #define SET_ERRNO(x) (errno = (x))
  308. #endif
  309. /*
  310. * Portable error number symbolic names defined to Winsock error codes.
  311. */
  312. #ifdef USE_WINSOCK
  313. #undef EBADF /* override definition in errno.h */
  314. #define EBADF WSAEBADF
  315. #undef EINTR /* override definition in errno.h */
  316. #define EINTR WSAEINTR
  317. #undef EINVAL /* override definition in errno.h */
  318. #define EINVAL WSAEINVAL
  319. #undef EWOULDBLOCK /* override definition in errno.h */
  320. #define EWOULDBLOCK WSAEWOULDBLOCK
  321. #undef EINPROGRESS /* override definition in errno.h */
  322. #define EINPROGRESS WSAEINPROGRESS
  323. #undef EALREADY /* override definition in errno.h */
  324. #define EALREADY WSAEALREADY
  325. #undef ENOTSOCK /* override definition in errno.h */
  326. #define ENOTSOCK WSAENOTSOCK
  327. #undef EDESTADDRREQ /* override definition in errno.h */
  328. #define EDESTADDRREQ WSAEDESTADDRREQ
  329. #undef EMSGSIZE /* override definition in errno.h */
  330. #define EMSGSIZE WSAEMSGSIZE
  331. #undef EPROTOTYPE /* override definition in errno.h */
  332. #define EPROTOTYPE WSAEPROTOTYPE
  333. #undef ENOPROTOOPT /* override definition in errno.h */
  334. #define ENOPROTOOPT WSAENOPROTOOPT
  335. #undef EPROTONOSUPPORT /* override definition in errno.h */
  336. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  337. #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  338. #undef EOPNOTSUPP /* override definition in errno.h */
  339. #define EOPNOTSUPP WSAEOPNOTSUPP
  340. #define EPFNOSUPPORT WSAEPFNOSUPPORT
  341. #undef EAFNOSUPPORT /* override definition in errno.h */
  342. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  343. #undef EADDRINUSE /* override definition in errno.h */
  344. #define EADDRINUSE WSAEADDRINUSE
  345. #undef EADDRNOTAVAIL /* override definition in errno.h */
  346. #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  347. #undef ENETDOWN /* override definition in errno.h */
  348. #define ENETDOWN WSAENETDOWN
  349. #undef ENETUNREACH /* override definition in errno.h */
  350. #define ENETUNREACH WSAENETUNREACH
  351. #undef ENETRESET /* override definition in errno.h */
  352. #define ENETRESET WSAENETRESET
  353. #undef ECONNABORTED /* override definition in errno.h */
  354. #define ECONNABORTED WSAECONNABORTED
  355. #undef ECONNRESET /* override definition in errno.h */
  356. #define ECONNRESET WSAECONNRESET
  357. #undef ENOBUFS /* override definition in errno.h */
  358. #define ENOBUFS WSAENOBUFS
  359. #undef EISCONN /* override definition in errno.h */
  360. #define EISCONN WSAEISCONN
  361. #undef ENOTCONN /* override definition in errno.h */
  362. #define ENOTCONN WSAENOTCONN
  363. #define ESHUTDOWN WSAESHUTDOWN
  364. #define ETOOMANYREFS WSAETOOMANYREFS
  365. #undef ETIMEDOUT /* override definition in errno.h */
  366. #define ETIMEDOUT WSAETIMEDOUT
  367. #undef ECONNREFUSED /* override definition in errno.h */
  368. #define ECONNREFUSED WSAECONNREFUSED
  369. #undef ELOOP /* override definition in errno.h */
  370. #define ELOOP WSAELOOP
  371. #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
  372. #define ENAMETOOLONG WSAENAMETOOLONG
  373. #endif
  374. #define EHOSTDOWN WSAEHOSTDOWN
  375. #undef EHOSTUNREACH /* override definition in errno.h */
  376. #define EHOSTUNREACH WSAEHOSTUNREACH
  377. #ifndef ENOTEMPTY /* possible previous definition in errno.h */
  378. #define ENOTEMPTY WSAENOTEMPTY
  379. #endif
  380. #define EPROCLIM WSAEPROCLIM
  381. #define EUSERS WSAEUSERS
  382. #define EDQUOT WSAEDQUOT
  383. #define ESTALE WSAESTALE
  384. #define EREMOTE WSAEREMOTE
  385. #endif
  386. /*
  387. * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
  388. */
  389. #if defined(__VMS) && \
  390. defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
  391. #define getpwuid __32_getpwuid
  392. #endif
  393. /*
  394. * Macro argv_item_t hides platform details to code using it.
  395. */
  396. #ifdef __VMS
  397. #define argv_item_t __char_ptr32
  398. #else
  399. #define argv_item_t char *
  400. #endif
  401. /*
  402. * We use this ZERO_NULL to avoid picky compiler warnings,
  403. * when assigning a NULL pointer to a function pointer var.
  404. */
  405. #define ZERO_NULL 0
  406. #endif /* __SETUP_ONCE_H */