Debian Codegraph @

deps/curl/lib/curl_setup_once.h

raw
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) 1998 - 2019, Daniel Stenberg, <[email protected]>, 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.haxx.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 ***************************************************************************/
24
25
26 /*
27 * Inclusion of common header files.
28 */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdarg.h>
34 #include <ctype.h>
35
36 #ifdef HAVE_ERRNO_H
37 #include <errno.h>
38 #endif
39
40 #ifdef HAVE_SYS_TYPES_H
41 #include <sys/types.h>
42 #endif
43
44 #ifdef NEED_MALLOC_H
45 #include <malloc.h>
46 #endif
47
48 #ifdef NEED_MEMORY_H
49 #include <memory.h>
50 #endif
51
52 #ifdef HAVE_SYS_STAT_H
53 #include <sys/stat.h>
54 #endif
55
56 #ifdef HAVE_SYS_TIME_H
57 #include <sys/time.h>
58 #ifdef TIME_WITH_SYS_TIME
59 #include <time.h>
60 #endif
61 #else
62 #ifdef HAVE_TIME_H
63 #include <time.h>
64 #endif
65 #endif
66
67 #ifdef WIN32
68 #include <io.h>
69 #include <fcntl.h>
70 #endif
71
72 #if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T)
73 #include <stdbool.h>
74 #endif
75
76 #ifdef HAVE_UNISTD_H
77 #include <unistd.h>
78 #endif
79
80 #ifdef __hpux
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
85 # else
86 # undef OLD_APP32_64BIT_OFF_T
87 # endif
88 # endif
89 #endif
90
91 #ifdef HAVE_SYS_SOCKET_H
92 #include <sys/socket.h>
93 #endif
94
95 #ifdef __hpux
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
100 # endif
101 # endif
102 #endif
103
104 /*
105 * Definition of timeval struct for platforms that don't have it.
106 */
107
108 #ifndef HAVE_STRUCT_TIMEVAL
109 struct timeval {
110 long tv_sec;
111 long tv_usec;
112 };
113 #endif
114
115
116 /*
117 * If we have the MSG_NOSIGNAL define, make sure we use
118 * it as the fourth argument of function send()
119 */
120
121 #ifdef HAVE_MSG_NOSIGNAL
122 #define SEND_4TH_ARG MSG_NOSIGNAL
123 #else
124 #define SEND_4TH_ARG 0
125 #endif
126
127
128 #if defined(__minix)
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), \
132 (RECV_TYPE_ARG3)(z))
133
134 #elif defined(HAVE_RECV)
135 /*
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.
139 *
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.
143 *
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
146 * be defined.
147 *
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.
151 *
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.
155 */
156
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)
162 /* */
163 Error Missing_definition_of_return_and_arguments_types_of_recv
164 /* */
165 #else
166 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
167 (RECV_TYPE_ARG2)(y), \
168 (RECV_TYPE_ARG3)(z), \
169 (RECV_TYPE_ARG4)(0))
170 #endif
171 #else /* HAVE_RECV */
172 #ifndef sread
173 /* */
174 Error Missing_definition_of_macro_sread
175 /* */
176 #endif
177 #endif /* HAVE_RECV */
178
179
180 #if defined(__minix)
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), \
184 (SEND_TYPE_ARG3)(z))
185
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)
193 /* */
194 Error Missing_definition_of_return_and_arguments_types_of_send
195 /* */
196 #else
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))
201 #endif
202 #else /* HAVE_SEND */
203 #ifndef swrite
204 /* */
205 Error Missing_definition_of_macro_swrite
206 /* */
207 #endif
208 #endif /* HAVE_SEND */
209
210
211 #if 0
212 #if defined(HAVE_RECVFROM)
213 /*
214 * Currently recvfrom is only used on udp sockets.
215 */
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)
223 /* */
224 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
225 /* */
226 #else
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))
233 #endif
234 #else /* HAVE_RECVFROM */
235 #ifndef sreadfrom
236 /* */
237 Error Missing_definition_of_macro_sreadfrom
238 /* */
239 #endif
240 #endif /* HAVE_RECVFROM */
241
242
243 #ifdef RECVFROM_TYPE_ARG6_IS_VOID
244 # define RECVFROM_ARG6_T int
245 #else
246 # define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
247 #endif
248 #endif /* if 0 */
249
250
251 /*
252 * Function-like macro definition used to close a socket.
253 */
254
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))
263 #else
264 # define sclose(x) close((x))
265 #endif
266
267 /*
268 * Stack-independent version of fcntl() on sockets:
269 */
270 #if defined(USE_LWIPSOCK)
271 # define sfcntl lwip_fcntl
272 #else
273 # define sfcntl fcntl
274 #endif
275
276 #define TOLOWER(x) (tolower((int) ((unsigned char)x)))
277
278
279 /*
280 * 'bool' stuff compatible with HP-UX headers.
281 */
282
283 #if defined(__hpux) && !defined(HAVE_BOOL_T)
284 typedef int bool;
285 # define false 0
286 # define true 1
287 # define HAVE_BOOL_T
288 #endif
289
290
291 /*
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.
296 */
297
298 #ifndef HAVE_BOOL_T
299 typedef enum {
300 bool_false = 0,
301 bool_true = 1
302 } bool;
303
304 /*
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.
309 */
310 # define false bool_false
311 # define true bool_true
312 # define HAVE_BOOL_T
313 #endif
314
315
316 /*
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.
321 */
322
323 #ifndef TRUE
324 #define TRUE true
325 #endif
326 #ifndef FALSE
327 #define FALSE false
328 #endif
329
330 #include "curl_ctype.h"
331
332 /*
333 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
334 */
335
336 #ifndef HAVE_SIG_ATOMIC_T
337 typedef int sig_atomic_t;
338 #define HAVE_SIG_ATOMIC_T
339 #endif
340
341
342 /*
343 * Convenience SIG_ATOMIC_T definition
344 */
345
346 #ifdef HAVE_SIG_ATOMIC_T_VOLATILE
347 #define SIG_ATOMIC_T static sig_atomic_t
348 #else
349 #define SIG_ATOMIC_T static volatile sig_atomic_t
350 #endif
351
352
353 /*
354 * Default return type for signal handlers.
355 */
356
357 #ifndef RETSIGTYPE
358 #define RETSIGTYPE void
359 #endif
360
361
362 /*
363 * Macro used to include code only in debug builds.
364 */
365
366 #ifdef DEBUGBUILD
367 #define DEBUGF(x) x
368 #else
369 #define DEBUGF(x) do { } while(0)
370 #endif
371
372
373 /*
374 * Macro used to include assertion code only in debug builds.
375 */
376
377 #undef DEBUGASSERT
378 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
379 #define DEBUGASSERT(x) assert(x)
380 #else
381 #define DEBUGASSERT(x) do { } while(0)
382 #endif
383
384
385 /*
386 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
387 * (or equivalent) on this platform to hide platform details to code using it.
388 */
389
390 #ifdef USE_WINSOCK
391 #define SOCKERRNO ((int)WSAGetLastError())
392 #define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
393 #else
394 #define SOCKERRNO (errno)
395 #define SET_SOCKERRNO(x) (errno = (x))
396 #endif
397
398
399 /*
400 * Portable error number symbolic names defined to Winsock error codes.
401 */
402
403 #ifdef USE_WINSOCK
404 #undef EBADF /* override definition in errno.h */
405 #define EBADF WSAEBADF
406 #undef EINTR /* override definition in errno.h */
407 #define EINTR WSAEINTR
408 #undef EINVAL /* override definition in errno.h */
409 #define EINVAL WSAEINVAL
410 #undef EWOULDBLOCK /* override definition in errno.h */
411 #define EWOULDBLOCK WSAEWOULDBLOCK
412 #undef EINPROGRESS /* override definition in errno.h */
413 #define EINPROGRESS WSAEINPROGRESS
414 #undef EALREADY /* override definition in errno.h */
415 #define EALREADY WSAEALREADY
416 #undef ENOTSOCK /* override definition in errno.h */
417 #define ENOTSOCK WSAENOTSOCK
418 #undef EDESTADDRREQ /* override definition in errno.h */
419 #define EDESTADDRREQ WSAEDESTADDRREQ
420 #undef EMSGSIZE /* override definition in errno.h */
421 #define EMSGSIZE WSAEMSGSIZE
422 #undef EPROTOTYPE /* override definition in errno.h */
423 #define EPROTOTYPE WSAEPROTOTYPE
424 #undef ENOPROTOOPT /* override definition in errno.h */
425 #define ENOPROTOOPT WSAENOPROTOOPT
426 #undef EPROTONOSUPPORT /* override definition in errno.h */
427 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
428 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
429 #undef EOPNOTSUPP /* override definition in errno.h */
430 #define EOPNOTSUPP WSAEOPNOTSUPP
431 #define EPFNOSUPPORT WSAEPFNOSUPPORT
432 #undef EAFNOSUPPORT /* override definition in errno.h */
433 #define EAFNOSUPPORT WSAEAFNOSUPPORT
434 #undef EADDRINUSE /* override definition in errno.h */
435 #define EADDRINUSE WSAEADDRINUSE
436 #undef EADDRNOTAVAIL /* override definition in errno.h */
437 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
438 #undef ENETDOWN /* override definition in errno.h */
439 #define ENETDOWN WSAENETDOWN
440 #undef ENETUNREACH /* override definition in errno.h */
441 #define ENETUNREACH WSAENETUNREACH
442 #undef ENETRESET /* override definition in errno.h */
443 #define ENETRESET WSAENETRESET
444 #undef ECONNABORTED /* override definition in errno.h */
445 #define ECONNABORTED WSAECONNABORTED
446 #undef ECONNRESET /* override definition in errno.h */
447 #define ECONNRESET WSAECONNRESET
448 #undef ENOBUFS /* override definition in errno.h */
449 #define ENOBUFS WSAENOBUFS
450 #undef EISCONN /* override definition in errno.h */
451 #define EISCONN WSAEISCONN
452 #undef ENOTCONN /* override definition in errno.h */
453 #define ENOTCONN WSAENOTCONN
454 #define ESHUTDOWN WSAESHUTDOWN
455 #define ETOOMANYREFS WSAETOOMANYREFS
456 #undef ETIMEDOUT /* override definition in errno.h */
457 #define ETIMEDOUT WSAETIMEDOUT
458 #undef ECONNREFUSED /* override definition in errno.h */
459 #define ECONNREFUSED WSAECONNREFUSED
460 #undef ELOOP /* override definition in errno.h */
461 #define ELOOP WSAELOOP
462 #ifndef ENAMETOOLONG /* possible previous definition in errno.h */
463 #define ENAMETOOLONG WSAENAMETOOLONG
464 #endif
465 #define EHOSTDOWN WSAEHOSTDOWN
466 #undef EHOSTUNREACH /* override definition in errno.h */
467 #define EHOSTUNREACH WSAEHOSTUNREACH
468 #ifndef ENOTEMPTY /* possible previous definition in errno.h */
469 #define ENOTEMPTY WSAENOTEMPTY
470 #endif
471 #define EPROCLIM WSAEPROCLIM
472 #define EUSERS WSAEUSERS
473 #define EDQUOT WSAEDQUOT
474 #define ESTALE WSAESTALE
475 #define EREMOTE WSAEREMOTE
476 #endif
477
478 /*
479 * Macro argv_item_t hides platform details to code using it.
480 */
481
482 #ifdef __VMS
483 #define argv_item_t __char_ptr32
484 #else
485 #define argv_item_t char *
486 #endif
487
488
489 /*
490 * We use this ZERO_NULL to avoid picky compiler warnings,
491 * when assigning a NULL pointer to a function pointer var.
492 */
493
494 #define ZERO_NULL 0
495
496
497 #endif /* HEADER_CURL_SETUP_ONCE_H */