2 /* Copyright (C) 2010-2012 by Daniel Stenberg
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of M.I.T. not be used in
10 * advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission.
12 * M.I.T. makes no representations about the suitability of
13 * this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
18 #include "ares_setup.h"
24 #if defined(__INTEL_COMPILER) && defined(__unix__)
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h>
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
33 #endif /* __INTEL_COMPILER && __unix__ */
35 #define BUILDING_ARES_NOWARN_C 1
37 #include "ares_nowarn.h"
39 #if (SIZEOF_SHORT == 2)
40 # define CARES_MASK_SSHORT 0x7FFF
41 # define CARES_MASK_USHORT 0xFFFF
42 #elif (SIZEOF_SHORT == 4)
43 # define CARES_MASK_SSHORT 0x7FFFFFFF
44 # define CARES_MASK_USHORT 0xFFFFFFFF
45 #elif (SIZEOF_SHORT == 8)
46 # define CARES_MASK_SSHORT 0x7FFFFFFFFFFFFFFF
47 # define CARES_MASK_USHORT 0xFFFFFFFFFFFFFFFF
49 # error "SIZEOF_SHORT not defined"
53 # define CARES_MASK_SINT 0x7FFF
54 # define CARES_MASK_UINT 0xFFFF
55 #elif (SIZEOF_INT == 4)
56 # define CARES_MASK_SINT 0x7FFFFFFF
57 # define CARES_MASK_UINT 0xFFFFFFFF
58 #elif (SIZEOF_INT == 8)
59 # define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFF
60 # define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFF
61 #elif (SIZEOF_INT == 16)
62 # define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
63 # define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
65 # error "SIZEOF_INT not defined"
68 #if (CARES_SIZEOF_LONG == 2)
69 # define CARES_MASK_SLONG 0x7FFFL
70 # define CARES_MASK_ULONG 0xFFFFUL
71 #elif (CARES_SIZEOF_LONG == 4)
72 # define CARES_MASK_SLONG 0x7FFFFFFFL
73 # define CARES_MASK_ULONG 0xFFFFFFFFUL
74 #elif (CARES_SIZEOF_LONG == 8)
75 # define CARES_MASK_SLONG 0x7FFFFFFFFFFFFFFFL
76 # define CARES_MASK_ULONG 0xFFFFFFFFFFFFFFFFUL
77 #elif (CARES_SIZEOF_LONG == 16)
78 # define CARES_MASK_SLONG 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
79 # define CARES_MASK_ULONG 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
81 # error "CARES_SIZEOF_LONG not defined"
85 ** unsigned size_t to signed long
88 long aresx_uztosl(size_t uznum)
90 #ifdef __INTEL_COMPILER
91 # pragma warning(push)
92 # pragma warning(disable:810) /* conversion may lose significant bits */
95 return (long)(uznum & (size_t) CARES_MASK_SLONG);
97 #ifdef __INTEL_COMPILER
103 ** unsigned size_t to signed int
106 int aresx_uztosi(size_t uznum)
108 #ifdef __INTEL_COMPILER
109 # pragma warning(push)
110 # pragma warning(disable:810) /* conversion may lose significant bits */
113 return (int)(uznum & (size_t) CARES_MASK_SINT);
115 #ifdef __INTEL_COMPILER
116 # pragma warning(pop)
121 ** unsigned size_t to signed short
124 short aresx_uztoss(size_t uznum)
126 #ifdef __INTEL_COMPILER
127 # pragma warning(push)
128 # pragma warning(disable:810) /* conversion may lose significant bits */
131 return (short)(uznum & (size_t) CARES_MASK_SSHORT);
133 #ifdef __INTEL_COMPILER
134 # pragma warning(pop)
139 ** signed int to signed short
142 short aresx_sitoss(int sinum)
144 #ifdef __INTEL_COMPILER
145 # pragma warning(push)
146 # pragma warning(disable:810) /* conversion may lose significant bits */
149 DEBUGASSERT(sinum >= 0);
150 return (short)(sinum & (int) CARES_MASK_SSHORT);
152 #ifdef __INTEL_COMPILER
153 # pragma warning(pop)
158 ** signed long to signed int
161 int aresx_sltosi(long slnum)
163 #ifdef __INTEL_COMPILER
164 # pragma warning(push)
165 # pragma warning(disable:810) /* conversion may lose significant bits */
168 DEBUGASSERT(slnum >= 0);
169 return (int)(slnum & (long) CARES_MASK_SINT);
171 #ifdef __INTEL_COMPILER
172 # pragma warning(pop)
177 ** signed ssize_t to signed int
180 int aresx_sztosi(ssize_t sznum)
182 #ifdef __INTEL_COMPILER
183 # pragma warning(push)
184 # pragma warning(disable:810) /* conversion may lose significant bits */
187 DEBUGASSERT(sznum >= 0);
188 return (int)(sznum & (ssize_t) CARES_MASK_SINT);
190 #ifdef __INTEL_COMPILER
191 # pragma warning(pop)
196 ** signed ssize_t to unsigned int
199 unsigned int aresx_sztoui(ssize_t sznum)
201 #ifdef __INTEL_COMPILER
202 # pragma warning(push)
203 # pragma warning(disable:810) /* conversion may lose significant bits */
206 DEBUGASSERT(sznum >= 0);
207 return (unsigned int)(sznum & (ssize_t) CARES_MASK_UINT);
209 #ifdef __INTEL_COMPILER
210 # pragma warning(pop)
215 ** signed int to unsigned short
218 unsigned short aresx_sitous(int sinum)
220 #ifdef __INTEL_COMPILER
221 # pragma warning(push)
222 # pragma warning(disable:810) /* conversion may lose significant bits */
225 DEBUGASSERT(sinum >= 0);
226 return (unsigned short)(sinum & (int) CARES_MASK_USHORT);
228 #ifdef __INTEL_COMPILER
229 # pragma warning(pop)
233 #if defined(__INTEL_COMPILER) && defined(__unix__)
235 int aresx_FD_ISSET(int fd, fd_set *fdset)
237 #pragma warning(push)
238 #pragma warning(disable:1469) /* clobber ignored */
239 return FD_ISSET(fd, fdset);
243 void aresx_FD_SET(int fd, fd_set *fdset)
245 #pragma warning(push)
246 #pragma warning(disable:1469) /* clobber ignored */
251 void aresx_FD_ZERO(fd_set *fdset)
253 #pragma warning(push)
254 #pragma warning(disable:593) /* variable was set but never used */
259 unsigned short aresx_htons(unsigned short usnum)
261 #if (__INTEL_COMPILER == 910) && defined(__i386__)
262 return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
264 #pragma warning(push)
265 #pragma warning(disable:810) /* conversion may lose significant bits */
271 unsigned short aresx_ntohs(unsigned short usnum)
273 #if (__INTEL_COMPILER == 910) && defined(__i386__)
274 return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
276 #pragma warning(push)
277 #pragma warning(disable:810) /* conversion may lose significant bits */
283 #endif /* __INTEL_COMPILER && __unix__ */