3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
26 /********************************************************************
30 * Content of header files lib/setup_once.h and ares/setup_once.h *
31 * must be kept in sync. Modify the other one if you change this. *
33 ********************************************************************/
37 * Inclusion of common header files.
47 #ifdef HAVE_SYS_TYPES_H
48 #include <sys/types.h>
59 #ifdef HAVE_SYS_STAT_H
63 #ifdef HAVE_SYS_TIME_H
65 #ifdef TIME_WITH_SYS_TIME
85 * Definition of timeval struct for platforms that don't have it.
88 #ifndef HAVE_STRUCT_TIMEVAL
97 * If we have the MSG_NOSIGNAL define, make sure we use
98 * it as the fourth argument of function send()
101 #ifdef HAVE_MSG_NOSIGNAL
102 #define SEND_4TH_ARG MSG_NOSIGNAL
104 #define SEND_4TH_ARG 0
109 /* Minix doesn't support recv on TCP sockets */
110 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
111 (RECV_TYPE_ARG2)(y), \
114 #elif defined(HAVE_RECV)
116 * The definitions for the return type and arguments types
117 * of functions recv() and send() belong and come from the
118 * configuration file. Do not define them in any other place.
120 * HAVE_RECV is defined if you have a function named recv()
121 * which is used to read incoming data from sockets. If your
122 * function has another name then don't define HAVE_RECV.
124 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
125 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
128 * HAVE_SEND is defined if you have a function named send()
129 * which is used to write outgoing data on a connected socket.
130 * If yours has another name then don't define HAVE_SEND.
132 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
133 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
134 * SEND_TYPE_RETV must also be defined.
137 #if !defined(RECV_TYPE_ARG1) || \
138 !defined(RECV_TYPE_ARG2) || \
139 !defined(RECV_TYPE_ARG3) || \
140 !defined(RECV_TYPE_ARG4) || \
141 !defined(RECV_TYPE_RETV)
143 Error Missing_definition_of_return_and_arguments_types_of_recv
146 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
147 (RECV_TYPE_ARG2)(y), \
148 (RECV_TYPE_ARG3)(z), \
151 #else /* HAVE_RECV */
154 Error Missing_definition_of_macro_sread
157 #endif /* HAVE_RECV */
161 /* Minix doesn't support send on TCP sockets */
162 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
163 (SEND_TYPE_ARG2)(y), \
166 #elif defined(HAVE_SEND)
167 #if !defined(SEND_TYPE_ARG1) || \
168 !defined(SEND_QUAL_ARG2) || \
169 !defined(SEND_TYPE_ARG2) || \
170 !defined(SEND_TYPE_ARG3) || \
171 !defined(SEND_TYPE_ARG4) || \
172 !defined(SEND_TYPE_RETV)
174 Error Missing_definition_of_return_and_arguments_types_of_send
177 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
178 (SEND_TYPE_ARG2)(y), \
179 (SEND_TYPE_ARG3)(z), \
180 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
182 #else /* HAVE_SEND */
185 Error Missing_definition_of_macro_swrite
188 #endif /* HAVE_SEND */
192 #if defined(HAVE_RECVFROM)
194 * Currently recvfrom is only used on udp sockets.
196 #if !defined(RECVFROM_TYPE_ARG1) || \
197 !defined(RECVFROM_TYPE_ARG2) || \
198 !defined(RECVFROM_TYPE_ARG3) || \
199 !defined(RECVFROM_TYPE_ARG4) || \
200 !defined(RECVFROM_TYPE_ARG5) || \
201 !defined(RECVFROM_TYPE_ARG6) || \
202 !defined(RECVFROM_TYPE_RETV)
204 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
207 #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
208 (RECVFROM_TYPE_ARG2 *)(b), \
209 (RECVFROM_TYPE_ARG3) (bl), \
210 (RECVFROM_TYPE_ARG4) (0), \
211 (RECVFROM_TYPE_ARG5 *)(f), \
212 (RECVFROM_TYPE_ARG6 *)(fl))
214 #else /* HAVE_RECVFROM */
217 Error Missing_definition_of_macro_sreadfrom
220 #endif /* HAVE_RECVFROM */
223 #ifdef RECVFROM_TYPE_ARG6_IS_VOID
224 # define RECVFROM_ARG6_T int
226 # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
232 * Function-like macro definition used to close a socket.
235 #if defined(HAVE_CLOSESOCKET)
236 # define sclose(x) closesocket((x))
237 #elif defined(HAVE_CLOSESOCKET_CAMEL)
238 # define sclose(x) CloseSocket((x))
240 # define sclose(x) close((x))
245 * Uppercase macro versions of ANSI/ISO is*() functions/macros which
246 * avoid negative number inputs with argument byte codes > 127.
249 #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
250 #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
251 #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
252 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
253 #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
254 #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
255 #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
256 #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
257 #define ISLOWER(x) (islower((int) ((unsigned char)x)))
259 #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
260 (((unsigned char)x) == '\t'))
264 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
265 * On non-C99 platforms there's no bool, so define an enum for that.
266 * On C99 platforms 'false' and 'true' also exist. Enum uses a
267 * global namespace though, so use bool_false and bool_true.
277 * Use a define to let 'true' and 'false' use those enums. There
278 * are currently no use of true and false in libcurl proper, but
279 * there are some in the examples. This will cater for any later
280 * code happening to use true and false.
282 # define false bool_false
283 # define true bool_true
289 * Redefine TRUE and FALSE too, to catch current use. With this
290 * change, 'bool found = 1' will give a warning on MIPSPro, but
291 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
292 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
304 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
307 #ifndef HAVE_SIG_ATOMIC_T
308 typedef int sig_atomic_t;
309 #define HAVE_SIG_ATOMIC_T
314 * Convenience SIG_ATOMIC_T definition
317 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
318 #define SIG_ATOMIC_T static sig_atomic_t
320 #define SIG_ATOMIC_T static volatile sig_atomic_t
325 * Default return type for signal handlers.
329 #define RETSIGTYPE void
334 * Macro used to include code only in debug builds.
340 #define DEBUGF(x) do { } while (0)
345 * Macro used to include assertion code only in debug builds.
348 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
349 #define DEBUGASSERT(x) assert(x)
351 #define DEBUGASSERT(x) do { } while (0)
356 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
357 * (or equivalent) on this platform to hide platform details to code using it.
361 #define SOCKERRNO ((int)WSAGetLastError())
362 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
364 #define SOCKERRNO (errno)
365 #define SET_SOCKERRNO(x) (errno = (x))
370 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
371 * (or equivalent) on this platform to hide platform details to code using it.
375 #define ERRNO ((int)GetLastError())
376 #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
378 #define ERRNO (errno)
379 #define SET_ERRNO(x) (errno = (x))
384 * Portable error number symbolic names defined to Winsock error codes.
388 #undef EBADF /* override definition in errno.h */
389 #define EBADF WSAEBADF
390 #undef EINTR /* override definition in errno.h */
391 #define EINTR WSAEINTR
392 #undef EINVAL /* override definition in errno.h */
393 #define EINVAL WSAEINVAL
394 #undef EWOULDBLOCK /* override definition in errno.h */
395 #define EWOULDBLOCK WSAEWOULDBLOCK
396 #undef EINPROGRESS /* override definition in errno.h */
397 #define EINPROGRESS WSAEINPROGRESS
398 #undef EALREADY /* override definition in errno.h */
399 #define EALREADY WSAEALREADY
400 #undef ENOTSOCK /* override definition in errno.h */
401 #define ENOTSOCK WSAENOTSOCK
402 #undef EDESTADDRREQ /* override definition in errno.h */
403 #define EDESTADDRREQ WSAEDESTADDRREQ
404 #undef EMSGSIZE /* override definition in errno.h */
405 #define EMSGSIZE WSAEMSGSIZE
406 #undef EPROTOTYPE /* override definition in errno.h */
407 #define EPROTOTYPE WSAEPROTOTYPE
408 #undef ENOPROTOOPT /* override definition in errno.h */
409 #define ENOPROTOOPT WSAENOPROTOOPT
410 #undef EPROTONOSUPPORT /* override definition in errno.h */
411 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
412 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
413 #undef EOPNOTSUPP /* override definition in errno.h */
414 #define EOPNOTSUPP WSAEOPNOTSUPP
415 #define EPFNOSUPPORT WSAEPFNOSUPPORT
416 #undef EAFNOSUPPORT /* override definition in errno.h */
417 #define EAFNOSUPPORT WSAEAFNOSUPPORT
418 #undef EADDRINUSE /* override definition in errno.h */
419 #define EADDRINUSE WSAEADDRINUSE
420 #undef EADDRNOTAVAIL /* override definition in errno.h */
421 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
422 #undef ENETDOWN /* override definition in errno.h */
423 #define ENETDOWN WSAENETDOWN
424 #undef ENETUNREACH /* override definition in errno.h */
425 #define ENETUNREACH WSAENETUNREACH
426 #undef ENETRESET /* override definition in errno.h */
427 #define ENETRESET WSAENETRESET
428 #undef ECONNABORTED /* override definition in errno.h */
429 #define ECONNABORTED WSAECONNABORTED
430 #undef ECONNRESET /* override definition in errno.h */
431 #define ECONNRESET WSAECONNRESET
432 #undef ENOBUFS /* override definition in errno.h */
433 #define ENOBUFS WSAENOBUFS
434 #undef EISCONN /* override definition in errno.h */
435 #define EISCONN WSAEISCONN
436 #undef ENOTCONN /* override definition in errno.h */
437 #define ENOTCONN WSAENOTCONN
438 #define ESHUTDOWN WSAESHUTDOWN
439 #define ETOOMANYREFS WSAETOOMANYREFS
440 #undef ETIMEDOUT /* override definition in errno.h */
441 #define ETIMEDOUT WSAETIMEDOUT
442 #undef ECONNREFUSED /* override definition in errno.h */
443 #define ECONNREFUSED WSAECONNREFUSED
444 #undef ELOOP /* override definition in errno.h */
445 #define ELOOP WSAELOOP
446 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
447 #define ENAMETOOLONG WSAENAMETOOLONG
449 #define EHOSTDOWN WSAEHOSTDOWN
450 #undef EHOSTUNREACH /* override definition in errno.h */
451 #define EHOSTUNREACH WSAEHOSTUNREACH
452 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
453 #define ENOTEMPTY WSAENOTEMPTY
455 #define EPROCLIM WSAEPROCLIM
456 #define EUSERS WSAEUSERS
457 #define EDQUOT WSAEDQUOT
458 #define ESTALE WSAESTALE
459 #define EREMOTE WSAEREMOTE
464 * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
467 #if defined(__VMS) && \
468 defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
469 #define getpwuid __32_getpwuid
474 * Macro argv_item_t hides platform details to code using it.
478 #define argv_item_t __char_ptr32
480 #define argv_item_t char *
485 * We use this ZERO_NULL to avoid picky compiler warnings,
486 * when assigning a NULL pointer to a function pointer var.
492 #endif /* __SETUP_ONCE_H */