1 #ifndef HEADER_CURL_SETUP_ONCE_H 2 #define HEADER_CURL_SETUP_ONCE_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 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. 15 * 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. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 * SPDX-License-Identifier: curl 24 * 25 ***************************************************************************/ 26 27 28 /* 29 * Inclusion of common header files. 30 */ 31 32 #include <stdio.h> 33 #include <stdlib.h> 34 #include <string.h> 35 #include <stdarg.h> 36 #include <time.h> 37 #include <errno.h> 38 39 #ifdef HAVE_SYS_TYPES_H 40 #include <sys/types.h> 41 #endif 42 43 #ifdef HAVE_SYS_STAT_H 44 #include <sys/stat.h> 45 #endif 46 47 #ifdef HAVE_SYS_TIME_H 48 #include <sys/time.h> 49 #endif 50 51 #ifdef HAVE_IO_H 52 #include <io.h> 53 #endif 54 55 #ifdef HAVE_FCNTL_H 56 #include <fcntl.h> 57 #endif 58 59 #if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T) 60 #include <stdbool.h> 61 #endif 62 63 #ifdef HAVE_UNISTD_H 64 #include <unistd.h> 65 #endif 66 67 #ifdef USE_WOLFSSL 68 #include <stdint.h> 69 #endif 70 71 #ifdef USE_SCHANNEL 72 /* Must set this before <schannel.h> is included directly or indirectly by 73 another Windows header. */ 74 # define SCHANNEL_USE_BLACKLISTS 1 75 #endif 76 77 #ifdef __hpux 78 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) 79 # ifdef _APP32_64BIT_OFF_T 80 # define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T 81 # undef _APP32_64BIT_OFF_T 82 # else 83 # undef OLD_APP32_64BIT_OFF_T 84 # endif 85 # endif 86 #endif 87 88 #ifdef HAVE_SYS_SOCKET_H 89 #include <sys/socket.h> 90 #endif 91 92 #include "functypes.h" 93 94 #ifdef __hpux 95 # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) 96 # ifdef OLD_APP32_64BIT_OFF_T 97 # define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T 98 # undef OLD_APP32_64BIT_OFF_T 99 # endif 100 # endif 101 #endif 102 103 /* 104 * Definition of timeval struct for platforms that do not have it. 105 */ 106 107 #ifndef HAVE_STRUCT_TIMEVAL 108 struct timeval { 109 long tv_sec; 110 long tv_usec; 111 }; 112 #endif 113 114 115 /* 116 * If we have the MSG_NOSIGNAL define, make sure we use 117 * it as the fourth argument of function send() 118 */ 119 120 #ifdef HAVE_MSG_NOSIGNAL 121 #define SEND_4TH_ARG MSG_NOSIGNAL 122 #else 123 #define SEND_4TH_ARG 0 124 #endif 125 126 127 #if defined(__minix) 128 /* Minix does not support recv on TCP sockets */ 129 #define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \ 130 (RECV_TYPE_ARG2)(y), \ 131 (RECV_TYPE_ARG3)(z)) 132 133 #elif defined(HAVE_RECV) 134 /* 135 * The definitions for the return type and arguments types 136 * of functions recv() and send() belong and come from the 137 * configuration file. Do not define them in any other place. 138 * 139 * HAVE_RECV is defined if you have a function named recv() 140 * which is used to read incoming data from sockets. If your 141 * function has another name then do not define HAVE_RECV. 142 * 143 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2, 144 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also 145 * be defined. 146 * 147 * HAVE_SEND is defined if you have a function named send() 148 * which is used to write outgoing data on a connected socket. 149 * If yours has another name then do not define HAVE_SEND. 150 * 151 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2, 152 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and 153 * SEND_TYPE_RETV must also be defined. 154 */ 155 156 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \ 157 (RECV_TYPE_ARG2)(y), \ 158 (RECV_TYPE_ARG3)(z), \ 159 (RECV_TYPE_ARG4)(0)) 160 #else /* HAVE_RECV */ 161 #ifndef sread 162 #error "Missing definition of macro sread!" 163 #endif 164 #endif /* HAVE_RECV */ 165 166 167 #if defined(__minix) 168 /* Minix does not support send on TCP sockets */ 169 #define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \ 170 (SEND_TYPE_ARG2)(y), \ 171 (SEND_TYPE_ARG3)(z)) 172 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 */ 179 #ifndef swrite 180 #error "Missing definition of macro swrite!" 181 #endif 182 #endif /* HAVE_SEND */ 183 184 185 /* 186 * Function-like macro definition used to close a socket. 187 */ 188 189 #if defined(HAVE_CLOSESOCKET) 190 # define sclose(x) closesocket((x)) 191 #elif defined(HAVE_CLOSESOCKET_CAMEL) 192 # define sclose(x) CloseSocket((x)) 193 #elif defined(MSDOS) /* Watt-32 */ 194 # define sclose(x) close_s((x)) 195 #elif defined(USE_LWIPSOCK) 196 # define sclose(x) lwip_close((x)) 197 #else 198 # define sclose(x) close((x)) 199 #endif 200 201 /* 202 * Stack-independent version of fcntl() on sockets: 203 */ 204 #if defined(USE_LWIPSOCK) 205 # define sfcntl lwip_fcntl 206 #else 207 # define sfcntl fcntl 208 #endif 209 210 /* 211 * 'bool' stuff compatible with HP-UX headers. 212 */ 213 214 #if defined(__hpux) && !defined(HAVE_BOOL_T) 215 typedef int bool; 216 # define false 0 217 # define true 1 218 # define HAVE_BOOL_T 219 #endif 220 221 222 /* 223 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms. 224 * On non-C99 platforms there is no bool, so define an enum for that. 225 * On C99 platforms 'false' and 'true' also exist. Enum uses a 226 * global namespace though, so use bool_false and bool_true. 227 */ 228 229 #ifndef HAVE_BOOL_T 230 typedef enum { 231 bool_false = 0, 232 bool_true = 1 233 } bool; 234 235 /* 236 * Use a define to let 'true' and 'false' use those enums. There 237 * are currently no use of true and false in libcurl proper, but 238 * there are some in the examples. This will cater for any later 239 * code happening to use true and false. 240 */ 241 # define false bool_false 242 # define true bool_true 243 # define HAVE_BOOL_T 244 #endif 245 246 /* the type we use for storing a single boolean bit */ 247 #ifdef _MSC_VER 248 typedef bool bit; 249 #define BIT(x) bool x 250 #else 251 typedef unsigned int bit; 252 #define BIT(x) bit x:1 253 #endif 254 255 /* 256 * Redefine TRUE and FALSE too, to catch current use. With this 257 * change, 'bool found = 1' will give a warning on MIPSPro, but 258 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro, 259 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too. 260 */ 261 262 #ifndef TRUE 263 #define TRUE true 264 #endif 265 #ifndef FALSE 266 #define FALSE false 267 #endif 268 269 #include "curl_ctype.h" 270 271 272 /* 273 * Macro used to include code only in debug builds. 274 */ 275 276 #ifdef DEBUGBUILD 277 #define DEBUGF(x) x 278 #else 279 #define DEBUGF(x) do { } while(0) 280 #endif 281 282 283 /* 284 * Macro used to include assertion code only in debug builds. 285 */ 286 287 #undef DEBUGASSERT 288 #if defined(DEBUGBUILD) 289 #define DEBUGASSERT(x) assert(x) 290 #else 291 #define DEBUGASSERT(x) do { } while(0) 292 #endif 293 294 295 /* 296 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno 297 * (or equivalent) on this platform to hide platform details to code using it. 298 */ 299 300 #ifdef USE_WINSOCK 301 #define SOCKERRNO ((int)WSAGetLastError()) 302 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) 303 #else 304 #define SOCKERRNO (errno) 305 #define SET_SOCKERRNO(x) (errno = (x)) 306 #endif 307 308 309 /* 310 * Portable error number symbolic names defined to Winsock error codes. 311 */ 312 313 #ifdef USE_WINSOCK 314 #undef EBADF /* override definition in errno.h */ 315 #define EBADF WSAEBADF 316 #undef EINTR /* override definition in errno.h */ 317 #define EINTR WSAEINTR 318 #undef EINVAL /* override definition in errno.h */ 319 #define EINVAL WSAEINVAL 320 #undef EWOULDBLOCK /* override definition in errno.h */ 321 #define EWOULDBLOCK WSAEWOULDBLOCK 322 #undef EINPROGRESS /* override definition in errno.h */ 323 #define EINPROGRESS WSAEINPROGRESS 324 #undef EALREADY /* override definition in errno.h */ 325 #define EALREADY WSAEALREADY 326 #undef ENOTSOCK /* override definition in errno.h */ 327 #define ENOTSOCK WSAENOTSOCK 328 #undef EDESTADDRREQ /* override definition in errno.h */ 329 #define EDESTADDRREQ WSAEDESTADDRREQ 330 #undef EMSGSIZE /* override definition in errno.h */ 331 #define EMSGSIZE WSAEMSGSIZE 332 #undef EPROTOTYPE /* override definition in errno.h */ 333 #define EPROTOTYPE WSAEPROTOTYPE 334 #undef ENOPROTOOPT /* override definition in errno.h */ 335 #define ENOPROTOOPT WSAENOPROTOOPT 336 #undef EPROTONOSUPPORT /* override definition in errno.h */ 337 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 338 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 339 #undef EOPNOTSUPP /* override definition in errno.h */ 340 #define EOPNOTSUPP WSAEOPNOTSUPP 341 #define EPFNOSUPPORT WSAEPFNOSUPPORT 342 #undef EAFNOSUPPORT /* override definition in errno.h */ 343 #define EAFNOSUPPORT WSAEAFNOSUPPORT 344 #undef EADDRINUSE /* override definition in errno.h */ 345 #define EADDRINUSE WSAEADDRINUSE 346 #undef EADDRNOTAVAIL /* override definition in errno.h */ 347 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 348 #undef ENETDOWN /* override definition in errno.h */ 349 #define ENETDOWN WSAENETDOWN 350 #undef ENETUNREACH /* override definition in errno.h */ 351 #define ENETUNREACH WSAENETUNREACH 352 #undef ENETRESET /* override definition in errno.h */ 353 #define ENETRESET WSAENETRESET 354 #undef ECONNABORTED /* override definition in errno.h */ 355 #define ECONNABORTED WSAECONNABORTED 356 #undef ECONNRESET /* override definition in errno.h */ 357 #define ECONNRESET WSAECONNRESET 358 #undef ENOBUFS /* override definition in errno.h */ 359 #define ENOBUFS WSAENOBUFS 360 #undef EISCONN /* override definition in errno.h */ 361 #define EISCONN WSAEISCONN 362 #undef ENOTCONN /* override definition in errno.h */ 363 #define ENOTCONN WSAENOTCONN 364 #define ESHUTDOWN WSAESHUTDOWN 365 #define ETOOMANYREFS WSAETOOMANYREFS 366 #undef ETIMEDOUT /* override definition in errno.h */ 367 #define ETIMEDOUT WSAETIMEDOUT 368 #undef ECONNREFUSED /* override definition in errno.h */ 369 #define ECONNREFUSED WSAECONNREFUSED 370 #undef ELOOP /* override definition in errno.h */ 371 #define ELOOP WSAELOOP 372 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */ 373 #define ENAMETOOLONG WSAENAMETOOLONG 374 #endif 375 #define EHOSTDOWN WSAEHOSTDOWN 376 #undef EHOSTUNREACH /* override definition in errno.h */ 377 #define EHOSTUNREACH WSAEHOSTUNREACH 378 #ifndef ENOTEMPTY /* possible previous definition in errno.h */ 379 #define ENOTEMPTY WSAENOTEMPTY 380 #endif 381 #define EPROCLIM WSAEPROCLIM 382 #define EUSERS WSAEUSERS 383 #define EDQUOT WSAEDQUOT 384 #define ESTALE WSAESTALE 385 #define EREMOTE WSAEREMOTE 386 #endif 387 388 /* 389 * Macro argv_item_t hides platform details to code using it. 390 */ 391 392 #ifdef __VMS 393 #define argv_item_t __char_ptr32 394 #elif defined(_UNICODE) 395 #define argv_item_t wchar_t * 396 #else 397 #define argv_item_t char * 398 #endif 399 400 401 /* 402 * We use this ZERO_NULL to avoid picky compiler warnings, 403 * when assigning a NULL pointer to a function pointer var. 404 */ 405 406 #define ZERO_NULL 0 407 408 409 #endif /* HEADER_CURL_SETUP_ONCE_H */ 410