1 #ifndef HEADER_CURL_SETUP_ONCE_H
2 #define HEADER_CURL_SETUP_ONCE_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2022, 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.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 * SPDX-License-Identifier: curl
25 ***************************************************************************/
29 * Inclusion of common header files.
42 #ifdef HAVE_SYS_TYPES_H
43 #include <sys/types.h>
54 #ifdef HAVE_SYS_STAT_H
58 #ifdef HAVE_SYS_TIME_H
67 #if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T)
76 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
77 # ifdef _APP32_64BIT_OFF_T
78 # define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T
79 # undef _APP32_64BIT_OFF_T
81 # undef OLD_APP32_64BIT_OFF_T
86 #ifdef HAVE_SYS_SOCKET_H
87 #include <sys/socket.h>
90 #include "functypes.h"
93 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL)
94 # ifdef OLD_APP32_64BIT_OFF_T
95 # define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T
96 # undef OLD_APP32_64BIT_OFF_T
102 * Definition of timeval struct for platforms that don't have it.
105 #ifndef HAVE_STRUCT_TIMEVAL
114 * If we have the MSG_NOSIGNAL define, make sure we use
115 * it as the fourth argument of function send()
118 #ifdef HAVE_MSG_NOSIGNAL
119 #define SEND_4TH_ARG MSG_NOSIGNAL
121 #define SEND_4TH_ARG 0
126 /* Minix doesn't support recv on TCP sockets */
127 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
128 (RECV_TYPE_ARG2)(y), \
131 #elif defined(HAVE_RECV)
133 * The definitions for the return type and arguments types
134 * of functions recv() and send() belong and come from the
135 * configuration file. Do not define them in any other place.
137 * HAVE_RECV is defined if you have a function named recv()
138 * which is used to read incoming data from sockets. If your
139 * function has another name then don't define HAVE_RECV.
141 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
142 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
145 * HAVE_SEND is defined if you have a function named send()
146 * which is used to write outgoing data on a connected socket.
147 * If yours has another name then don't define HAVE_SEND.
149 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
150 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
151 * SEND_TYPE_RETV must also be defined.
154 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
155 (RECV_TYPE_ARG2)(y), \
156 (RECV_TYPE_ARG3)(z), \
158 #else /* HAVE_RECV */
161 Error Missing_definition_of_macro_sread
164 #endif /* HAVE_RECV */
168 /* Minix doesn't support send on TCP sockets */
169 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
170 (SEND_TYPE_ARG2)(y), \
173 #elif defined(HAVE_SEND)
174 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
175 (SEND_QUAL_ARG2 SEND_TYPE_ARG2)(y), \
176 (SEND_TYPE_ARG3)(z), \
177 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
178 #else /* HAVE_SEND */
181 Error Missing_definition_of_macro_swrite
184 #endif /* HAVE_SEND */
188 * Function-like macro definition used to close a socket.
191 #if defined(HAVE_CLOSESOCKET)
192 # define sclose(x) closesocket((x))
193 #elif defined(HAVE_CLOSESOCKET_CAMEL)
194 # define sclose(x) CloseSocket((x))
195 #elif defined(HAVE_CLOSE_S)
196 # define sclose(x) close_s((x))
197 #elif defined(USE_LWIPSOCK)
198 # define sclose(x) lwip_close((x))
200 # define sclose(x) close((x))
204 * Stack-independent version of fcntl() on sockets:
206 #if defined(USE_LWIPSOCK)
207 # define sfcntl lwip_fcntl
209 # define sfcntl fcntl
213 * 'bool' stuff compatible with HP-UX headers.
216 #if defined(__hpux) && !defined(HAVE_BOOL_T)
225 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
226 * On non-C99 platforms there's no bool, so define an enum for that.
227 * On C99 platforms 'false' and 'true' also exist. Enum uses a
228 * global namespace though, so use bool_false and bool_true.
238 * Use a define to let 'true' and 'false' use those enums. There
239 * are currently no use of true and false in libcurl proper, but
240 * there are some in the examples. This will cater for any later
241 * code happening to use true and false.
243 # define false bool_false
244 # define true bool_true
248 /* the type we use for storing a single boolean bit */
251 #define BIT(x) bool x
253 typedef unsigned int bit;
254 #define BIT(x) bit x:1
258 * Redefine TRUE and FALSE too, to catch current use. With this
259 * change, 'bool found = 1' will give a warning on MIPSPro, but
260 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
261 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
271 #include "curl_ctype.h"
275 * Macro used to include code only in debug builds.
281 #define DEBUGF(x) do { } while(0)
286 * Macro used to include assertion code only in debug builds.
290 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
291 #define DEBUGASSERT(x) assert(x)
293 #define DEBUGASSERT(x) do { } while(0)
298 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
299 * (or equivalent) on this platform to hide platform details to code using it.
303 #define SOCKERRNO ((int)WSAGetLastError())
304 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
306 #define SOCKERRNO (errno)
307 #define SET_SOCKERRNO(x) (errno = (x))
312 * Portable error number symbolic names defined to Winsock error codes.
316 #undef EBADF /* override definition in errno.h */
317 #define EBADF WSAEBADF
318 #undef EINTR /* override definition in errno.h */
319 #define EINTR WSAEINTR
320 #undef EINVAL /* override definition in errno.h */
321 #define EINVAL WSAEINVAL
322 #undef EWOULDBLOCK /* override definition in errno.h */
323 #define EWOULDBLOCK WSAEWOULDBLOCK
324 #undef EINPROGRESS /* override definition in errno.h */
325 #define EINPROGRESS WSAEINPROGRESS
326 #undef EALREADY /* override definition in errno.h */
327 #define EALREADY WSAEALREADY
328 #undef ENOTSOCK /* override definition in errno.h */
329 #define ENOTSOCK WSAENOTSOCK
330 #undef EDESTADDRREQ /* override definition in errno.h */
331 #define EDESTADDRREQ WSAEDESTADDRREQ
332 #undef EMSGSIZE /* override definition in errno.h */
333 #define EMSGSIZE WSAEMSGSIZE
334 #undef EPROTOTYPE /* override definition in errno.h */
335 #define EPROTOTYPE WSAEPROTOTYPE
336 #undef ENOPROTOOPT /* override definition in errno.h */
337 #define ENOPROTOOPT WSAENOPROTOOPT
338 #undef EPROTONOSUPPORT /* override definition in errno.h */
339 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
340 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
341 #undef EOPNOTSUPP /* override definition in errno.h */
342 #define EOPNOTSUPP WSAEOPNOTSUPP
343 #define EPFNOSUPPORT WSAEPFNOSUPPORT
344 #undef EAFNOSUPPORT /* override definition in errno.h */
345 #define EAFNOSUPPORT WSAEAFNOSUPPORT
346 #undef EADDRINUSE /* override definition in errno.h */
347 #define EADDRINUSE WSAEADDRINUSE
348 #undef EADDRNOTAVAIL /* override definition in errno.h */
349 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
350 #undef ENETDOWN /* override definition in errno.h */
351 #define ENETDOWN WSAENETDOWN
352 #undef ENETUNREACH /* override definition in errno.h */
353 #define ENETUNREACH WSAENETUNREACH
354 #undef ENETRESET /* override definition in errno.h */
355 #define ENETRESET WSAENETRESET
356 #undef ECONNABORTED /* override definition in errno.h */
357 #define ECONNABORTED WSAECONNABORTED
358 #undef ECONNRESET /* override definition in errno.h */
359 #define ECONNRESET WSAECONNRESET
360 #undef ENOBUFS /* override definition in errno.h */
361 #define ENOBUFS WSAENOBUFS
362 #undef EISCONN /* override definition in errno.h */
363 #define EISCONN WSAEISCONN
364 #undef ENOTCONN /* override definition in errno.h */
365 #define ENOTCONN WSAENOTCONN
366 #define ESHUTDOWN WSAESHUTDOWN
367 #define ETOOMANYREFS WSAETOOMANYREFS
368 #undef ETIMEDOUT /* override definition in errno.h */
369 #define ETIMEDOUT WSAETIMEDOUT
370 #undef ECONNREFUSED /* override definition in errno.h */
371 #define ECONNREFUSED WSAECONNREFUSED
372 #undef ELOOP /* override definition in errno.h */
373 #define ELOOP WSAELOOP
374 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
375 #define ENAMETOOLONG WSAENAMETOOLONG
377 #define EHOSTDOWN WSAEHOSTDOWN
378 #undef EHOSTUNREACH /* override definition in errno.h */
379 #define EHOSTUNREACH WSAEHOSTUNREACH
380 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
381 #define ENOTEMPTY WSAENOTEMPTY
383 #define EPROCLIM WSAEPROCLIM
384 #define EUSERS WSAEUSERS
385 #define EDQUOT WSAEDQUOT
386 #define ESTALE WSAESTALE
387 #define EREMOTE WSAEREMOTE
391 * Macro argv_item_t hides platform details to code using it.
395 #define argv_item_t __char_ptr32
396 #elif defined(_UNICODE)
397 #define argv_item_t wchar_t *
399 #define argv_item_t char *
404 * We use this ZERO_NULL to avoid picky compiler warnings,
405 * when assigning a NULL pointer to a function pointer var.
411 #endif /* HEADER_CURL_SETUP_ONCE_H */