5 /* Copyright (C) 2004 - 2013 by Daniel Stenberg et al
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation for any purpose and without fee is hereby granted, provided
9 * that the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of M.I.T. not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. M.I.T. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
19 /********************************************************************
23 * Content of header files lib/setup_once.h and ares/setup_once.h *
24 * must be kept in sync. Modify the other one if you change this. *
26 ********************************************************************/
30 * Inclusion of common header files.
43 #ifdef HAVE_SYS_TYPES_H
44 #include <sys/types.h>
55 #ifdef HAVE_SYS_STAT_H
59 #ifdef HAVE_SYS_TIME_H
61 #ifdef TIME_WITH_SYS_TIME
75 #if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T)
84 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
85 # ifdef _APP32_64BIT_OFF_T
86 # define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T
87 # undef _APP32_64BIT_OFF_T
89 # undef OLD_APP32_64BIT_OFF_T
94 #ifdef HAVE_SYS_SOCKET_H
95 #include <sys/socket.h>
99 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
100 # ifdef OLD_APP32_64BIT_OFF_T
101 # define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T
102 # undef OLD_APP32_64BIT_OFF_T
109 * Definition of timeval struct for platforms that don't have it.
112 #ifndef HAVE_STRUCT_TIMEVAL
121 * If we have the MSG_NOSIGNAL define, make sure we use
122 * it as the fourth argument of function send()
125 #ifdef HAVE_MSG_NOSIGNAL
126 #define SEND_4TH_ARG MSG_NOSIGNAL
128 #define SEND_4TH_ARG 0
133 /* Minix doesn't support recv on TCP sockets */
134 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
135 (RECV_TYPE_ARG2)(y), \
138 #elif defined(HAVE_RECV)
140 * The definitions for the return type and arguments types
141 * of functions recv() and send() belong and come from the
142 * configuration file. Do not define them in any other place.
144 * HAVE_RECV is defined if you have a function named recv()
145 * which is used to read incoming data from sockets. If your
146 * function has another name then don't define HAVE_RECV.
148 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
149 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
152 * HAVE_SEND is defined if you have a function named send()
153 * which is used to write outgoing data on a connected socket.
154 * If yours has another name then don't define HAVE_SEND.
156 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
157 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
158 * SEND_TYPE_RETV must also be defined.
161 #if !defined(RECV_TYPE_ARG1) || \
162 !defined(RECV_TYPE_ARG2) || \
163 !defined(RECV_TYPE_ARG3) || \
164 !defined(RECV_TYPE_ARG4) || \
165 !defined(RECV_TYPE_RETV)
167 Error Missing_definition_of_return_and_arguments_types_of_recv
170 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
171 (RECV_TYPE_ARG2)(y), \
172 (RECV_TYPE_ARG3)(z), \
175 #else /* HAVE_RECV */
178 Error Missing_definition_of_macro_sread
181 #endif /* HAVE_RECV */
185 /* Minix doesn't support send on TCP sockets */
186 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
187 (SEND_TYPE_ARG2)(y), \
190 #elif defined(HAVE_SEND)
191 #if !defined(SEND_TYPE_ARG1) || \
192 !defined(SEND_QUAL_ARG2) || \
193 !defined(SEND_TYPE_ARG2) || \
194 !defined(SEND_TYPE_ARG3) || \
195 !defined(SEND_TYPE_ARG4) || \
196 !defined(SEND_TYPE_RETV)
198 Error Missing_definition_of_return_and_arguments_types_of_send
201 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
202 (SEND_TYPE_ARG2)(y), \
203 (SEND_TYPE_ARG3)(z), \
204 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
206 #else /* HAVE_SEND */
209 Error Missing_definition_of_macro_swrite
212 #endif /* HAVE_SEND */
216 #if defined(HAVE_RECVFROM)
218 * Currently recvfrom is only used on udp sockets.
220 #if !defined(RECVFROM_TYPE_ARG1) || \
221 !defined(RECVFROM_TYPE_ARG2) || \
222 !defined(RECVFROM_TYPE_ARG3) || \
223 !defined(RECVFROM_TYPE_ARG4) || \
224 !defined(RECVFROM_TYPE_ARG5) || \
225 !defined(RECVFROM_TYPE_ARG6) || \
226 !defined(RECVFROM_TYPE_RETV)
228 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
231 #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
232 (RECVFROM_TYPE_ARG2 *)(b), \
233 (RECVFROM_TYPE_ARG3) (bl), \
234 (RECVFROM_TYPE_ARG4) (0), \
235 (RECVFROM_TYPE_ARG5 *)(f), \
236 (RECVFROM_TYPE_ARG6 *)(fl))
238 #else /* HAVE_RECVFROM */
241 Error Missing_definition_of_macro_sreadfrom
244 #endif /* HAVE_RECVFROM */
247 #ifdef RECVFROM_TYPE_ARG6_IS_VOID
248 # define RECVFROM_ARG6_T int
250 # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
256 * Function-like macro definition used to close a socket.
259 #if defined(HAVE_CLOSESOCKET)
260 # define sclose(x) closesocket((x))
261 #elif defined(HAVE_CLOSESOCKET_CAMEL)
262 # define sclose(x) CloseSocket((x))
263 #elif defined(HAVE_CLOSE_S)
264 # define sclose(x) close_s((x))
266 # define sclose(x) close((x))
271 * Uppercase macro versions of ANSI/ISO is*() functions/macros which
272 * avoid negative number inputs with argument byte codes > 127.
275 #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
276 #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
277 #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
278 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
279 #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
280 #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
281 #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
282 #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
283 #define ISLOWER(x) (islower((int) ((unsigned char)x)))
284 #define ISASCII(x) (isascii((int) ((unsigned char)x)))
286 #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
287 (((unsigned char)x) == '\t'))
289 #define TOLOWER(x) (tolower((int) ((unsigned char)x)))
293 * 'bool' stuff compatible with HP-UX headers.
296 #if defined(__hpux) && !defined(HAVE_BOOL_T)
305 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
306 * On non-C99 platforms there's no bool, so define an enum for that.
307 * On C99 platforms 'false' and 'true' also exist. Enum uses a
308 * global namespace though, so use bool_false and bool_true.
318 * Use a define to let 'true' and 'false' use those enums. There
319 * are currently no use of true and false in libcurl proper, but
320 * there are some in the examples. This will cater for any later
321 * code happening to use true and false.
323 # define false bool_false
324 # define true bool_true
330 * Redefine TRUE and FALSE too, to catch current use. With this
331 * change, 'bool found = 1' will give a warning on MIPSPro, but
332 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
333 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
345 * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
346 * avoiding compiler warnings. Mostly intended for other macro definitions.
349 #define WHILE_FALSE while(0)
351 #if defined(_MSC_VER) && !defined(__POCC__)
353 # if (_MSC_VER < 1500)
354 # define WHILE_FALSE while(1, 0)
356 # define WHILE_FALSE \
357 __pragma(warning(push)) \
358 __pragma(warning(disable:4127)) \
360 __pragma(warning(pop))
366 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
369 #ifndef HAVE_SIG_ATOMIC_T
370 typedef int sig_atomic_t;
371 #define HAVE_SIG_ATOMIC_T
376 * Convenience SIG_ATOMIC_T definition
379 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
380 #define SIG_ATOMIC_T static sig_atomic_t
382 #define SIG_ATOMIC_T static volatile sig_atomic_t
387 * Default return type for signal handlers.
391 #define RETSIGTYPE void
396 * Macro used to include code only in debug builds.
402 #define DEBUGF(x) do { } WHILE_FALSE
407 * Macro used to include assertion code only in debug builds.
410 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
411 #define DEBUGASSERT(x) assert(x)
413 #define DEBUGASSERT(x) do { } WHILE_FALSE
418 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
419 * (or equivalent) on this platform to hide platform details to code using it.
423 #define SOCKERRNO ((int)WSAGetLastError())
424 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
426 #define SOCKERRNO (errno)
427 #define SET_SOCKERRNO(x) (errno = (x))
432 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
433 * (or equivalent) on this platform to hide platform details to code using it.
436 #if defined(WIN32) && !defined(WATT32)
437 #define ERRNO ((int)GetLastError())
438 #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
440 #define ERRNO (errno)
441 #define SET_ERRNO(x) (errno = (x))
446 * Portable error number symbolic names defined to Winsock error codes.
450 #undef EBADF /* override definition in errno.h */
451 #define EBADF WSAEBADF
452 #undef EINTR /* override definition in errno.h */
453 #define EINTR WSAEINTR
454 #undef EINVAL /* override definition in errno.h */
455 #define EINVAL WSAEINVAL
456 #undef EWOULDBLOCK /* override definition in errno.h */
457 #define EWOULDBLOCK WSAEWOULDBLOCK
458 #undef EINPROGRESS /* override definition in errno.h */
459 #define EINPROGRESS WSAEINPROGRESS
460 #undef EALREADY /* override definition in errno.h */
461 #define EALREADY WSAEALREADY
462 #undef ENOTSOCK /* override definition in errno.h */
463 #define ENOTSOCK WSAENOTSOCK
464 #undef EDESTADDRREQ /* override definition in errno.h */
465 #define EDESTADDRREQ WSAEDESTADDRREQ
466 #undef EMSGSIZE /* override definition in errno.h */
467 #define EMSGSIZE WSAEMSGSIZE
468 #undef EPROTOTYPE /* override definition in errno.h */
469 #define EPROTOTYPE WSAEPROTOTYPE
470 #undef ENOPROTOOPT /* override definition in errno.h */
471 #define ENOPROTOOPT WSAENOPROTOOPT
472 #undef EPROTONOSUPPORT /* override definition in errno.h */
473 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
474 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
475 #undef EOPNOTSUPP /* override definition in errno.h */
476 #define EOPNOTSUPP WSAEOPNOTSUPP
477 #define EPFNOSUPPORT WSAEPFNOSUPPORT
478 #undef EAFNOSUPPORT /* override definition in errno.h */
479 #define EAFNOSUPPORT WSAEAFNOSUPPORT
480 #undef EADDRINUSE /* override definition in errno.h */
481 #define EADDRINUSE WSAEADDRINUSE
482 #undef EADDRNOTAVAIL /* override definition in errno.h */
483 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
484 #undef ENETDOWN /* override definition in errno.h */
485 #define ENETDOWN WSAENETDOWN
486 #undef ENETUNREACH /* override definition in errno.h */
487 #define ENETUNREACH WSAENETUNREACH
488 #undef ENETRESET /* override definition in errno.h */
489 #define ENETRESET WSAENETRESET
490 #undef ECONNABORTED /* override definition in errno.h */
491 #define ECONNABORTED WSAECONNABORTED
492 #undef ECONNRESET /* override definition in errno.h */
493 #define ECONNRESET WSAECONNRESET
494 #undef ENOBUFS /* override definition in errno.h */
495 #define ENOBUFS WSAENOBUFS
496 #undef EISCONN /* override definition in errno.h */
497 #define EISCONN WSAEISCONN
498 #undef ENOTCONN /* override definition in errno.h */
499 #define ENOTCONN WSAENOTCONN
500 #define ESHUTDOWN WSAESHUTDOWN
501 #define ETOOMANYREFS WSAETOOMANYREFS
502 #undef ETIMEDOUT /* override definition in errno.h */
503 #define ETIMEDOUT WSAETIMEDOUT
504 #undef ECONNREFUSED /* override definition in errno.h */
505 #define ECONNREFUSED WSAECONNREFUSED
506 #undef ELOOP /* override definition in errno.h */
507 #define ELOOP WSAELOOP
508 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
509 #define ENAMETOOLONG WSAENAMETOOLONG
511 #define EHOSTDOWN WSAEHOSTDOWN
512 #undef EHOSTUNREACH /* override definition in errno.h */
513 #define EHOSTUNREACH WSAEHOSTUNREACH
514 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
515 #define ENOTEMPTY WSAENOTEMPTY
517 #define EPROCLIM WSAEPROCLIM
518 #define EUSERS WSAEUSERS
519 #define EDQUOT WSAEDQUOT
520 #define ESTALE WSAESTALE
521 #define EREMOTE WSAEREMOTE
526 * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
529 #if defined(__VMS) && \
530 defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
531 #define getpwuid __32_getpwuid
536 * Macro argv_item_t hides platform details to code using it.
540 #define argv_item_t __char_ptr32
542 #define argv_item_t char *
547 * We use this ZERO_NULL to avoid picky compiler warnings,
548 * when assigning a NULL pointer to a function pointer var.
554 #endif /* __SETUP_ONCE_H */