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