1 #ifndef HEADER_CURL_SETUP_ONCE_H
2 #define HEADER_CURL_SETUP_ONCE_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2018, 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
105 * Definition of timeval struct for platforms that don't have it.
108 #ifndef HAVE_STRUCT_TIMEVAL
117 * If we have the MSG_NOSIGNAL define, make sure we use
118 * it as the fourth argument of function send()
121 #ifdef HAVE_MSG_NOSIGNAL
122 #define SEND_4TH_ARG MSG_NOSIGNAL
124 #define SEND_4TH_ARG 0
129 /* Minix doesn't support recv on TCP sockets */
130 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
131 (RECV_TYPE_ARG2)(y), \
134 #elif defined(HAVE_RECV)
136 * The definitions for the return type and arguments types
137 * of functions recv() and send() belong and come from the
138 * configuration file. Do not define them in any other place.
140 * HAVE_RECV is defined if you have a function named recv()
141 * which is used to read incoming data from sockets. If your
142 * function has another name then don't define HAVE_RECV.
144 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
145 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
148 * HAVE_SEND is defined if you have a function named send()
149 * which is used to write outgoing data on a connected socket.
150 * If yours has another name then don't define HAVE_SEND.
152 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
153 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
154 * SEND_TYPE_RETV must also be defined.
157 #if !defined(RECV_TYPE_ARG1) || \
158 !defined(RECV_TYPE_ARG2) || \
159 !defined(RECV_TYPE_ARG3) || \
160 !defined(RECV_TYPE_ARG4) || \
161 !defined(RECV_TYPE_RETV)
163 Error Missing_definition_of_return_and_arguments_types_of_recv
166 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
167 (RECV_TYPE_ARG2)(y), \
168 (RECV_TYPE_ARG3)(z), \
171 #else /* HAVE_RECV */
174 Error Missing_definition_of_macro_sread
177 #endif /* HAVE_RECV */
181 /* Minix doesn't support send on TCP sockets */
182 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
183 (SEND_TYPE_ARG2)(y), \
186 #elif defined(HAVE_SEND)
187 #if !defined(SEND_TYPE_ARG1) || \
188 !defined(SEND_QUAL_ARG2) || \
189 !defined(SEND_TYPE_ARG2) || \
190 !defined(SEND_TYPE_ARG3) || \
191 !defined(SEND_TYPE_ARG4) || \
192 !defined(SEND_TYPE_RETV)
194 Error Missing_definition_of_return_and_arguments_types_of_send
197 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
198 (SEND_QUAL_ARG2 SEND_TYPE_ARG2)(y), \
199 (SEND_TYPE_ARG3)(z), \
200 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
202 #else /* HAVE_SEND */
205 Error Missing_definition_of_macro_swrite
208 #endif /* HAVE_SEND */
212 #if defined(HAVE_RECVFROM)
214 * Currently recvfrom is only used on udp sockets.
216 #if !defined(RECVFROM_TYPE_ARG1) || \
217 !defined(RECVFROM_TYPE_ARG2) || \
218 !defined(RECVFROM_TYPE_ARG3) || \
219 !defined(RECVFROM_TYPE_ARG4) || \
220 !defined(RECVFROM_TYPE_ARG5) || \
221 !defined(RECVFROM_TYPE_ARG6) || \
222 !defined(RECVFROM_TYPE_RETV)
224 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
227 #define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
228 (RECVFROM_TYPE_ARG2 *)(b), \
229 (RECVFROM_TYPE_ARG3) (bl), \
230 (RECVFROM_TYPE_ARG4) (0), \
231 (RECVFROM_TYPE_ARG5 *)(f), \
232 (RECVFROM_TYPE_ARG6 *)(fl))
234 #else /* HAVE_RECVFROM */
237 Error Missing_definition_of_macro_sreadfrom
240 #endif /* HAVE_RECVFROM */
243 #ifdef RECVFROM_TYPE_ARG6_IS_VOID
244 # define RECVFROM_ARG6_T int
246 # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
252 * Function-like macro definition used to close a socket.
255 #if defined(HAVE_CLOSESOCKET)
256 # define sclose(x) closesocket((x))
257 #elif defined(HAVE_CLOSESOCKET_CAMEL)
258 # define sclose(x) CloseSocket((x))
259 #elif defined(HAVE_CLOSE_S)
260 # define sclose(x) close_s((x))
261 #elif defined(USE_LWIPSOCK)
262 # define sclose(x) lwip_close((x))
264 # define sclose(x) close((x))
268 * Stack-independent version of fcntl() on sockets:
270 #if defined(USE_LWIPSOCK)
271 # define sfcntl lwip_fcntl
273 # define sfcntl fcntl
276 #define TOLOWER(x) (tolower((int) ((unsigned char)x)))
280 * 'bool' stuff compatible with HP-UX headers.
283 #if defined(__hpux) && !defined(HAVE_BOOL_T)
292 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
293 * On non-C99 platforms there's no bool, so define an enum for that.
294 * On C99 platforms 'false' and 'true' also exist. Enum uses a
295 * global namespace though, so use bool_false and bool_true.
305 * Use a define to let 'true' and 'false' use those enums. There
306 * are currently no use of true and false in libcurl proper, but
307 * there are some in the examples. This will cater for any later
308 * code happening to use true and false.
310 # define false bool_false
311 # define true bool_true
317 * Redefine TRUE and FALSE too, to catch current use. With this
318 * change, 'bool found = 1' will give a warning on MIPSPro, but
319 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
320 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
330 #include "curl_ctype.h"
333 * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
334 * avoiding compiler warnings. Mostly intended for other macro definitions.
337 #define WHILE_FALSE while(0)
339 #if defined(_MSC_VER) && !defined(__POCC__)
341 # if (_MSC_VER < 1500)
342 # define WHILE_FALSE while(1, 0)
344 # define WHILE_FALSE \
345 __pragma(warning(push)) \
346 __pragma(warning(disable:4127)) \
348 __pragma(warning(pop))
354 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
357 #ifndef HAVE_SIG_ATOMIC_T
358 typedef int sig_atomic_t;
359 #define HAVE_SIG_ATOMIC_T
364 * Convenience SIG_ATOMIC_T definition
367 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
368 #define SIG_ATOMIC_T static sig_atomic_t
370 #define SIG_ATOMIC_T static volatile sig_atomic_t
375 * Default return type for signal handlers.
379 #define RETSIGTYPE void
384 * Macro used to include code only in debug builds.
390 #define DEBUGF(x) do { } WHILE_FALSE
395 * Macro used to include assertion code only in debug builds.
398 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
399 #define DEBUGASSERT(x) assert(x)
401 #define DEBUGASSERT(x) do { } WHILE_FALSE
406 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
407 * (or equivalent) on this platform to hide platform details to code using it.
411 #define SOCKERRNO ((int)WSAGetLastError())
412 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
414 #define SOCKERRNO (errno)
415 #define SET_SOCKERRNO(x) (errno = (x))
420 * Portable error number symbolic names defined to Winsock error codes.
424 #undef EBADF /* override definition in errno.h */
425 #define EBADF WSAEBADF
426 #undef EINTR /* override definition in errno.h */
427 #define EINTR WSAEINTR
428 #undef EINVAL /* override definition in errno.h */
429 #define EINVAL WSAEINVAL
430 #undef EWOULDBLOCK /* override definition in errno.h */
431 #define EWOULDBLOCK WSAEWOULDBLOCK
432 #undef EINPROGRESS /* override definition in errno.h */
433 #define EINPROGRESS WSAEINPROGRESS
434 #undef EALREADY /* override definition in errno.h */
435 #define EALREADY WSAEALREADY
436 #undef ENOTSOCK /* override definition in errno.h */
437 #define ENOTSOCK WSAENOTSOCK
438 #undef EDESTADDRREQ /* override definition in errno.h */
439 #define EDESTADDRREQ WSAEDESTADDRREQ
440 #undef EMSGSIZE /* override definition in errno.h */
441 #define EMSGSIZE WSAEMSGSIZE
442 #undef EPROTOTYPE /* override definition in errno.h */
443 #define EPROTOTYPE WSAEPROTOTYPE
444 #undef ENOPROTOOPT /* override definition in errno.h */
445 #define ENOPROTOOPT WSAENOPROTOOPT
446 #undef EPROTONOSUPPORT /* override definition in errno.h */
447 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
448 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
449 #undef EOPNOTSUPP /* override definition in errno.h */
450 #define EOPNOTSUPP WSAEOPNOTSUPP
451 #define EPFNOSUPPORT WSAEPFNOSUPPORT
452 #undef EAFNOSUPPORT /* override definition in errno.h */
453 #define EAFNOSUPPORT WSAEAFNOSUPPORT
454 #undef EADDRINUSE /* override definition in errno.h */
455 #define EADDRINUSE WSAEADDRINUSE
456 #undef EADDRNOTAVAIL /* override definition in errno.h */
457 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
458 #undef ENETDOWN /* override definition in errno.h */
459 #define ENETDOWN WSAENETDOWN
460 #undef ENETUNREACH /* override definition in errno.h */
461 #define ENETUNREACH WSAENETUNREACH
462 #undef ENETRESET /* override definition in errno.h */
463 #define ENETRESET WSAENETRESET
464 #undef ECONNABORTED /* override definition in errno.h */
465 #define ECONNABORTED WSAECONNABORTED
466 #undef ECONNRESET /* override definition in errno.h */
467 #define ECONNRESET WSAECONNRESET
468 #undef ENOBUFS /* override definition in errno.h */
469 #define ENOBUFS WSAENOBUFS
470 #undef EISCONN /* override definition in errno.h */
471 #define EISCONN WSAEISCONN
472 #undef ENOTCONN /* override definition in errno.h */
473 #define ENOTCONN WSAENOTCONN
474 #define ESHUTDOWN WSAESHUTDOWN
475 #define ETOOMANYREFS WSAETOOMANYREFS
476 #undef ETIMEDOUT /* override definition in errno.h */
477 #define ETIMEDOUT WSAETIMEDOUT
478 #undef ECONNREFUSED /* override definition in errno.h */
479 #define ECONNREFUSED WSAECONNREFUSED
480 #undef ELOOP /* override definition in errno.h */
481 #define ELOOP WSAELOOP
482 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
483 #define ENAMETOOLONG WSAENAMETOOLONG
485 #define EHOSTDOWN WSAEHOSTDOWN
486 #undef EHOSTUNREACH /* override definition in errno.h */
487 #define EHOSTUNREACH WSAEHOSTUNREACH
488 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
489 #define ENOTEMPTY WSAENOTEMPTY
491 #define EPROCLIM WSAEPROCLIM
492 #define EUSERS WSAEUSERS
493 #define EDQUOT WSAEDQUOT
494 #define ESTALE WSAESTALE
495 #define EREMOTE WSAEREMOTE
499 * Macro argv_item_t hides platform details to code using it.
503 #define argv_item_t __char_ptr32
505 #define argv_item_t char *
510 * We use this ZERO_NULL to avoid picky compiler warnings,
511 * when assigning a NULL pointer to a function pointer var.
517 #endif /* HEADER_CURL_SETUP_ONCE_H */