fix ENAMETOOLONG and ENOTEMPTY may already be defined in errno.h
[platform/upstream/c-ares.git] / setup_once.h
1 #ifndef __SETUP_ONCE_H
2 #define __SETUP_ONCE_H
3
4 /* $Id$ */
5
6 /* Copyright (C) 2004 - 2007 by Daniel Stenberg et al
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose and without fee is hereby granted, provided
10  * that the above copyright notice appear in all copies and that both that
11  * copyright notice and this permission notice appear in supporting
12  * documentation, and that the name of M.I.T. not be used in advertising or
13  * publicity pertaining to distribution of the software without specific,
14  * written prior permission.  M.I.T. makes no representations about the
15  * suitability of this software for any purpose.  It is provided "as is"
16  * without express or implied warranty.
17  */
18
19
20 /********************************************************************
21  *                              NOTICE                              *
22  *                             ========                             *
23  *                                                                  *
24  *  Content of header files lib/setup_once.h and ares/setup_once.h  *
25  *  must be kept in sync. Modify the other one if you change this.  *
26  *                                                                  *
27  ********************************************************************/
28
29
30 /*
31  * Inclusion of common header files.
32  */
33
34 #include <errno.h>
35
36
37 /*
38  * If we have the MSG_NOSIGNAL define, make sure we use
39  * it as the fourth argument of function send()
40  */
41
42 #ifdef HAVE_MSG_NOSIGNAL
43 #define SEND_4TH_ARG MSG_NOSIGNAL
44 #else
45 #define SEND_4TH_ARG 0
46 #endif 
47
48
49 /*
50  * The definitions for the return type and arguments types
51  * of functions recv() and send() belong and come from the
52  * configuration file. Do not define them in any other place.
53  *
54  * HAVE_RECV is defined if you have a function named recv()
55  * which is used to read incoming data from sockets. If your
56  * function has another name then don't define HAVE_RECV.
57  *
58  * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2,
59  * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also
60  * be defined.
61  *
62  * HAVE_SEND is defined if you have a function named send()
63  * which is used to write outgoing data on a connected socket.
64  * If yours has another name then don't define HAVE_SEND.
65  *
66  * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2,
67  * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and
68  * SEND_TYPE_RETV must also be defined.
69  */
70
71 #ifdef HAVE_RECV
72 #if !defined(RECV_TYPE_ARG1) || \
73     !defined(RECV_TYPE_ARG2) || \
74     !defined(RECV_TYPE_ARG3) || \
75     !defined(RECV_TYPE_ARG4) || \
76     !defined(RECV_TYPE_RETV)
77   /* */
78   Error Missing_definition_of_return_and_arguments_types_of_recv
79   /* */
80 #else
81 #define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \
82                                    (RECV_TYPE_ARG2)(y), \
83                                    (RECV_TYPE_ARG3)(z), \
84                                    (RECV_TYPE_ARG4)(0))
85 #endif
86 #else /* HAVE_RECV */
87 #ifndef sread
88   /* */
89   Error Missing_definition_of_macro_sread
90   /* */
91 #endif
92 #endif /* HAVE_RECV */
93
94 #ifdef HAVE_SEND
95 #if !defined(SEND_TYPE_ARG1) || \
96     !defined(SEND_QUAL_ARG2) || \
97     !defined(SEND_TYPE_ARG2) || \
98     !defined(SEND_TYPE_ARG3) || \
99     !defined(SEND_TYPE_ARG4) || \
100     !defined(SEND_TYPE_RETV)
101   /* */
102   Error Missing_definition_of_return_and_arguments_types_of_send
103   /* */
104 #else
105 #define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
106                                     (SEND_TYPE_ARG2)(y), \
107                                     (SEND_TYPE_ARG3)(z), \
108                                     (SEND_TYPE_ARG4)(SEND_4TH_ARG))
109 #endif
110 #else /* HAVE_SEND */
111 #ifndef swrite
112   /* */
113   Error Missing_definition_of_macro_swrite
114   /* */
115 #endif
116 #endif /* HAVE_SEND */
117
118
119 /*
120  * Uppercase macro versions of ANSI/ISO is*() functions/macros which 
121  * avoid negative number inputs with argument byte codes > 127.
122  */
123
124 #define ISSPACE(x)  (isspace((int)  ((unsigned char)x)))
125 #define ISDIGIT(x)  (isdigit((int)  ((unsigned char)x)))
126 #define ISALNUM(x)  (isalnum((int)  ((unsigned char)x)))
127 #define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
128 #define ISGRAPH(x)  (isgraph((int)  ((unsigned char)x)))
129 #define ISALPHA(x)  (isalpha((int)  ((unsigned char)x)))
130 #define ISPRINT(x)  (isprint((int)  ((unsigned char)x)))
131 #define ISUPPER(x)  (isupper((int)  ((unsigned char)x)))
132 #define ISLOWER(x)  (islower((int)  ((unsigned char)x)))
133
134 #define ISBLANK(x)  (int)((((unsigned char)x) == ' ') || \
135                           (((unsigned char)x) == '\t'))
136
137
138 /*
139  * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
140  */
141
142 #ifndef HAVE_SIG_ATOMIC_T
143 typedef int sig_atomic_t;
144 #define HAVE_SIG_ATOMIC_T
145 #endif
146
147
148 /*
149  * Default return type for signal handlers.
150  */
151
152 #ifndef RETSIGTYPE
153 #define RETSIGTYPE void
154 #endif
155
156
157 /*
158  * Macro used to include code only in debug builds.
159  */
160
161 #ifdef CURLDEBUG
162 #define DEBUGF(X) X
163 #else
164 #define DEBUGF(X) do { } while (0)
165 #endif
166
167
168 /*
169  * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno
170  * (or equivalent) on this platform to hide platform details to code using it.
171  */
172
173 #ifdef USE_WINSOCK
174 #define SOCKERRNO         ((int)WSAGetLastError())
175 #define SET_SOCKERRNO(x)  (WSASetLastError((int)(x)))
176 #else
177 #define SOCKERRNO         (errno)
178 #define SET_SOCKERRNO(x)  (errno = (x))
179 #endif
180
181
182 /*
183  * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
184  * (or equivalent) on this platform to hide platform details to code using it.
185  */
186
187 #ifdef WIN32
188 #define ERRNO         ((int)GetLastError())
189 #define SET_ERRNO(x)  (SetLastError((DWORD)(x)))
190 #else
191 #define ERRNO         (errno)
192 #define SET_ERRNO(x)  (errno = (x))
193 #endif
194
195
196 /*
197  * Portable error number symbolic names defined to Winsock error codes.
198  */
199
200 #ifdef USE_WINSOCK
201 #define EWOULDBLOCK      WSAEWOULDBLOCK
202 #define EINPROGRESS      WSAEINPROGRESS
203 #define EALREADY         WSAEALREADY
204 #define ENOTSOCK         WSAENOTSOCK
205 #define EDESTADDRREQ     WSAEDESTADDRREQ
206 #define EMSGSIZE         WSAEMSGSIZE
207 #define EPROTOTYPE       WSAEPROTOTYPE
208 #define ENOPROTOOPT      WSAENOPROTOOPT
209 #define EPROTONOSUPPORT  WSAEPROTONOSUPPORT
210 #define ESOCKTNOSUPPORT  WSAESOCKTNOSUPPORT
211 #define EOPNOTSUPP       WSAEOPNOTSUPP
212 #define EPFNOSUPPORT     WSAEPFNOSUPPORT
213 #define EAFNOSUPPORT     WSAEAFNOSUPPORT
214 #define EADDRINUSE       WSAEADDRINUSE
215 #define EADDRNOTAVAIL    WSAEADDRNOTAVAIL
216 #define ENETDOWN         WSAENETDOWN
217 #define ENETUNREACH      WSAENETUNREACH
218 #define ENETRESET        WSAENETRESET
219 #define ECONNABORTED     WSAECONNABORTED
220 #define ECONNRESET       WSAECONNRESET
221 #define ENOBUFS          WSAENOBUFS
222 #define EISCONN          WSAEISCONN
223 #define ENOTCONN         WSAENOTCONN
224 #define ESHUTDOWN        WSAESHUTDOWN
225 #define ETOOMANYREFS     WSAETOOMANYREFS
226 #define ETIMEDOUT        WSAETIMEDOUT
227 #define ECONNREFUSED     WSAECONNREFUSED
228 #define ELOOP            WSAELOOP
229 #ifndef ENAMETOOLONG     /* possible previous definition in errno.h */
230 #define ENAMETOOLONG     WSAENAMETOOLONG
231 #endif
232 #define EHOSTDOWN        WSAEHOSTDOWN
233 #define EHOSTUNREACH     WSAEHOSTUNREACH
234 #ifndef ENOTEMPTY        /* possible previous definition in errno.h */
235 #define ENOTEMPTY        WSAENOTEMPTY
236 #endif
237 #define EPROCLIM         WSAEPROCLIM
238 #define EUSERS           WSAEUSERS
239 #define EDQUOT           WSAEDQUOT
240 #define ESTALE           WSAESTALE
241 #define EREMOTE          WSAEREMOTE
242 #endif
243
244
245 #endif /* __SETUP_ONCE_H */
246