warnings: fix some 'conversion may lose significant bits' compiler warnings
[platform/upstream/c-ares.git] / ares_nowarn.c
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 #if defined(__INTEL_COMPILER) && defined(__unix__)
25
26 #ifdef HAVE_SYS_SOCKET_H
27 #  include <sys/socket.h>
28 #endif
29 #ifdef HAVE_NETINET_IN_H
30 #  include <netinet/in.h>
31 #endif
32 #ifdef HAVE_ARPA_INET_H
33 #  include <arpa/inet.h>
34 #endif
35
36 #endif /* __INTEL_COMPILER && __unix__ */
37
38 #define BUILDING_ARES_NOWARN_C 1
39
40 #include "ares_nowarn.h"
41
42 #if (SIZEOF_SHORT == 2)
43 #  define CARES_MASK_SSHORT  0x7FFF
44 #  define CARES_MASK_USHORT  0xFFFF
45 #elif (SIZEOF_SHORT == 4)
46 #  define CARES_MASK_SSHORT  0x7FFFFFFF
47 #  define CARES_MASK_USHORT  0xFFFFFFFF
48 #elif (SIZEOF_SHORT == 8)
49 #  define CARES_MASK_SSHORT  0x7FFFFFFFFFFFFFFF
50 #  define CARES_MASK_USHORT  0xFFFFFFFFFFFFFFFF
51 #else
52 #  error "SIZEOF_SHORT not defined"
53 #endif
54
55 #if (SIZEOF_INT == 2)
56 #  define CARES_MASK_SINT  0x7FFF
57 #  define CARES_MASK_UINT  0xFFFF
58 #elif (SIZEOF_INT == 4)
59 #  define CARES_MASK_SINT  0x7FFFFFFF
60 #  define CARES_MASK_UINT  0xFFFFFFFF
61 #elif (SIZEOF_INT == 8)
62 #  define CARES_MASK_SINT  0x7FFFFFFFFFFFFFFF
63 #  define CARES_MASK_UINT  0xFFFFFFFFFFFFFFFF
64 #elif (SIZEOF_INT == 16)
65 #  define CARES_MASK_SINT  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
66 #  define CARES_MASK_UINT  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
67 #endif
68
69 /*
70 ** unsigned size_t to signed int
71 */
72
73 int aresx_uztosi(size_t uznum)
74 {
75 #ifdef __INTEL_COMPILER
76 #  pragma warning(push)
77 #  pragma warning(disable:810) /* conversion may lose significant bits */
78 #endif
79
80   return (int)(uznum & (size_t) CARES_MASK_SINT);
81
82 #ifdef __INTEL_COMPILER
83 #  pragma warning(pop)
84 #endif
85 }
86
87 /*
88 ** unsigned size_t to signed short
89 */
90
91 short aresx_uztoss(size_t uznum)
92 {
93 #ifdef __INTEL_COMPILER
94 #  pragma warning(push)
95 #  pragma warning(disable:810) /* conversion may lose significant bits */
96 #endif
97
98   return (short)(uznum & (size_t) CARES_MASK_SSHORT);
99
100 #ifdef __INTEL_COMPILER
101 #  pragma warning(pop)
102 #endif
103 }
104
105 /*
106 ** signed int to signed short
107 */
108
109 short aresx_sitoss(int sinum)
110 {
111 #ifdef __INTEL_COMPILER
112 #  pragma warning(push)
113 #  pragma warning(disable:810) /* conversion may lose significant bits */
114 #endif
115
116   DEBUGASSERT(sinum >= 0);
117   return (short)(sinum & (int) CARES_MASK_SSHORT);
118
119 #ifdef __INTEL_COMPILER
120 #  pragma warning(pop)
121 #endif
122 }
123
124 /*
125 ** signed long to signed int
126 */
127
128 int aresx_sltosi(long slnum)
129 {
130 #ifdef __INTEL_COMPILER
131 #  pragma warning(push)
132 #  pragma warning(disable:810) /* conversion may lose significant bits */
133 #endif
134
135   DEBUGASSERT(slnum >= 0);
136   return (int)(slnum & (long) CARES_MASK_SINT);
137
138 #ifdef __INTEL_COMPILER
139 #  pragma warning(pop)
140 #endif
141 }
142
143 /*
144 ** signed ssize_t to signed int
145 */
146
147 int aresx_sztosi(ssize_t sznum)
148 {
149 #ifdef __INTEL_COMPILER
150 #  pragma warning(push)
151 #  pragma warning(disable:810) /* conversion may lose significant bits */
152 #endif
153
154   DEBUGASSERT(sznum >= 0);
155   return (int)(sznum & (ssize_t) CARES_MASK_SINT);
156
157 #ifdef __INTEL_COMPILER
158 #  pragma warning(pop)
159 #endif
160 }
161
162 /*
163 ** signed ssize_t to unsigned int
164 */
165
166 unsigned int aresx_sztoui(ssize_t sznum)
167 {
168 #ifdef __INTEL_COMPILER
169 #  pragma warning(push)
170 #  pragma warning(disable:810) /* conversion may lose significant bits */
171 #endif
172
173   DEBUGASSERT(sznum >= 0);
174   return (unsigned int)(sznum & (ssize_t) CARES_MASK_UINT);
175
176 #ifdef __INTEL_COMPILER
177 #  pragma warning(pop)
178 #endif
179 }
180
181 #if defined(__INTEL_COMPILER) && defined(__unix__)
182
183 int aresx_FD_ISSET(int fd, fd_set *fdset)
184 {
185   #pragma warning(push)
186   #pragma warning(disable:1469) /* clobber ignored */
187   return FD_ISSET(fd, fdset);
188   #pragma warning(pop)
189 }
190
191 void aresx_FD_SET(int fd, fd_set *fdset)
192 {
193   #pragma warning(push)
194   #pragma warning(disable:1469) /* clobber ignored */
195   FD_SET(fd, fdset);
196   #pragma warning(pop)
197 }
198
199 void aresx_FD_ZERO(fd_set *fdset)
200 {
201   #pragma warning(push)
202   #pragma warning(disable:593) /* variable was set but never used */
203   FD_ZERO(fdset);
204   #pragma warning(pop)
205 }
206
207 unsigned short aresx_htons(unsigned short usnum)
208 {
209 #if (__INTEL_COMPILER == 910) && defined(__i386__)
210   return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
211 #else
212   #pragma warning(push)
213   #pragma warning(disable:810) /* conversion may lose significant bits */
214   return htons(usnum);
215   #pragma warning(pop)
216 #endif
217 }
218
219 unsigned short aresx_ntohs(unsigned short usnum)
220 {
221 #if (__INTEL_COMPILER == 910) && defined(__i386__)
222   return (unsigned short)(((usnum << 8) & 0xFF00) | ((usnum >> 8) & 0x00FF));
223 #else
224   #pragma warning(push)
225   #pragma warning(disable:810) /* conversion may lose significant bits */
226   return ntohs(usnum);
227   #pragma warning(pop)
228 #endif
229 }
230
231 #endif /* __INTEL_COMPILER && __unix__ */