5 /* Copyright (C) 2004 - 2012 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))
264 # define sclose(x) close((x))
269 * Uppercase macro versions of ANSI/ISO is*() functions/macros which
270 * avoid negative number inputs with argument byte codes > 127.
273 #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
274 #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
275 #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
276 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
277 #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
278 #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
279 #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
280 #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
281 #define ISLOWER(x) (islower((int) ((unsigned char)x)))
282 #define ISASCII(x) (isascii((int) ((unsigned char)x)))
284 #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
285 (((unsigned char)x) == '\t'))
287 #define TOLOWER(x) (tolower((int) ((unsigned char)x)))
291 * 'bool' stuff compatible with HP-UX headers.
294 #if defined(__hpux) && !defined(HAVE_BOOL_T)
303 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
304 * On non-C99 platforms there's no bool, so define an enum for that.
305 * On C99 platforms 'false' and 'true' also exist. Enum uses a
306 * global namespace though, so use bool_false and bool_true.
316 * Use a define to let 'true' and 'false' use those enums. There
317 * are currently no use of true and false in libcurl proper, but
318 * there are some in the examples. This will cater for any later
319 * code happening to use true and false.
321 # define false bool_false
322 # define true bool_true
328 * Redefine TRUE and FALSE too, to catch current use. With this
329 * change, 'bool found = 1' will give a warning on MIPSPro, but
330 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
331 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
343 * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
344 * avoiding compiler warnings. Mostly intended for other macro definitions.
347 #define WHILE_FALSE while(0)
349 #if defined(_MSC_VER) && !defined(__POCC__)
351 # if (_MSC_VER < 1500)
352 # define WHILE_FALSE while(1, 0)
354 # define WHILE_FALSE \
355 __pragma(warning(push)) \
356 __pragma(warning(disable:4127)) \
358 __pragma(warning(pop))
364 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
367 #ifndef HAVE_SIG_ATOMIC_T
368 typedef int sig_atomic_t;
369 #define HAVE_SIG_ATOMIC_T
374 * Convenience SIG_ATOMIC_T definition
377 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
378 #define SIG_ATOMIC_T static sig_atomic_t
380 #define SIG_ATOMIC_T static volatile sig_atomic_t
385 * Default return type for signal handlers.
389 #define RETSIGTYPE void
394 * Macro used to include code only in debug builds.
400 #define DEBUGF(x) do { } WHILE_FALSE
405 * Macro used to include assertion code only in debug builds.
408 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
409 #define DEBUGASSERT(x) assert(x)
411 #define DEBUGASSERT(x) do { } WHILE_FALSE
416 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
417 * (or equivalent) on this platform to hide platform details to code using it.
421 #define SOCKERRNO ((int)WSAGetLastError())
422 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
424 #define SOCKERRNO (errno)
425 #define SET_SOCKERRNO(x) (errno = (x))
430 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
431 * (or equivalent) on this platform to hide platform details to code using it.
434 #if defined(WIN32) && !defined(WATT32)
435 #define ERRNO ((int)GetLastError())
436 #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
438 #define ERRNO (errno)
439 #define SET_ERRNO(x) (errno = (x))
444 * Portable error number symbolic names defined to Winsock error codes.
448 #undef EBADF /* override definition in errno.h */
449 #define EBADF WSAEBADF
450 #undef EINTR /* override definition in errno.h */
451 #define EINTR WSAEINTR
452 #undef EINVAL /* override definition in errno.h */
453 #define EINVAL WSAEINVAL
454 #undef EWOULDBLOCK /* override definition in errno.h */
455 #define EWOULDBLOCK WSAEWOULDBLOCK
456 #undef EINPROGRESS /* override definition in errno.h */
457 #define EINPROGRESS WSAEINPROGRESS
458 #undef EALREADY /* override definition in errno.h */
459 #define EALREADY WSAEALREADY
460 #undef ENOTSOCK /* override definition in errno.h */
461 #define ENOTSOCK WSAENOTSOCK
462 #undef EDESTADDRREQ /* override definition in errno.h */
463 #define EDESTADDRREQ WSAEDESTADDRREQ
464 #undef EMSGSIZE /* override definition in errno.h */
465 #define EMSGSIZE WSAEMSGSIZE
466 #undef EPROTOTYPE /* override definition in errno.h */
467 #define EPROTOTYPE WSAEPROTOTYPE
468 #undef ENOPROTOOPT /* override definition in errno.h */
469 #define ENOPROTOOPT WSAENOPROTOOPT
470 #undef EPROTONOSUPPORT /* override definition in errno.h */
471 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
472 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
473 #undef EOPNOTSUPP /* override definition in errno.h */
474 #define EOPNOTSUPP WSAEOPNOTSUPP
475 #define EPFNOSUPPORT WSAEPFNOSUPPORT
476 #undef EAFNOSUPPORT /* override definition in errno.h */
477 #define EAFNOSUPPORT WSAEAFNOSUPPORT
478 #undef EADDRINUSE /* override definition in errno.h */
479 #define EADDRINUSE WSAEADDRINUSE
480 #undef EADDRNOTAVAIL /* override definition in errno.h */
481 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
482 #undef ENETDOWN /* override definition in errno.h */
483 #define ENETDOWN WSAENETDOWN
484 #undef ENETUNREACH /* override definition in errno.h */
485 #define ENETUNREACH WSAENETUNREACH
486 #undef ENETRESET /* override definition in errno.h */
487 #define ENETRESET WSAENETRESET
488 #undef ECONNABORTED /* override definition in errno.h */
489 #define ECONNABORTED WSAECONNABORTED
490 #undef ECONNRESET /* override definition in errno.h */
491 #define ECONNRESET WSAECONNRESET
492 #undef ENOBUFS /* override definition in errno.h */
493 #define ENOBUFS WSAENOBUFS
494 #undef EISCONN /* override definition in errno.h */
495 #define EISCONN WSAEISCONN
496 #undef ENOTCONN /* override definition in errno.h */
497 #define ENOTCONN WSAENOTCONN
498 #define ESHUTDOWN WSAESHUTDOWN
499 #define ETOOMANYREFS WSAETOOMANYREFS
500 #undef ETIMEDOUT /* override definition in errno.h */
501 #define ETIMEDOUT WSAETIMEDOUT
502 #undef ECONNREFUSED /* override definition in errno.h */
503 #define ECONNREFUSED WSAECONNREFUSED
504 #undef ELOOP /* override definition in errno.h */
505 #define ELOOP WSAELOOP
506 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
507 #define ENAMETOOLONG WSAENAMETOOLONG
509 #define EHOSTDOWN WSAEHOSTDOWN
510 #undef EHOSTUNREACH /* override definition in errno.h */
511 #define EHOSTUNREACH WSAEHOSTUNREACH
512 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
513 #define ENOTEMPTY WSAENOTEMPTY
515 #define EPROCLIM WSAEPROCLIM
516 #define EUSERS WSAEUSERS
517 #define EDQUOT WSAEDQUOT
518 #define ESTALE WSAESTALE
519 #define EREMOTE WSAEREMOTE
524 * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
527 #if defined(__VMS) && \
528 defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
529 #define getpwuid __32_getpwuid
534 * Macro argv_item_t hides platform details to code using it.
538 #define argv_item_t __char_ptr32
540 #define argv_item_t char *
545 * We use this ZERO_NULL to avoid picky compiler warnings,
546 * when assigning a NULL pointer to a function pointer var.
552 #endif /* __SETUP_ONCE_H */