3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2008, 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 * $Id: setup_once.h,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
24 ***************************************************************************/
27 /********************************************************************
31 * Content of header files lib/setup_once.h and ares/setup_once.h *
32 * must be kept in sync. Modify the other one if you change this. *
34 ********************************************************************/
38 * Inclusion of common header files.
48 #ifdef HAVE_SYS_TYPES_H
49 #include <sys/types.h>
52 #ifdef HAVE_SYS_STAT_H
56 #ifdef HAVE_SYS_TIME_H
58 #ifdef TIME_WITH_SYS_TIME
78 * Definition of timeval struct for platforms that don't have it.
81 #ifndef HAVE_STRUCT_TIMEVAL
90 * If we have the MSG_NOSIGNAL define, make sure we use
91 * it as the fourth argument of function send()
94 #ifdef HAVE_MSG_NOSIGNAL
95 #define SEND_4TH_ARG MSG_NOSIGNAL
97 #define SEND_4TH_ARG 0
102 * Windows build targets have socklen_t definition in
103 * ws2tcpip.h but some versions of ws2tcpip.h do not
104 * have the definition. It seems that when the socklen_t
105 * definition is missing from ws2tcpip.h the definition
106 * for INET_ADDRSTRLEN is also missing, and that when one
107 * definition is present the other one also is available.
110 #if defined(WIN32) && !defined(HAVE_CONFIG_H)
111 # if ( defined(_MSC_VER) && !defined(INET_ADDRSTRLEN) ) || \
112 (!defined(_MSC_VER) && !defined(HAVE_WS2TCPIP_H) )
113 # define socklen_t int
119 /* Minix doesn't support recv on TCP sockets */
120 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
121 (RECV_TYPE_ARG2)(y), \
124 #elif defined(HAVE_RECV)
126 * The definitions for the return type and arguments types
127 * of functions recv() and send() belong and come from the
128 * configuration file. Do not define them in any other place.
130 * HAVE_RECV is defined if you have a function named recv()
131 * which is used to read incoming data from sockets. If your
132 * function has another name then don't define HAVE_RECV.
134 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
135 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
138 * HAVE_SEND is defined if you have a function named send()
139 * which is used to write outgoing data on a connected socket.
140 * If yours has another name then don't define HAVE_SEND.
142 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
143 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
144 * SEND_TYPE_RETV must also be defined.
147 #if !defined(RECV_TYPE_ARG1) || \
148 !defined(RECV_TYPE_ARG2) || \
149 !defined(RECV_TYPE_ARG3) || \
150 !defined(RECV_TYPE_ARG4) || \
151 !defined(RECV_TYPE_RETV)
153 Error Missing_definition_of_return_and_arguments_types_of_recv
156 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
157 (RECV_TYPE_ARG2)(y), \
158 (RECV_TYPE_ARG3)(z), \
161 #else /* HAVE_RECV */
164 Error Missing_definition_of_macro_sread
167 #endif /* HAVE_RECV */
171 /* Minix doesn't support send on TCP sockets */
172 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
173 (SEND_TYPE_ARG2)(y), \
176 #elif defined(HAVE_SEND)
177 #if !defined(SEND_TYPE_ARG1) || \
178 !defined(SEND_QUAL_ARG2) || \
179 !defined(SEND_TYPE_ARG2) || \
180 !defined(SEND_TYPE_ARG3) || \
181 !defined(SEND_TYPE_ARG4) || \
182 !defined(SEND_TYPE_RETV)
184 Error Missing_definition_of_return_and_arguments_types_of_send
187 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
188 (SEND_TYPE_ARG2)(y), \
189 (SEND_TYPE_ARG3)(z), \
190 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
192 #else /* HAVE_SEND */
195 Error Missing_definition_of_macro_swrite
198 #endif /* HAVE_SEND */
202 #if defined(HAVE_RECVFROM)
204 * Currently recvfrom is only used on udp sockets.
206 #if !defined(RECVFROM_TYPE_ARG1) || \
207 !defined(RECVFROM_TYPE_ARG2) || \
208 !defined(RECVFROM_TYPE_ARG3) || \
209 !defined(RECVFROM_TYPE_ARG4) || \
210 !defined(RECVFROM_TYPE_ARG5) || \
211 !defined(RECVFROM_TYPE_ARG6) || \
212 !defined(RECVFROM_TYPE_RETV)
214 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
217 #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
218 (RECVFROM_TYPE_ARG2 *)(b), \
219 (RECVFROM_TYPE_ARG3) (bl), \
220 (RECVFROM_TYPE_ARG4) (0), \
221 (RECVFROM_TYPE_ARG5 *)(f), \
222 (RECVFROM_TYPE_ARG6 *)(fl))
224 #else /* HAVE_RECVFROM */
227 Error Missing_definition_of_macro_sreadfrom
230 #endif /* HAVE_RECVFROM */
233 #ifdef RECVFROM_TYPE_ARG6_IS_VOID
234 # define RECVFROM_ARG6_T int
236 # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
242 * Uppercase macro versions of ANSI/ISO is*() functions/macros which
243 * avoid negative number inputs with argument byte codes > 127.
246 #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
247 #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
248 #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
249 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
250 #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
251 #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
252 #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
253 #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
254 #define ISLOWER(x) (islower((int) ((unsigned char)x)))
256 #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
257 (((unsigned char)x) == '\t'))
261 * Typedef to 'unsigned char' if bool is not an available 'typedefed' type.
265 typedef unsigned char bool;
271 * Default definition of uppercase TRUE and FALSE.
283 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
286 #ifndef HAVE_SIG_ATOMIC_T
287 typedef int sig_atomic_t;
288 #define HAVE_SIG_ATOMIC_T
293 * Convenience SIG_ATOMIC_T definition
296 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
297 #define SIG_ATOMIC_T static sig_atomic_t
299 #define SIG_ATOMIC_T static volatile sig_atomic_t
304 * Default return type for signal handlers.
308 #define RETSIGTYPE void
313 * Macro used to include code only in debug builds.
319 #define DEBUGF(x) do { } while (0)
324 * Macro used to include assertion code only in debug builds.
327 #if defined(CURLDEBUG) && defined(HAVE_ASSERT_H)
328 #define DEBUGASSERT(x) assert(x)
330 #define DEBUGASSERT(x) do { } while (0)
335 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
336 * (or equivalent) on this platform to hide platform details to code using it.
340 #define SOCKERRNO ((int)WSAGetLastError())
341 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
343 #define SOCKERRNO (errno)
344 #define SET_SOCKERRNO(x) (errno = (x))
349 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
350 * (or equivalent) on this platform to hide platform details to code using it.
354 #define ERRNO ((int)GetLastError())
355 #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
357 #define ERRNO (errno)
358 #define SET_ERRNO(x) (errno = (x))
363 * Portable error number symbolic names defined to Winsock error codes.
367 #undef EBADF /* override definition in errno.h */
368 #define EBADF WSAEBADF
369 #undef EINTR /* override definition in errno.h */
370 #define EINTR WSAEINTR
371 #undef EINVAL /* override definition in errno.h */
372 #define EINVAL WSAEINVAL
373 #define EWOULDBLOCK WSAEWOULDBLOCK
374 #define EINPROGRESS WSAEINPROGRESS
375 #define EALREADY WSAEALREADY
376 #define ENOTSOCK WSAENOTSOCK
377 #define EDESTADDRREQ WSAEDESTADDRREQ
378 #define EMSGSIZE WSAEMSGSIZE
379 #define EPROTOTYPE WSAEPROTOTYPE
380 #define ENOPROTOOPT WSAENOPROTOOPT
381 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
382 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
383 #define EOPNOTSUPP WSAEOPNOTSUPP
384 #define EPFNOSUPPORT WSAEPFNOSUPPORT
385 #define EAFNOSUPPORT WSAEAFNOSUPPORT
386 #define EADDRINUSE WSAEADDRINUSE
387 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
388 #define ENETDOWN WSAENETDOWN
389 #define ENETUNREACH WSAENETUNREACH
390 #define ENETRESET WSAENETRESET
391 #define ECONNABORTED WSAECONNABORTED
392 #define ECONNRESET WSAECONNRESET
393 #define ENOBUFS WSAENOBUFS
394 #define EISCONN WSAEISCONN
395 #define ENOTCONN WSAENOTCONN
396 #define ESHUTDOWN WSAESHUTDOWN
397 #define ETOOMANYREFS WSAETOOMANYREFS
398 #define ETIMEDOUT WSAETIMEDOUT
399 #define ECONNREFUSED WSAECONNREFUSED
400 #define ELOOP WSAELOOP
401 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
402 #define ENAMETOOLONG WSAENAMETOOLONG
404 #define EHOSTDOWN WSAEHOSTDOWN
405 #define EHOSTUNREACH WSAEHOSTUNREACH
406 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
407 #define ENOTEMPTY WSAENOTEMPTY
409 #define EPROCLIM WSAEPROCLIM
410 #define EUSERS WSAEUSERS
411 #define EDQUOT WSAEDQUOT
412 #define ESTALE WSAESTALE
413 #define EREMOTE WSAEREMOTE
418 * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid()
421 #if defined(VMS) && \
422 defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
423 #define getpwuid __32_getpwuid
428 * Macro argv_item_t hides platform details to code using it.
432 #define argv_item_t __char_ptr32
434 #define argv_item_t char *
439 * We use this ZERO_NULL to avoid picky compiler warnings,
440 * when assigning a NULL pointer to a function pointer var.
446 #if defined (__LP64__) && defined(__hpux) && !defined(_XOPEN_SOURCE_EXTENDED)
447 #include <sys/socket.h>
448 /* HP-UX has this oddity where it features a few functions that don't work
449 with socklen_t so we need to convert to ints
451 This is due to socklen_t being a 64bit int under 64bit ABI, but the
452 pre-xopen (default) interfaces require an int, which is 32bits.
454 Therefore, Anytime socklen_t is passed by pointer, the libc function
455 truncates the 64bit socklen_t value by treating it as a 32bit value.
458 Note that some socket calls are allowed to have a NULL pointer for
462 inline static int Curl_hp_getsockname(int s
, struct sockaddr
*name
,
468 rc
= getsockname(s
, name
, &len
);
472 rc
= getsockname(s
, name
, 0);
476 inline static int Curl_hp_getsockopt(int s
, int level
, int optname
,
477 void *optval
, socklen_t
*optlen
)
482 rc
= getsockopt(s
, level
, optname
, optval
, &len
);
486 rc
= getsockopt(s
, level
, optname
, optval
, 0);
490 inline static int Curl_hp_accept(int sockfd
, struct sockaddr
*addr
,
496 rc
= accept(sockfd
, addr
, &len
);
500 rc
= accept(sockfd
, addr
, 0);
505 inline static ssize_t
Curl_hp_recvfrom(int s
, void *buf
, size_t len
, int flags
,
506 struct sockaddr
*from
,
511 int fromlen32
= *fromlen
;
512 rc
= recvfrom(s
, buf
, len
, flags
, from
, &fromlen32
);
513 *fromlen
= fromlen32
;
516 rc
= recvfrom(s
, buf
, len
, flags
, from
, 0);
521 #define getsockname(a,b,c) Curl_hp_getsockname((a),(b),(c))
522 #define getsockopt(a,b,c,d,e) Curl_hp_getsockopt((a),(b),(c),(d),(e))
523 #define accept(a,b,c) Curl_hp_accept((a),(b),(c))
524 #define recvfrom(a,b,c,d,e,f) Curl_hp_recvfrom((a),(b),(c),(d),(e),(f))
526 #endif /* HPUX work-around */
529 #endif /* __SETUP_ONCE_H */