1 #ifndef HEADER_CURL_SETUP_ONCE_H
2 #define HEADER_CURL_SETUP_ONCE_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2013, 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 https://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 ***************************************************************************/
27 * Inclusion of common header files.
40 #ifdef HAVE_SYS_TYPES_H
41 #include <sys/types.h>
52 #ifdef HAVE_SYS_STAT_H
56 #ifdef HAVE_SYS_TIME_H
58 #ifdef TIME_WITH_SYS_TIME
72 #if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T)
81 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
82 # ifdef _APP32_64BIT_OFF_T
83 # define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T
84 # undef _APP32_64BIT_OFF_T
86 # undef OLD_APP32_64BIT_OFF_T
91 #ifdef HAVE_SYS_SOCKET_H
92 #include <sys/socket.h>
96 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
97 # ifdef OLD_APP32_64BIT_OFF_T
98 # define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T
99 # undef OLD_APP32_64BIT_OFF_T
106 * Definition of timeval struct for platforms that don't have it.
109 #ifndef HAVE_STRUCT_TIMEVAL
118 * If we have the MSG_NOSIGNAL define, make sure we use
119 * it as the fourth argument of function send()
122 #ifdef HAVE_MSG_NOSIGNAL
123 #define SEND_4TH_ARG MSG_NOSIGNAL
125 #define SEND_4TH_ARG 0
130 /* Minix doesn't support recv on TCP sockets */
131 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
132 (RECV_TYPE_ARG2)(y), \
135 #elif defined(HAVE_RECV)
137 * The definitions for the return type and arguments types
138 * of functions recv() and send() belong and come from the
139 * configuration file. Do not define them in any other place.
141 * HAVE_RECV is defined if you have a function named recv()
142 * which is used to read incoming data from sockets. If your
143 * function has another name then don't define HAVE_RECV.
145 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
146 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
149 * HAVE_SEND is defined if you have a function named send()
150 * which is used to write outgoing data on a connected socket.
151 * If yours has another name then don't define HAVE_SEND.
153 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
154 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
155 * SEND_TYPE_RETV must also be defined.
158 #if !defined(RECV_TYPE_ARG1) || \
159 !defined(RECV_TYPE_ARG2) || \
160 !defined(RECV_TYPE_ARG3) || \
161 !defined(RECV_TYPE_ARG4) || \
162 !defined(RECV_TYPE_RETV)
164 Error Missing_definition_of_return_and_arguments_types_of_recv
167 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
168 (RECV_TYPE_ARG2)(y), \
169 (RECV_TYPE_ARG3)(z), \
172 #else /* HAVE_RECV */
175 Error Missing_definition_of_macro_sread
178 #endif /* HAVE_RECV */
182 /* Minix doesn't support send on TCP sockets */
183 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
184 (SEND_TYPE_ARG2)(y), \
187 #elif defined(HAVE_SEND)
188 #if !defined(SEND_TYPE_ARG1) || \
189 !defined(SEND_QUAL_ARG2) || \
190 !defined(SEND_TYPE_ARG2) || \
191 !defined(SEND_TYPE_ARG3) || \
192 !defined(SEND_TYPE_ARG4) || \
193 !defined(SEND_TYPE_RETV)
195 Error Missing_definition_of_return_and_arguments_types_of_send
198 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
199 (SEND_TYPE_ARG2)(y), \
200 (SEND_TYPE_ARG3)(z), \
201 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
203 #else /* HAVE_SEND */
206 Error Missing_definition_of_macro_swrite
209 #endif /* HAVE_SEND */
213 #if defined(HAVE_RECVFROM)
215 * Currently recvfrom is only used on udp sockets.
217 #if !defined(RECVFROM_TYPE_ARG1) || \
218 !defined(RECVFROM_TYPE_ARG2) || \
219 !defined(RECVFROM_TYPE_ARG3) || \
220 !defined(RECVFROM_TYPE_ARG4) || \
221 !defined(RECVFROM_TYPE_ARG5) || \
222 !defined(RECVFROM_TYPE_ARG6) || \
223 !defined(RECVFROM_TYPE_RETV)
225 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
228 #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
229 (RECVFROM_TYPE_ARG2 *)(b), \
230 (RECVFROM_TYPE_ARG3) (bl), \
231 (RECVFROM_TYPE_ARG4) (0), \
232 (RECVFROM_TYPE_ARG5 *)(f), \
233 (RECVFROM_TYPE_ARG6 *)(fl))
235 #else /* HAVE_RECVFROM */
238 Error Missing_definition_of_macro_sreadfrom
241 #endif /* HAVE_RECVFROM */
244 #ifdef RECVFROM_TYPE_ARG6_IS_VOID
245 # define RECVFROM_ARG6_T int
247 # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
253 * Function-like macro definition used to close a socket.
256 #if defined(HAVE_CLOSESOCKET)
257 # define sclose(x) closesocket((x))
258 #elif defined(HAVE_CLOSESOCKET_CAMEL)
259 # define sclose(x) CloseSocket((x))
260 #elif defined(HAVE_CLOSE_S)
261 # define sclose(x) close_s((x))
262 #elif defined(USE_LWIPSOCK)
263 # define sclose(x) lwip_close((x))
265 # define sclose(x) close((x))
269 * Stack-independent version of fcntl() on sockets:
271 #if defined(USE_LWIPSOCK)
272 # define sfcntl lwip_fcntl
274 # define sfcntl fcntl
278 * Uppercase macro versions of ANSI/ISO is*() functions/macros which
279 * avoid negative number inputs with argument byte codes > 127.
282 #define ISSPACE(x) (isspace((int) ((unsigned char)x)))
283 #define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
284 #define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
285 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
286 #define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
287 #define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
288 #define ISPRINT(x) (isprint((int) ((unsigned char)x)))
289 #define ISUPPER(x) (isupper((int) ((unsigned char)x)))
290 #define ISLOWER(x) (islower((int) ((unsigned char)x)))
291 #define ISASCII(x) (isascii((int) ((unsigned char)x)))
293 #define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
294 (((unsigned char)x) == '\t'))
296 #define TOLOWER(x) (tolower((int) ((unsigned char)x)))
300 * 'bool' stuff compatible with HP-UX headers.
303 #if defined(__hpux) && !defined(HAVE_BOOL_T)
312 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
313 * On non-C99 platforms there's no bool, so define an enum for that.
314 * On C99 platforms 'false' and 'true' also exist. Enum uses a
315 * global namespace though, so use bool_false and bool_true.
325 * Use a define to let 'true' and 'false' use those enums. There
326 * are currently no use of true and false in libcurl proper, but
327 * there are some in the examples. This will cater for any later
328 * code happening to use true and false.
330 # define false bool_false
331 # define true bool_true
337 * Redefine TRUE and FALSE too, to catch current use. With this
338 * change, 'bool found = 1' will give a warning on MIPSPro, but
339 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
340 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
352 * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
353 * avoiding compiler warnings. Mostly intended for other macro definitions.
356 #define WHILE_FALSE while(0)
358 #if defined(_MSC_VER) && !defined(__POCC__)
360 # if (_MSC_VER < 1500)
361 # define WHILE_FALSE while(1, 0)
363 # define WHILE_FALSE \
364 __pragma(warning(push)) \
365 __pragma(warning(disable:4127)) \
367 __pragma(warning(pop))
373 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
376 #ifndef HAVE_SIG_ATOMIC_T
377 typedef int sig_atomic_t;
378 #define HAVE_SIG_ATOMIC_T
383 * Convenience SIG_ATOMIC_T definition
386 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
387 #define SIG_ATOMIC_T static sig_atomic_t
389 #define SIG_ATOMIC_T static volatile sig_atomic_t
394 * Default return type for signal handlers.
398 #define RETSIGTYPE void
403 * Macro used to include code only in debug builds.
409 #define DEBUGF(x) do { } WHILE_FALSE
414 * Macro used to include assertion code only in debug builds.
417 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
418 #define DEBUGASSERT(x) assert(x)
420 #define DEBUGASSERT(x) do { } WHILE_FALSE
425 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
426 * (or equivalent) on this platform to hide platform details to code using it.
430 #define SOCKERRNO ((int)WSAGetLastError())
431 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
433 #define SOCKERRNO (errno)
434 #define SET_SOCKERRNO(x) (errno = (x))
439 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
440 * (or equivalent) on this platform to hide platform details to code using it.
443 #if defined(WIN32) && !defined(USE_LWIPSOCK)
444 #define ERRNO ((int)GetLastError())
445 #define SET_ERRNO(x) (SetLastError((DWORD)(x)))
447 #define ERRNO (errno)
448 #define SET_ERRNO(x) (errno = (x))
453 * Portable error number symbolic names defined to Winsock error codes.
457 #undef EBADF /* override definition in errno.h */
458 #define EBADF WSAEBADF
459 #undef EINTR /* override definition in errno.h */
460 #define EINTR WSAEINTR
461 #undef EINVAL /* override definition in errno.h */
462 #define EINVAL WSAEINVAL
463 #undef EWOULDBLOCK /* override definition in errno.h */
464 #define EWOULDBLOCK WSAEWOULDBLOCK
465 #undef EINPROGRESS /* override definition in errno.h */
466 #define EINPROGRESS WSAEINPROGRESS
467 #undef EALREADY /* override definition in errno.h */
468 #define EALREADY WSAEALREADY
469 #undef ENOTSOCK /* override definition in errno.h */
470 #define ENOTSOCK WSAENOTSOCK
471 #undef EDESTADDRREQ /* override definition in errno.h */
472 #define EDESTADDRREQ WSAEDESTADDRREQ
473 #undef EMSGSIZE /* override definition in errno.h */
474 #define EMSGSIZE WSAEMSGSIZE
475 #undef EPROTOTYPE /* override definition in errno.h */
476 #define EPROTOTYPE WSAEPROTOTYPE
477 #undef ENOPROTOOPT /* override definition in errno.h */
478 #define ENOPROTOOPT WSAENOPROTOOPT
479 #undef EPROTONOSUPPORT /* override definition in errno.h */
480 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
481 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
482 #undef EOPNOTSUPP /* override definition in errno.h */
483 #define EOPNOTSUPP WSAEOPNOTSUPP
484 #define EPFNOSUPPORT WSAEPFNOSUPPORT
485 #undef EAFNOSUPPORT /* override definition in errno.h */
486 #define EAFNOSUPPORT WSAEAFNOSUPPORT
487 #undef EADDRINUSE /* override definition in errno.h */
488 #define EADDRINUSE WSAEADDRINUSE
489 #undef EADDRNOTAVAIL /* override definition in errno.h */
490 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
491 #undef ENETDOWN /* override definition in errno.h */
492 #define ENETDOWN WSAENETDOWN
493 #undef ENETUNREACH /* override definition in errno.h */
494 #define ENETUNREACH WSAENETUNREACH
495 #undef ENETRESET /* override definition in errno.h */
496 #define ENETRESET WSAENETRESET
497 #undef ECONNABORTED /* override definition in errno.h */
498 #define ECONNABORTED WSAECONNABORTED
499 #undef ECONNRESET /* override definition in errno.h */
500 #define ECONNRESET WSAECONNRESET
501 #undef ENOBUFS /* override definition in errno.h */
502 #define ENOBUFS WSAENOBUFS
503 #undef EISCONN /* override definition in errno.h */
504 #define EISCONN WSAEISCONN
505 #undef ENOTCONN /* override definition in errno.h */
506 #define ENOTCONN WSAENOTCONN
507 #define ESHUTDOWN WSAESHUTDOWN
508 #define ETOOMANYREFS WSAETOOMANYREFS
509 #undef ETIMEDOUT /* override definition in errno.h */
510 #define ETIMEDOUT WSAETIMEDOUT
511 #undef ECONNREFUSED /* override definition in errno.h */
512 #define ECONNREFUSED WSAECONNREFUSED
513 #undef ELOOP /* override definition in errno.h */
514 #define ELOOP WSAELOOP
515 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
516 #define ENAMETOOLONG WSAENAMETOOLONG
518 #define EHOSTDOWN WSAEHOSTDOWN
519 #undef EHOSTUNREACH /* override definition in errno.h */
520 #define EHOSTUNREACH WSAEHOSTUNREACH
521 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
522 #define ENOTEMPTY WSAENOTEMPTY
524 #define EPROCLIM WSAEPROCLIM
525 #define EUSERS WSAEUSERS
526 #define EDQUOT WSAEDQUOT
527 #define ESTALE WSAESTALE
528 #define EREMOTE WSAEREMOTE
532 * Macro argv_item_t hides platform details to code using it.
536 #define argv_item_t __char_ptr32
538 #define argv_item_t char *
543 * We use this ZERO_NULL to avoid picky compiler warnings,
544 * when assigning a NULL pointer to a function pointer var.
550 #endif /* HEADER_CURL_SETUP_ONCE_H */