setup_once.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. #ifndef __SETUP_ONCE_H
  2. #define __SETUP_ONCE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * $Id$
  24. ***************************************************************************/
  25. /********************************************************************
  26. * NOTICE *
  27. * ======== *
  28. * *
  29. * Content of header files lib/setup_once.h and ares/setup_once.h *
  30. * must be kept in sync. Modify the other one if you change this. *
  31. * *
  32. ********************************************************************/
  33. /*
  34. * Inclusion of common header files.
  35. */
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <stdarg.h>
  40. #include <ctype.h>
  41. #include <errno.h>
  42. #ifdef HAVE_SYS_TYPES_H
  43. #include <sys/types.h>
  44. #endif
  45. #ifdef NEED_MALLOC_H
  46. #include <malloc.h>
  47. #endif
  48. #ifdef NEED_MEMORY_H
  49. #include <memory.h>
  50. #endif
  51. #ifdef HAVE_SYS_STAT_H
  52. #include <sys/stat.h>
  53. #endif
  54. #ifdef HAVE_SYS_TIME_H
  55. #include <sys/time.h>
  56. #ifdef TIME_WITH_SYS_TIME
  57. #include <time.h>
  58. #endif
  59. #else
  60. #ifdef HAVE_TIME_H
  61. #include <time.h>
  62. #endif
  63. #endif
  64. #ifdef WIN32
  65. #include <io.h>
  66. #include <fcntl.h>
  67. #endif
  68. #ifdef HAVE_STDBOOL_H
  69. #include <stdbool.h>
  70. #endif
  71. /*
  72. * Definition of timeval struct for platforms that don't have it.
  73. */
  74. #ifndef HAVE_STRUCT_TIMEVAL
  75. struct timeval {
  76. long tv_sec;
  77. long tv_usec;
  78. };
  79. #endif
  80. /*
  81. * If we have the MSG_NOSIGNAL define, make sure we use
  82. * it as the fourth argument of function send()
  83. */
  84. #ifdef HAVE_MSG_NOSIGNAL
  85. #define SEND_4TH_ARG MSG_NOSIGNAL
  86. #else
  87. #define SEND_4TH_ARG 0
  88. #endif
  89. #if defined(__minix)
  90. /* Minix doesn't support recv on TCP sockets */
  91. #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
  92. (RECV_TYPE_ARG2)(y), \
  93. (RECV_TYPE_ARG3)(z))
  94. #elif defined(HAVE_RECV)
  95. /*
  96. * The definitions for the return type and arguments types
  97. * of functions recv() and send() belong and come from the
  98. * configuration file. Do not define them in any other place.
  99. *
  100. * HAVE_RECV is defined if you have a function named recv()
  101. * which is used to read incoming data from sockets. If your
  102. * function has another name then don't define HAVE_RECV.
  103. *
  104. * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
  105. * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
  106. * be defined.
  107. *
  108. * HAVE_SEND is defined if you have a function named send()
  109. * which is used to write outgoing data on a connected socket.
  110. * If yours has another name then don't define HAVE_SEND.
  111. *
  112. * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
  113. * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
  114. * SEND_TYPE_RETV must also be defined.
  115. */
  116. #if !defined(RECV_TYPE_ARG1) || \
  117. !defined(RECV_TYPE_ARG2) || \
  118. !defined(RECV_TYPE_ARG3) || \
  119. !defined(RECV_TYPE_ARG4) || \
  120. !defined(RECV_TYPE_RETV)
  121. /* */
  122. Error Missing_definition_of_return_and_arguments_types_of_recv
  123. /* */
  124. #else
  125. #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
  126. (RECV_TYPE_ARG2)(y), \
  127. (RECV_TYPE_ARG3)(z), \
  128. (RECV_TYPE_ARG4)(0))
  129. #endif
  130. #else /* HAVE_RECV */
  131. #ifndef sread
  132. /* */
  133. Error Missing_definition_of_macro_sread
  134. /* */
  135. #endif
  136. #endif /* HAVE_RECV */
  137. #if defined(__minix)
  138. /* Minix doesn't support send on TCP sockets */
  139. #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
  140. (SEND_TYPE_ARG2)(y), \
  141. (SEND_TYPE_ARG3)(z))
  142. #elif defined(HAVE_SEND)
  143. #if !defined(SEND_TYPE_ARG1) || \
  144. !defined(SEND_QUAL_ARG2) || \
  145. !defined(SEND_TYPE_ARG2) || \
  146. !defined(SEND_TYPE_ARG3) || \
  147. !defined(SEND_TYPE_ARG4) || \
  148. !defined(SEND_TYPE_RETV)
  149. /* */
  150. Error Missing_definition_of_return_and_arguments_types_of_send
  151. /* */
  152. #else
  153. #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
  154. (SEND_TYPE_ARG2)(y), \
  155. (SEND_TYPE_ARG3)(z), \
  156. (SEND_TYPE_ARG4)(SEND_4TH_ARG))
  157. #endif
  158. #else /* HAVE_SEND */
  159. #ifndef swrite
  160. /* */
  161. Error Missing_definition_of_macro_swrite
  162. /* */
  163. #endif
  164. #endif /* HAVE_SEND */
  165. #if 0
  166. #if defined(HAVE_RECVFROM)
  167. /*
  168. * Currently recvfrom is only used on udp sockets.
  169. */
  170. #if !defined(RECVFROM_TYPE_ARG1) || \
  171. !defined(RECVFROM_TYPE_ARG2) || \
  172. !defined(RECVFROM_TYPE_ARG3) || \
  173. !defined(RECVFROM_TYPE_ARG4) || \
  174. !defined(RECVFROM_TYPE_ARG5) || \
  175. !defined(RECVFROM_TYPE_ARG6) || \
  176. !defined(RECVFROM_TYPE_RETV)
  177. /* */
  178. Error Missing_definition_of_return_and_arguments_types_of_recvfrom
  179. /* */
  180. #else
  181. #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
  182. (RECVFROM_TYPE_ARG2 *)(b), \
  183. (RECVFROM_TYPE_ARG3) (bl), \
  184. (RECVFROM_TYPE_ARG4) (0), \
  185. (RECVFROM_TYPE_ARG5 *)(f), \
  186. (RECVFROM_TYPE_ARG6 *)(fl))
  187. #endif
  188. #else /* HAVE_RECVFROM */
  189. #ifndef sreadfrom
  190. /* */
  191. Error Missing_definition_of_macro_sreadfrom
  192. /* */
  193. #endif
  194. #endif /* HAVE_RECVFROM */
  195. #ifdef RECVFROM_TYPE_ARG6_IS_VOID
  196. # define RECVFROM_ARG6_T int
  197. #else
  198. # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
  199. #endif
  200. #endif /* if 0 */
  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. /*
  217. * Typedef to 'unsigned char' if bool is not an available 'typedefed' type.
  218. */
  219. #ifndef HAVE_BOOL_T
  220. typedef unsigned char bool;
  221. #define HAVE_BOOL_T
  222. #endif
  223. /*
  224. * Default definition of uppercase TRUE and FALSE.
  225. */
  226. #ifndef TRUE
  227. #define TRUE 1
  228. #endif
  229. #ifndef FALSE
  230. #define FALSE 0
  231. #endif
  232. /*
  233. * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
  234. */
  235. #ifndef HAVE_SIG_ATOMIC_T
  236. typedef int sig_atomic_t;
  237. #define HAVE_SIG_ATOMIC_T
  238. #endif
  239. /*
  240. * Convenience SIG_ATOMIC_T definition
  241. */
  242. #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
  243. #define SIG_ATOMIC_T static sig_atomic_t
  244. #else
  245. #define SIG_ATOMIC_T static volatile sig_atomic_t
  246. #endif
  247. /*
  248. * Default return type for signal handlers.
  249. */
  250. #ifndef RETSIGTYPE
  251. #define RETSIGTYPE void
  252. #endif
  253. /*
  254. * Macro used to include code only in debug builds.
  255. */
  256. #ifdef CURLDEBUG
  257. #define DEBUGF(x) x
  258. #else
  259. #define DEBUGF(x) do { } while (0)
  260. #endif
  261. /*
  262. * Macro used to include assertion code only in debug builds.
  263. */
  264. #if defined(CURLDEBUG) && defined(HAVE_ASSERT_H)
  265. #define DEBUGASSERT(x) assert(x)
  266. #else
  267. #define DEBUGASSERT(x) do { } while (0)
  268. #endif
  269. /*
  270. * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
  271. * (or equivalent) on this platform to hide platform details to code using it.
  272. */
  273. #ifdef USE_WINSOCK
  274. #define SOCKERRNO ((int)WSAGetLastError())
  275. #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
  276. #else
  277. #define SOCKERRNO (errno)
  278. #define SET_SOCKERRNO(x) (errno = (x))
  279. #endif
  280. /*
  281. * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
  282. * (or equivalent) on this platform to hide platform details to code using it.
  283. */
  284. #ifdef WIN32
  285. #define ERRNO ((int)GetLastError())
  286. #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
  287. #else
  288. #define ERRNO (errno)
  289. #define SET_ERRNO(x) (errno = (x))
  290. #endif
  291. /*
  292. * Portable error number symbolic names defined to Winsock error codes.
  293. */
  294. #ifdef USE_WINSOCK
  295. #undef EBADF /* override definition in errno.h */
  296. #define EBADF WSAEBADF
  297. #undef EINTR /* override definition in errno.h */
  298. #define EINTR WSAEINTR
  299. #undef EINVAL /* override definition in errno.h */
  300. #define EINVAL WSAEINVAL
  301. #define EWOULDBLOCK WSAEWOULDBLOCK
  302. #define EINPROGRESS WSAEINPROGRESS
  303. #define EALREADY WSAEALREADY
  304. #define ENOTSOCK WSAENOTSOCK
  305. #define EDESTADDRREQ WSAEDESTADDRREQ
  306. #define EMSGSIZE WSAEMSGSIZE
  307. #define EPROTOTYPE WSAEPROTOTYPE
  308. #define ENOPROTOOPT WSAENOPROTOOPT
  309. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  310. #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  311. #define EOPNOTSUPP WSAEOPNOTSUPP
  312. #define EPFNOSUPPORT WSAEPFNOSUPPORT
  313. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  314. #define EADDRINUSE WSAEADDRINUSE
  315. #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  316. #define ENETDOWN WSAENETDOWN
  317. #define ENETUNREACH WSAENETUNREACH
  318. #define ENETRESET WSAENETRESET
  319. #define ECONNABORTED WSAECONNABORTED
  320. #define ECONNRESET WSAECONNRESET
  321. #define ENOBUFS WSAENOBUFS
  322. #define EISCONN WSAEISCONN
  323. #define ENOTCONN WSAENOTCONN
  324. #define ESHUTDOWN WSAESHUTDOWN
  325. #define ETOOMANYREFS WSAETOOMANYREFS
  326. #define ETIMEDOUT WSAETIMEDOUT
  327. #define ECONNREFUSED WSAECONNREFUSED
  328. #define ELOOP WSAELOOP
  329. #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
  330. #define ENAMETOOLONG WSAENAMETOOLONG
  331. #endif
  332. #define EHOSTDOWN WSAEHOSTDOWN
  333. #define EHOSTUNREACH WSAEHOSTUNREACH
  334. #ifndef ENOTEMPTY /* possible previous definition in errno.h */
  335. #define ENOTEMPTY WSAENOTEMPTY
  336. #endif
  337. #define EPROCLIM WSAEPROCLIM
  338. #define EUSERS WSAEUSERS
  339. #define EDQUOT WSAEDQUOT
  340. #define ESTALE WSAESTALE
  341. #define EREMOTE WSAEREMOTE
  342. #endif
  343. /*
  344. * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
  345. */
  346. #if defined(VMS) && \
  347. defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
  348. #define getpwuid __32_getpwuid
  349. #endif
  350. /*
  351. * Macro argv_item_t hides platform details to code using it.
  352. */
  353. #ifdef VMS
  354. #define argv_item_t __char_ptr32
  355. #else
  356. #define argv_item_t char *
  357. #endif
  358. /*
  359. * We use this ZERO_NULL to avoid picky compiler warnings,
  360. * when assigning a NULL pointer to a function pointer var.
  361. */
  362. #define ZERO_NULL 0
  363. #endif /* __SETUP_ONCE_H */