compiler warning: fix
[platform/upstream/curl.git] / lib / warnless.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22
23 #include "setup.h"
24
25 #define BUILDING_WARNLESS_C 1
26
27 #include "warnless.h"
28
29 #define CURL_MASK_SCHAR  0x7F
30 #define CURL_MASK_UCHAR  0xFF
31
32 #if (SIZEOF_SHORT == 2)
33 #  define CURL_MASK_SSHORT  0x7FFF
34 #  define CURL_MASK_USHORT  0xFFFF
35 #elif (SIZEOF_SHORT == 4)
36 #  define CURL_MASK_SSHORT  0x7FFFFFFF
37 #  define CURL_MASK_USHORT  0xFFFFFFFF
38 #elif (SIZEOF_SHORT == 8)
39 #  define CURL_MASK_SSHORT  0x7FFFFFFFFFFFFFFF
40 #  define CURL_MASK_USHORT  0xFFFFFFFFFFFFFFFF
41 #else
42 #  error "SIZEOF_SHORT not defined"
43 #endif
44
45 #if (SIZEOF_INT == 2)
46 #  define CURL_MASK_SINT  0x7FFF
47 #  define CURL_MASK_UINT  0xFFFF
48 #elif (SIZEOF_INT == 4)
49 #  define CURL_MASK_SINT  0x7FFFFFFF
50 #  define CURL_MASK_UINT  0xFFFFFFFF
51 #elif (SIZEOF_INT == 8)
52 #  define CURL_MASK_SINT  0x7FFFFFFFFFFFFFFF
53 #  define CURL_MASK_UINT  0xFFFFFFFFFFFFFFFF
54 #elif (SIZEOF_INT == 16)
55 #  define CURL_MASK_SINT  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
56 #  define CURL_MASK_UINT  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
57 #else
58 #  error "SIZEOF_INT not defined"
59 #endif
60
61 #if (CURL_SIZEOF_LONG == 2)
62 #  define CURL_MASK_SLONG  0x7FFFL
63 #  define CURL_MASK_ULONG  0xFFFFUL
64 #elif (CURL_SIZEOF_LONG == 4)
65 #  define CURL_MASK_SLONG  0x7FFFFFFFL
66 #  define CURL_MASK_ULONG  0xFFFFFFFFUL
67 #elif (CURL_SIZEOF_LONG == 8)
68 #  define CURL_MASK_SLONG  0x7FFFFFFFFFFFFFFFL
69 #  define CURL_MASK_ULONG  0xFFFFFFFFFFFFFFFFUL
70 #elif (CURL_SIZEOF_LONG == 16)
71 #  define CURL_MASK_SLONG  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
72 #  define CURL_MASK_ULONG  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
73 #else
74 #  error "CURL_SIZEOF_LONG not defined"
75 #endif
76
77 #if (CURL_SIZEOF_CURL_OFF_T == 2)
78 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFF)
79 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFF)
80 #elif (CURL_SIZEOF_CURL_OFF_T == 4)
81 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFFFFFF)
82 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFFFFFF)
83 #elif (CURL_SIZEOF_CURL_OFF_T == 8)
84 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
85 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFF)
86 #elif (CURL_SIZEOF_CURL_OFF_T == 16)
87 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
88 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
89 #else
90 #  error "CURL_SIZEOF_CURL_OFF_T not defined"
91 #endif
92
93 #if (SIZEOF_SIZE_T == SIZEOF_SHORT)
94 #  define CURL_MASK_SSIZE_T  CURL_MASK_SSHORT
95 #  define CURL_MASK_USIZE_T  CURL_MASK_USHORT
96 #elif (SIZEOF_SIZE_T == SIZEOF_INT)
97 #  define CURL_MASK_SSIZE_T  CURL_MASK_SINT
98 #  define CURL_MASK_USIZE_T  CURL_MASK_UINT
99 #elif (SIZEOF_SIZE_T == CURL_SIZEOF_LONG)
100 #  define CURL_MASK_SSIZE_T  CURL_MASK_SLONG
101 #  define CURL_MASK_USIZE_T  CURL_MASK_ULONG
102 #elif (SIZEOF_SIZE_T == CURL_SIZEOF_CURL_OFF_T)
103 #  define CURL_MASK_SSIZE_T  CURL_MASK_SCOFFT
104 #  define CURL_MASK_USIZE_T  CURL_MASK_UCOFFT
105 #else
106 #  error "SIZEOF_SIZE_T not defined"
107 #endif
108
109 /*
110 ** unsigned long to unsigned short
111 */
112
113 unsigned short curlx_ultous(unsigned long ulnum)
114 {
115 #ifdef __INTEL_COMPILER
116 #  pragma warning(push)
117 #  pragma warning(disable:810) /* conversion may lose significant bits */
118 #endif
119
120   return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
121
122 #ifdef __INTEL_COMPILER
123 #  pragma warning(pop)
124 #endif
125 }
126
127 /*
128 ** unsigned long to unsigned char
129 */
130
131 unsigned char curlx_ultouc(unsigned long ulnum)
132 {
133 #ifdef __INTEL_COMPILER
134 #  pragma warning(push)
135 #  pragma warning(disable:810) /* conversion may lose significant bits */
136 #endif
137
138   return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);
139
140 #ifdef __INTEL_COMPILER
141 #  pragma warning(pop)
142 #endif
143 }
144
145 /*
146 ** unsigned size_t to signed int
147 */
148
149 int curlx_uztosi(size_t uznum)
150 {
151 #ifdef __INTEL_COMPILER
152 #  pragma warning(push)
153 #  pragma warning(disable:810) /* conversion may lose significant bits */
154 #endif
155
156   return (int)(uznum & (size_t) CURL_MASK_SINT);
157
158 #ifdef __INTEL_COMPILER
159 #  pragma warning(pop)
160 #endif
161 }
162
163 /*
164 ** signed long to signed int
165 */
166
167 int curlx_sltosi(long slnum)
168 {
169 #ifdef __INTEL_COMPILER
170 #  pragma warning(push)
171 #  pragma warning(disable:810) /* conversion may lose significant bits */
172 #endif
173
174   DEBUGASSERT(slnum >= 0);
175   return (int)(slnum & (long) CURL_MASK_SINT);
176
177 #ifdef __INTEL_COMPILER
178 #  pragma warning(pop)
179 #endif
180 }
181
182 /*
183 ** signed long to unsigned int
184 */
185
186 unsigned int curlx_sltoui(long slnum)
187 {
188 #ifdef __INTEL_COMPILER
189 #  pragma warning(push)
190 #  pragma warning(disable:810) /* conversion may lose significant bits */
191 #endif
192
193   DEBUGASSERT(slnum >= 0);
194   return (unsigned int)(slnum & (long) CURL_MASK_UINT);
195
196 #ifdef __INTEL_COMPILER
197 #  pragma warning(pop)
198 #endif
199 }
200
201 /*
202 ** signed long to unsigned short
203 */
204
205 unsigned short curlx_sltous(long slnum)
206 {
207 #ifdef __INTEL_COMPILER
208 #  pragma warning(push)
209 #  pragma warning(disable:810) /* conversion may lose significant bits */
210 #endif
211
212   DEBUGASSERT(slnum >= 0);
213   return (unsigned short)(slnum & (long) CURL_MASK_USHORT);
214
215 #ifdef __INTEL_COMPILER
216 #  pragma warning(pop)
217 #endif
218 }
219
220 /*
221 ** unsigned size_t to signed ssize_t
222 */
223
224 ssize_t curlx_uztosz(size_t uznum)
225 {
226 #ifdef __INTEL_COMPILER
227 #  pragma warning(push)
228 #  pragma warning(disable:810) /* conversion may lose significant bits */
229 #endif
230
231   return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T);
232
233 #ifdef __INTEL_COMPILER
234 #  pragma warning(pop)
235 #endif
236 }
237
238 /*
239 ** signed curl_off_t to unsigned size_t
240 */
241
242 size_t curlx_sotouz(curl_off_t sonum)
243 {
244 #ifdef __INTEL_COMPILER
245 #  pragma warning(push)
246 #  pragma warning(disable:810) /* conversion may lose significant bits */
247 #endif
248
249   DEBUGASSERT(sonum >= 0);
250   return (size_t)(sonum & (curl_off_t) CURL_MASK_USIZE_T);
251
252 #ifdef __INTEL_COMPILER
253 #  pragma warning(pop)
254 #endif
255 }
256
257 #if defined(__INTEL_COMPILER) && defined(__unix__)
258
259 int curlx_FD_ISSET(int fd, fd_set *fdset)
260 {
261   #pragma warning(push)
262   #pragma warning(disable:1469) /* clobber ignored */
263   return FD_ISSET(fd, fdset);
264   #pragma warning(pop)
265 }
266
267 void curlx_FD_SET(int fd, fd_set *fdset)
268 {
269   #pragma warning(push)
270   #pragma warning(disable:1469) /* clobber ignored */
271   FD_SET(fd, fdset);
272   #pragma warning(pop)
273 }
274
275 void curlx_FD_ZERO(fd_set *fdset)
276 {
277   #pragma warning(push)
278   #pragma warning(disable:593) /* variable was set but never used */
279   FD_ZERO(fdset);
280   #pragma warning(pop)
281 }
282
283 #endif /* __INTEL_COMPILER && __unix__ */