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