• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* Copyright (C) 2010-2011 by Daniel Stenberg
3  *
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.
15  */
16 
17 
18 #include "ares_setup.h"
19 
20 #ifdef HAVE_ASSERT_H
21 #  include <assert.h>
22 #endif
23 
24 #ifdef HAVE_LIMITS_H
25 #  include <limits.h>
26 #endif
27 
28 #if defined(__INTEL_COMPILER) && defined(__unix__)
29 
30 #ifdef HAVE_SYS_SOCKET_H
31 #  include <sys/socket.h>
32 #endif
33 #ifdef HAVE_NETINET_IN_H
34 #  include <netinet/in.h>
35 #endif
36 #ifdef HAVE_ARPA_INET_H
37 #  include <arpa/inet.h>
38 #endif
39 
40 #endif /* __INTEL_COMPILER && __unix__ */
41 
42 #define BUILDING_ARES_NOWARN_C 1
43 
44 #include "ares_nowarn.h"
45 
46 #if (SIZEOF_INT == 2)
47 #  define CARES_MASK_SINT  0x7FFF
48 #  define CARES_MASK_UINT  0xFFFF
49 #elif (SIZEOF_INT == 4)
50 #  define CARES_MASK_SINT  0x7FFFFFFF
51 #  define CARES_MASK_UINT  0xFFFFFFFF
52 #elif (SIZEOF_INT == 8)
53 #  define CARES_MASK_SINT  0x7FFFFFFFFFFFFFFF
54 #  define CARES_MASK_UINT  0xFFFFFFFFFFFFFFFF
55 #elif (SIZEOF_INT == 16)
56 #  define CARES_MASK_SINT  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
57 #  define CARES_MASK_UINT  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
58 #elif defined(HAVE_LIMITS_H)
59 #  define CARES_MASK_SINT  INT_MAX
60 #  define CARES_MASK_UINT  UINT_MAX
61 #endif
62 
63 /*
64 ** unsigned size_t to signed int
65 */
66 
aresx_uztosi(size_t uznum)67 int aresx_uztosi(size_t uznum)
68 {
69 #ifdef __INTEL_COMPILER
70 #  pragma warning(push)
71 #  pragma warning(disable:810) /* conversion may lose significant bits */
72 #endif
73 
74   return (int)(uznum & (size_t) CARES_MASK_SINT);
75 
76 #ifdef __INTEL_COMPILER
77 #  pragma warning(pop)
78 #endif
79 }
80 
81 /*
82 ** signed long to signed int
83 */
84 
aresx_sltosi(long slnum)85 int aresx_sltosi(long slnum)
86 {
87 #ifdef __INTEL_COMPILER
88 #  pragma warning(push)
89 #  pragma warning(disable:810) /* conversion may lose significant bits */
90 #endif
91 
92   DEBUGASSERT(slnum >= 0);
93   return (int)(slnum & (long) CARES_MASK_SINT);
94 
95 #ifdef __INTEL_COMPILER
96 #  pragma warning(pop)
97 #endif
98 }
99 
100 /*
101 ** signed ssize_t to signed int
102 */
103 
aresx_sztosi(ssize_t sznum)104 int aresx_sztosi(ssize_t sznum)
105 {
106 #ifdef __INTEL_COMPILER
107 #  pragma warning(push)
108 #  pragma warning(disable:810) /* conversion may lose significant bits */
109 #endif
110 
111   DEBUGASSERT(sznum >= 0);
112   return (int)(sznum & (ssize_t) CARES_MASK_SINT);
113 
114 #ifdef __INTEL_COMPILER
115 #  pragma warning(pop)
116 #endif
117 }
118 
119 /*
120 ** signed ssize_t to unsigned int
121 */
122 
aresx_sztoui(ssize_t sznum)123 unsigned int aresx_sztoui(ssize_t sznum)
124 {
125 #ifdef __INTEL_COMPILER
126 #  pragma warning(push)
127 #  pragma warning(disable:810) /* conversion may lose significant bits */
128 #endif
129 
130   DEBUGASSERT(sznum >= 0);
131   return (unsigned int)(sznum & (ssize_t) CARES_MASK_UINT);
132 
133 #ifdef __INTEL_COMPILER
134 #  pragma warning(pop)
135 #endif
136 }
137 
138 #if defined(__INTEL_COMPILER) && defined(__unix__)
139 
aresx_FD_ISSET(int fd,fd_set * fdset)140 int aresx_FD_ISSET(int fd, fd_set *fdset)
141 {
142   #pragma warning(push)
143   #pragma warning(disable:1469) /* clobber ignored */
144   return FD_ISSET(fd, fdset);
145   #pragma warning(pop)
146 }
147 
aresx_FD_SET(int fd,fd_set * fdset)148 void aresx_FD_SET(int fd, fd_set *fdset)
149 {
150   #pragma warning(push)
151   #pragma warning(disable:1469) /* clobber ignored */
152   FD_SET(fd, fdset);
153   #pragma warning(pop)
154 }
155 
aresx_FD_ZERO(fd_set * fdset)156 void aresx_FD_ZERO(fd_set *fdset)
157 {
158   #pragma warning(push)
159   #pragma warning(disable:593) /* variable was set but never used */
160   FD_ZERO(fdset);
161   #pragma warning(pop)
162 }
163 
aresx_htons(unsigned short usnum)164 unsigned short aresx_htons(unsigned short usnum)
165 {
166 #if (__INTEL_COMPILER == 910) && defined(__i386__)
167   return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
168 #else
169   #pragma warning(push)
170   #pragma warning(disable:810) /* conversion may lose significant bits */
171   return htons(usnum);
172   #pragma warning(pop)
173 #endif
174 }
175 
aresx_ntohs(unsigned short usnum)176 unsigned short aresx_ntohs(unsigned short usnum)
177 {
178 #if (__INTEL_COMPILER == 910) && defined(__i386__)
179   return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
180 #else
181   #pragma warning(push)
182   #pragma warning(disable:810) /* conversion may lose significant bits */
183   return ntohs(usnum);
184   #pragma warning(pop)
185 #endif
186 }
187 
188 #endif /* __INTEL_COMPILER && __unix__ */
189