5 /* Copyright (C) 2004 - 2011 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
81 * Definition of timeval struct for platforms that don't have it.
84 #ifndef HAVE_STRUCT_TIMEVAL
93 * If we have the MSG_NOSIGNAL define, make sure we use
94 * it as the fourth argument of function send()
97 #ifdef HAVE_MSG_NOSIGNAL
98 #define SEND_4TH_ARG MSG_NOSIGNAL
100 #define SEND_4TH_ARG 0
105 /* Minix doesn't support recv on TCP sockets */
106 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
107 (RECV_TYPE_ARG2)(y), \
110 #elif defined(HAVE_RECV)
112 * The definitions for the return type and arguments types
113 * of functions recv() and send() belong and come from the
114 * configuration file. Do not define them in any other place.
116 * HAVE_RECV is defined if you have a function named recv()
117 * which is used to read incoming data from sockets. If your
118 * function has another name then don't define HAVE_RECV.
120 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
121 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
124 * HAVE_SEND is defined if you have a function named send()
125 * which is used to write outgoing data on a connected socket.
126 * If yours has another name then don't define HAVE_SEND.
128 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
129 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
130 * SEND_TYPE_RETV must also be defined.
133 #if !defined(RECV_TYPE_ARG1) || \
134 !defined(RECV_TYPE_ARG2) || \
135 !defined(RECV_TYPE_ARG3) || \
136 !defined(RECV_TYPE_ARG4) || \
137 !defined(RECV_TYPE_RETV)
139 Error Missing_definition_of_return_and_arguments_types_of_recv
142 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
143 (RECV_TYPE_ARG2)(y), \
144 (RECV_TYPE_ARG3)(z), \
147 #else /* HAVE_RECV */
150 Error Missing_definition_of_macro_sread
153 #endif /* HAVE_RECV */
157 /* Minix doesn't support send on TCP sockets */
158 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
159 (SEND_TYPE_ARG2)(y), \
162 #elif defined(HAVE_SEND)
163 #if !defined(SEND_TYPE_ARG1) || \
164 !defined(SEND_QUAL_ARG2) || \
165 !defined(SEND_TYPE_ARG2) || \
166 !defined(SEND_TYPE_ARG3) || \
167 !defined(SEND_TYPE_ARG4) || \
168 !defined(SEND_TYPE_RETV)
170 Error Missing_definition_of_return_and_arguments_types_of_send
173 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
174 (SEND_TYPE_ARG2)(y), \
175 (SEND_TYPE_ARG3)(z), \
176 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
178 #else /* HAVE_SEND */
181 Error Missing_definition_of_macro_swrite
184 #endif /* HAVE_SEND */
188 #if defined(HAVE_RECVFROM)
190 * Currently recvfrom is only used on udp sockets.
192 #if !defined(RECVFROM_TYPE_ARG1) || \
193 !defined(RECVFROM_TYPE_ARG2) || \
194 !defined(RECVFROM_TYPE_ARG3) || \
195 !defined(RECVFROM_TYPE_ARG4) || \
196 !defined(RECVFROM_TYPE_ARG5) || \
197 !defined(RECVFROM_TYPE_ARG6) || \
198 !defined(RECVFROM_TYPE_RETV)
200 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
203 #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
204 (RECVFROM_TYPE_ARG2 *)(b), \
205 (RECVFROM_TYPE_ARG3) (bl), \
206 (RECVFROM_TYPE_ARG4) (0), \
207 (RECVFROM_TYPE_ARG5 *)(f), \
208 (RECVFROM_TYPE_ARG6 *)(fl))
210 #else /* HAVE_RECVFROM */
213 Error Missing_definition_of_macro_sreadfrom
216 #endif /* HAVE_RECVFROM */
219 #ifdef RECVFROM_TYPE_ARG6_IS_VOID
220 # define RECVFROM_ARG6_T int
222 # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
228 * Function-like macro definition used to close a socket.
231 #if defined(HAVE_CLOSESOCKET)
232 # define sclose(x) closesocket((x))
233 #elif defined(HAVE_CLOSESOCKET_CAMEL)
234 # define sclose(x) CloseSocket((x))
236 # define sclose(x) close((x))
241 * Uppercase macro versions of ANSI/ISO is*() functions/macros which
242 * avoid negative number inputs with argument byte codes > 127.
245 #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
246 #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
247 #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
248 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
249 #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
250 #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
251 #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
252 #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
253 #define ISLOWER(x) (islower((int) ((unsigned char)x)))
254 #define ISASCII(x) (isascii((int) ((unsigned char)x)))
256 #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
257 (((unsigned char)x) == '\t'))
259 #define TOLOWER(x) (tolower((int) ((unsigned char)x)))
263 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
264 * On non-C99 platforms there's no bool, so define an enum for that.
265 * On C99 platforms 'false' and 'true' also exist. Enum uses a
266 * global namespace though, so use bool_false and bool_true.
276 * Use a define to let 'true' and 'false' use those enums. There
277 * are currently no use of true and false in libcurl proper, but
278 * there are some in the examples. This will cater for any later
279 * code happening to use true and false.
281 # define false bool_false
282 # define true bool_true
288 * Redefine TRUE and FALSE too, to catch current use. With this
289 * change, 'bool found = 1' will give a warning on MIPSPro, but
290 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
291 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
303 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
306 #ifndef HAVE_SIG_ATOMIC_T
307 typedef int sig_atomic_t;
308 #define HAVE_SIG_ATOMIC_T
313 * Convenience SIG_ATOMIC_T definition
316 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
317 #define SIG_ATOMIC_T static sig_atomic_t
319 #define SIG_ATOMIC_T static volatile sig_atomic_t
324 * Default return type for signal handlers.
328 #define RETSIGTYPE void
333 * Macro used to include code only in debug builds.
339 #define DEBUGF(x) do { } while (0)
344 * Macro used to include assertion code only in debug builds.
347 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
348 #define DEBUGASSERT(x) assert(x)
350 #define DEBUGASSERT(x) do { } while (0)
355 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
356 * (or equivalent) on this platform to hide platform details to code using it.
360 #define SOCKERRNO ((int)WSAGetLastError())
361 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
363 #define SOCKERRNO (errno)
364 #define SET_SOCKERRNO(x) (errno = (x))
369 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
370 * (or equivalent) on this platform to hide platform details to code using it.
373 #if defined(WIN32) && !defined(WATT32)
374 #define ERRNO ((int)GetLastError())
375 #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
377 #define ERRNO (errno)
378 #define SET_ERRNO(x) (errno = (x))
383 * Portable error number symbolic names defined to Winsock error codes.
387 #undef EBADF /* override definition in errno.h */
388 #define EBADF WSAEBADF
389 #undef EINTR /* override definition in errno.h */
390 #define EINTR WSAEINTR
391 #undef EINVAL /* override definition in errno.h */
392 #define EINVAL WSAEINVAL
393 #undef EWOULDBLOCK /* override definition in errno.h */
394 #define EWOULDBLOCK WSAEWOULDBLOCK
395 #undef EINPROGRESS /* override definition in errno.h */
396 #define EINPROGRESS WSAEINPROGRESS
397 #undef EALREADY /* override definition in errno.h */
398 #define EALREADY WSAEALREADY
399 #undef ENOTSOCK /* override definition in errno.h */
400 #define ENOTSOCK WSAENOTSOCK
401 #undef EDESTADDRREQ /* override definition in errno.h */
402 #define EDESTADDRREQ WSAEDESTADDRREQ
403 #undef EMSGSIZE /* override definition in errno.h */
404 #define EMSGSIZE WSAEMSGSIZE
405 #undef EPROTOTYPE /* override definition in errno.h */
406 #define EPROTOTYPE WSAEPROTOTYPE
407 #undef ENOPROTOOPT /* override definition in errno.h */
408 #define ENOPROTOOPT WSAENOPROTOOPT
409 #undef EPROTONOSUPPORT /* override definition in errno.h */
410 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
411 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
412 #undef EOPNOTSUPP /* override definition in errno.h */
413 #define EOPNOTSUPP WSAEOPNOTSUPP
414 #define EPFNOSUPPORT WSAEPFNOSUPPORT
415 #undef EAFNOSUPPORT /* override definition in errno.h */
416 #define EAFNOSUPPORT WSAEAFNOSUPPORT
417 #undef EADDRINUSE /* override definition in errno.h */
418 #define EADDRINUSE WSAEADDRINUSE
419 #undef EADDRNOTAVAIL /* override definition in errno.h */
420 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
421 #undef ENETDOWN /* override definition in errno.h */
422 #define ENETDOWN WSAENETDOWN
423 #undef ENETUNREACH /* override definition in errno.h */
424 #define ENETUNREACH WSAENETUNREACH
425 #undef ENETRESET /* override definition in errno.h */
426 #define ENETRESET WSAENETRESET
427 #undef ECONNABORTED /* override definition in errno.h */
428 #define ECONNABORTED WSAECONNABORTED
429 #undef ECONNRESET /* override definition in errno.h */
430 #define ECONNRESET WSAECONNRESET
431 #undef ENOBUFS /* override definition in errno.h */
432 #define ENOBUFS WSAENOBUFS
433 #undef EISCONN /* override definition in errno.h */
434 #define EISCONN WSAEISCONN
435 #undef ENOTCONN /* override definition in errno.h */
436 #define ENOTCONN WSAENOTCONN
437 #define ESHUTDOWN WSAESHUTDOWN
438 #define ETOOMANYREFS WSAETOOMANYREFS
439 #undef ETIMEDOUT /* override definition in errno.h */
440 #define ETIMEDOUT WSAETIMEDOUT
441 #undef ECONNREFUSED /* override definition in errno.h */
442 #define ECONNREFUSED WSAECONNREFUSED
443 #undef ELOOP /* override definition in errno.h */
444 #define ELOOP WSAELOOP
445 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
446 #define ENAMETOOLONG WSAENAMETOOLONG
448 #define EHOSTDOWN WSAEHOSTDOWN
449 #undef EHOSTUNREACH /* override definition in errno.h */
450 #define EHOSTUNREACH WSAEHOSTUNREACH
451 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
452 #define ENOTEMPTY WSAENOTEMPTY
454 #define EPROCLIM WSAEPROCLIM
455 #define EUSERS WSAEUSERS
456 #define EDQUOT WSAEDQUOT
457 #define ESTALE WSAESTALE
458 #define EREMOTE WSAEREMOTE
463 * System error codes for Windows CE
466 #if defined(WIN32) && !defined(HAVE_ERRNO_H)
467 #define ENOENT ERROR_FILE_NOT_FOUND
468 #define ESRCH ERROR_PATH_NOT_FOUND
469 #define ENOMEM ERROR_NOT_ENOUGH_MEMORY
470 #define ENOSPC ERROR_INVALID_PARAMETER
475 * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
478 #if defined(__VMS) && \
479 defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
480 #define getpwuid __32_getpwuid
485 * Macro argv_item_t hides platform details to code using it.
489 #define argv_item_t __char_ptr32
491 #define argv_item_t char *
496 * We use this ZERO_NULL to avoid picky compiler warnings,
497 * when assigning a NULL pointer to a function pointer var.
503 #endif /* __SETUP_ONCE_H */