source: UsbWattMeter/trunk/curl-7.47.1/lib/curl_setup_once.h@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr
File size: 14.9 KB
RevLine 
[164]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 - 2013, 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.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/*
106 * Definition of timeval struct for platforms that don't have it.
107 */
108
109#ifndef HAVE_STRUCT_TIMEVAL
110struct timeval {
111 long tv_sec;
112 long tv_usec;
113};
114#endif
115
116
117/*
118 * If we have the MSG_NOSIGNAL define, make sure we use
119 * it as the fourth argument of function send()
120 */
121
122#ifdef HAVE_MSG_NOSIGNAL
123#define SEND_4TH_ARG MSG_NOSIGNAL
124#else
125#define SEND_4TH_ARG 0
126#endif
127
128
129#if defined(__minix)
130/* Minix doesn't support recv on TCP sockets */
131#define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
132 (RECV_TYPE_ARG2)(y), \
133 (RECV_TYPE_ARG3)(z))
134
135#elif defined(HAVE_RECV)
136/*
137 * The definitions for the return type and arguments types
138 * of functions recv() and send() belong and come from the
139 * configuration file. Do not define them in any other place.
140 *
141 * HAVE_RECV is defined if you have a function named recv()
142 * which is used to read incoming data from sockets. If your
143 * function has another name then don't define HAVE_RECV.
144 *
145 * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
146 * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
147 * be defined.
148 *
149 * HAVE_SEND is defined if you have a function named send()
150 * which is used to write outgoing data on a connected socket.
151 * If yours has another name then don't define HAVE_SEND.
152 *
153 * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
154 * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
155 * SEND_TYPE_RETV must also be defined.
156 */
157
158#if !defined(RECV_TYPE_ARG1) || \
159 !defined(RECV_TYPE_ARG2) || \
160 !defined(RECV_TYPE_ARG3) || \
161 !defined(RECV_TYPE_ARG4) || \
162 !defined(RECV_TYPE_RETV)
163 /* */
164 Error Missing_definition_of_return_and_arguments_types_of_recv
165 /* */
166#else
167#define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
168 (RECV_TYPE_ARG2)(y), \
169 (RECV_TYPE_ARG3)(z), \
170 (RECV_TYPE_ARG4)(0))
171#endif
172#else /* HAVE_RECV */
173#ifndef sread
174 /* */
175 Error Missing_definition_of_macro_sread
176 /* */
177#endif
178#endif /* HAVE_RECV */
179
180
181#if defined(__minix)
182/* Minix doesn't support send on TCP sockets */
183#define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \
184 (SEND_TYPE_ARG2)(y), \
185 (SEND_TYPE_ARG3)(z))
186
187#elif defined(HAVE_SEND)
188#if !defined(SEND_TYPE_ARG1) || \
189 !defined(SEND_QUAL_ARG2) || \
190 !defined(SEND_TYPE_ARG2) || \
191 !defined(SEND_TYPE_ARG3) || \
192 !defined(SEND_TYPE_ARG4) || \
193 !defined(SEND_TYPE_RETV)
194 /* */
195 Error Missing_definition_of_return_and_arguments_types_of_send
196 /* */
197#else
198#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
199 (SEND_TYPE_ARG2)(y), \
200 (SEND_TYPE_ARG3)(z), \
201 (SEND_TYPE_ARG4)(SEND_4TH_ARG))
202#endif
203#else /* HAVE_SEND */
204#ifndef swrite
205 /* */
206 Error Missing_definition_of_macro_swrite
207 /* */
208#endif
209#endif /* HAVE_SEND */
210
211
212#if 0
213#if defined(HAVE_RECVFROM)
214/*
215 * Currently recvfrom is only used on udp sockets.
216 */
217#if !defined(RECVFROM_TYPE_ARG1) || \
218 !defined(RECVFROM_TYPE_ARG2) || \
219 !defined(RECVFROM_TYPE_ARG3) || \
220 !defined(RECVFROM_TYPE_ARG4) || \
221 !defined(RECVFROM_TYPE_ARG5) || \
222 !defined(RECVFROM_TYPE_ARG6) || \
223 !defined(RECVFROM_TYPE_RETV)
224 /* */
225 Error Missing_definition_of_return_and_arguments_types_of_recvfrom
226 /* */
227#else
228#define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \
229 (RECVFROM_TYPE_ARG2 *)(b), \
230 (RECVFROM_TYPE_ARG3) (bl), \
231 (RECVFROM_TYPE_ARG4) (0), \
232 (RECVFROM_TYPE_ARG5 *)(f), \
233 (RECVFROM_TYPE_ARG6 *)(fl))
234#endif
235#else /* HAVE_RECVFROM */
236#ifndef sreadfrom
237 /* */
238 Error Missing_definition_of_macro_sreadfrom
239 /* */
240#endif
241#endif /* HAVE_RECVFROM */
242
243
244#ifdef RECVFROM_TYPE_ARG6_IS_VOID
245# define RECVFROM_ARG6_T int
246#else
247# define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6
248#endif
249#endif /* if 0 */
250
251
252/*
253 * Function-like macro definition used to close a socket.
254 */
255
256#if defined(HAVE_CLOSESOCKET)
257# define sclose(x) closesocket((x))
258#elif defined(HAVE_CLOSESOCKET_CAMEL)
259# define sclose(x) CloseSocket((x))
260#elif defined(HAVE_CLOSE_S)
261# define sclose(x) close_s((x))
262#elif defined(USE_LWIPSOCK)
263# define sclose(x) lwip_close((x))
264#else
265# define sclose(x) close((x))
266#endif
267
268/*
269 * Stack-independent version of fcntl() on sockets:
270 */
271#if defined(USE_LWIPSOCK)
272# define sfcntl lwip_fcntl
273#else
274# define sfcntl fcntl
275#endif
276
277/*
278 * Uppercase macro versions of ANSI/ISO is*() functions/macros which
279 * avoid negative number inputs with argument byte codes > 127.
280 */
281
282#define ISSPACE(x) (isspace((int) ((unsigned char)x)))
283#define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
284#define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
285#define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
286#define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
287#define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
288#define ISPRINT(x) (isprint((int) ((unsigned char)x)))
289#define ISUPPER(x) (isupper((int) ((unsigned char)x)))
290#define ISLOWER(x) (islower((int) ((unsigned char)x)))
291#define ISASCII(x) (isascii((int) ((unsigned char)x)))
292
293#define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
294 (((unsigned char)x) == '\t'))
295
296#define TOLOWER(x) (tolower((int) ((unsigned char)x)))
297
298
299/*
300 * 'bool' stuff compatible with HP-UX headers.
301 */
302
303#if defined(__hpux) && !defined(HAVE_BOOL_T)
304 typedef int bool;
305# define false 0
306# define true 1
307# define HAVE_BOOL_T
308#endif
309
310
311/*
312 * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
313 * On non-C99 platforms there's no bool, so define an enum for that.
314 * On C99 platforms 'false' and 'true' also exist. Enum uses a
315 * global namespace though, so use bool_false and bool_true.
316 */
317
318#ifndef HAVE_BOOL_T
319 typedef enum {
320 bool_false = 0,
321 bool_true = 1
322 } bool;
323
324/*
325 * Use a define to let 'true' and 'false' use those enums. There
326 * are currently no use of true and false in libcurl proper, but
327 * there are some in the examples. This will cater for any later
328 * code happening to use true and false.
329 */
330# define false bool_false
331# define true bool_true
332# define HAVE_BOOL_T
333#endif
334
335
336/*
337 * Redefine TRUE and FALSE too, to catch current use. With this
338 * change, 'bool found = 1' will give a warning on MIPSPro, but
339 * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
340 * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
341 */
342
343#ifndef TRUE
344#define TRUE true
345#endif
346#ifndef FALSE
347#define FALSE false
348#endif
349
350
351/*
352 * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
353 * avoiding compiler warnings. Mostly intended for other macro definitions.
354 */
355
356#define WHILE_FALSE while(0)
357
358#if defined(_MSC_VER) && !defined(__POCC__)
359# undef WHILE_FALSE
360# if (_MSC_VER < 1500)
361# define WHILE_FALSE while(1, 0)
362# else
363# define WHILE_FALSE \
364__pragma(warning(push)) \
365__pragma(warning(disable:4127)) \
366while(0) \
367__pragma(warning(pop))
368# endif
369#endif
370
371
372/*
373 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
374 */
375
376#ifndef HAVE_SIG_ATOMIC_T
377typedef int sig_atomic_t;
378#define HAVE_SIG_ATOMIC_T
379#endif
380
381
382/*
383 * Convenience SIG_ATOMIC_T definition
384 */
385
386#ifdef HAVE_SIG_ATOMIC_T_VOLATILE
387#define SIG_ATOMIC_T static sig_atomic_t
388#else
389#define SIG_ATOMIC_T static volatile sig_atomic_t
390#endif
391
392
393/*
394 * Default return type for signal handlers.
395 */
396
397#ifndef RETSIGTYPE
398#define RETSIGTYPE void
399#endif
400
401
402/*
403 * Macro used to include code only in debug builds.
404 */
405
406#ifdef DEBUGBUILD
407#define DEBUGF(x) x
408#else
409#define DEBUGF(x) do { } WHILE_FALSE
410#endif
411
412
413/*
414 * Macro used to include assertion code only in debug builds.
415 */
416
417#if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
418#define DEBUGASSERT(x) assert(x)
419#else
420#define DEBUGASSERT(x) do { } WHILE_FALSE
421#endif
422
423
424/*
425 * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
426 * (or equivalent) on this platform to hide platform details to code using it.
427 */
428
429#ifdef USE_WINSOCK
430#define SOCKERRNO ((int)WSAGetLastError())
431#define SET_SOCKERRNO(x) (WSASetLastError((int)(x)))
432#else
433#define SOCKERRNO (errno)
434#define SET_SOCKERRNO(x) (errno = (x))
435#endif
436
437
438/*
439 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
440 * (or equivalent) on this platform to hide platform details to code using it.
441 */
442
443#if defined(WIN32) && !defined(USE_LWIPSOCK)
444#define ERRNO ((int)GetLastError())
445#define SET_ERRNO(x) (SetLastError((DWORD)(x)))
446#else
447#ifndef ERRNO
448#define ERRNO (errno)
449#endif // !ERRNO
450#define SET_ERRNO(x) (errno = (x))
451#endif
452
453
454/*
455 * Portable error number symbolic names defined to Winsock error codes.
456 */
457
458#ifdef USE_WINSOCK
459#undef EBADF /* override definition in errno.h */
460#define EBADF WSAEBADF
461#undef EINTR /* override definition in errno.h */
462#define EINTR WSAEINTR
463#undef EINVAL /* override definition in errno.h */
464#define EINVAL WSAEINVAL
465#undef EWOULDBLOCK /* override definition in errno.h */
466#define EWOULDBLOCK WSAEWOULDBLOCK
467#undef EINPROGRESS /* override definition in errno.h */
468#define EINPROGRESS WSAEINPROGRESS
469#undef EALREADY /* override definition in errno.h */
470#define EALREADY WSAEALREADY
471#undef ENOTSOCK /* override definition in errno.h */
472#define ENOTSOCK WSAENOTSOCK
473#undef EDESTADDRREQ /* override definition in errno.h */
474#define EDESTADDRREQ WSAEDESTADDRREQ
475#undef EMSGSIZE /* override definition in errno.h */
476#define EMSGSIZE WSAEMSGSIZE
477#undef EPROTOTYPE /* override definition in errno.h */
478#define EPROTOTYPE WSAEPROTOTYPE
479#undef ENOPROTOOPT /* override definition in errno.h */
480#define ENOPROTOOPT WSAENOPROTOOPT
481#undef EPROTONOSUPPORT /* override definition in errno.h */
482#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
483#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
484#undef EOPNOTSUPP /* override definition in errno.h */
485#define EOPNOTSUPP WSAEOPNOTSUPP
486#define EPFNOSUPPORT WSAEPFNOSUPPORT
487#undef EAFNOSUPPORT /* override definition in errno.h */
488#define EAFNOSUPPORT WSAEAFNOSUPPORT
489#undef EADDRINUSE /* override definition in errno.h */
490#define EADDRINUSE WSAEADDRINUSE
491#undef EADDRNOTAVAIL /* override definition in errno.h */
492#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
493#undef ENETDOWN /* override definition in errno.h */
494#define ENETDOWN WSAENETDOWN
495#undef ENETUNREACH /* override definition in errno.h */
496#define ENETUNREACH WSAENETUNREACH
497#undef ENETRESET /* override definition in errno.h */
498#define ENETRESET WSAENETRESET
499#undef ECONNABORTED /* override definition in errno.h */
500#define ECONNABORTED WSAECONNABORTED
501#undef ECONNRESET /* override definition in errno.h */
502#define ECONNRESET WSAECONNRESET
503#undef ENOBUFS /* override definition in errno.h */
504#define ENOBUFS WSAENOBUFS
505#undef EISCONN /* override definition in errno.h */
506#define EISCONN WSAEISCONN
507#undef ENOTCONN /* override definition in errno.h */
508#define ENOTCONN WSAENOTCONN
509#define ESHUTDOWN WSAESHUTDOWN
510#define ETOOMANYREFS WSAETOOMANYREFS
511#undef ETIMEDOUT /* override definition in errno.h */
512#define ETIMEDOUT WSAETIMEDOUT
513#undef ECONNREFUSED /* override definition in errno.h */
514#define ECONNREFUSED WSAECONNREFUSED
515#undef ELOOP /* override definition in errno.h */
516#define ELOOP WSAELOOP
517#ifndef ENAMETOOLONG /* possible previous definition in errno.h */
518#define ENAMETOOLONG WSAENAMETOOLONG
519#endif
520#define EHOSTDOWN WSAEHOSTDOWN
521#undef EHOSTUNREACH /* override definition in errno.h */
522#define EHOSTUNREACH WSAEHOSTUNREACH
523#ifndef ENOTEMPTY /* possible previous definition in errno.h */
524#define ENOTEMPTY WSAENOTEMPTY
525#endif
526#define EPROCLIM WSAEPROCLIM
527#define EUSERS WSAEUSERS
528#define EDQUOT WSAEDQUOT
529#define ESTALE WSAESTALE
530#define EREMOTE WSAEREMOTE
531#endif
532
533/*
534 * Macro argv_item_t hides platform details to code using it.
535 */
536
537#ifdef __VMS
538#define argv_item_t __char_ptr32
539#else
540#define argv_item_t char *
541#endif
542
543
544/*
545 * We use this ZERO_NULL to avoid picky compiler warnings,
546 * when assigning a NULL pointer to a function pointer var.
547 */
548
549#define ZERO_NULL 0
550
551
552#endif /* HEADER_CURL_SETUP_ONCE_H */
553
Note: See TracBrowser for help on using the repository browser.