Git init
[external/curl.git] / lib / warnless.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2010, 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 #include "warnless.h"
26
27 #define CURL_MASK_SCHAR  0x7F
28 #define CURL_MASK_UCHAR  0xFF
29
30 #if (SIZEOF_SHORT == 2)
31 #  define CURL_MASK_SSHORT  0x7FFF
32 #  define CURL_MASK_USHORT  0xFFFF
33 #elif (SIZEOF_SHORT == 4)
34 #  define CURL_MASK_SSHORT  0x7FFFFFFF
35 #  define CURL_MASK_USHORT  0xFFFFFFFF
36 #elif (SIZEOF_SHORT == 8)
37 #  define CURL_MASK_SSHORT  0x7FFFFFFFFFFFFFFF
38 #  define CURL_MASK_USHORT  0xFFFFFFFFFFFFFFFF
39 #else
40 #  error "SIZEOF_SHORT not defined"
41 #endif
42
43 #if (SIZEOF_INT == 2)
44 #  define CURL_MASK_SINT  0x7FFF
45 #  define CURL_MASK_UINT  0xFFFF
46 #elif (SIZEOF_INT == 4)
47 #  define CURL_MASK_SINT  0x7FFFFFFF
48 #  define CURL_MASK_UINT  0xFFFFFFFF
49 #elif (SIZEOF_INT == 8)
50 #  define CURL_MASK_SINT  0x7FFFFFFFFFFFFFFF
51 #  define CURL_MASK_UINT  0xFFFFFFFFFFFFFFFF
52 #elif (SIZEOF_INT == 16)
53 #  define CURL_MASK_SINT  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
54 #  define CURL_MASK_UINT  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
55 #else
56 #  error "SIZEOF_INT not defined"
57 #endif
58
59 #if (CURL_SIZEOF_LONG == 2)
60 #  define CURL_MASK_SLONG  0x7FFFL
61 #  define CURL_MASK_ULONG  0xFFFFUL
62 #elif (CURL_SIZEOF_LONG == 4)
63 #  define CURL_MASK_SLONG  0x7FFFFFFFL
64 #  define CURL_MASK_ULONG  0xFFFFFFFFUL
65 #elif (CURL_SIZEOF_LONG == 8)
66 #  define CURL_MASK_SLONG  0x7FFFFFFFFFFFFFFFL
67 #  define CURL_MASK_ULONG  0xFFFFFFFFFFFFFFFFUL
68 #elif (CURL_SIZEOF_LONG == 16)
69 #  define CURL_MASK_SLONG  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
70 #  define CURL_MASK_ULONG  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
71 #else
72 #  error "CURL_SIZEOF_LONG not defined"
73 #endif
74
75 #if (CURL_SIZEOF_CURL_OFF_T == 2)
76 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFF)
77 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFF)
78 #elif (CURL_SIZEOF_CURL_OFF_T == 4)
79 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFFFFFF)
80 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFFFFFF)
81 #elif (CURL_SIZEOF_CURL_OFF_T == 8)
82 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
83 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFF)
84 #elif (CURL_SIZEOF_CURL_OFF_T == 16)
85 #  define CURL_MASK_SCOFFT  CURL_OFF_T_C(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
86 #  define CURL_MASK_UCOFFT  CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
87 #else
88 #  error "CURL_SIZEOF_CURL_OFF_T not defined"
89 #endif
90
91 #if (SIZEOF_SIZE_T == SIZEOF_SHORT)
92 #  define CURL_MASK_SSIZE_T  CURL_MASK_SSHORT
93 #  define CURL_MASK_USIZE_T  CURL_MASK_USHORT
94 #elif (SIZEOF_SIZE_T == SIZEOF_INT)
95 #  define CURL_MASK_SSIZE_T  CURL_MASK_SINT
96 #  define CURL_MASK_USIZE_T  CURL_MASK_UINT
97 #elif (SIZEOF_SIZE_T == CURL_SIZEOF_LONG)
98 #  define CURL_MASK_SSIZE_T  CURL_MASK_SLONG
99 #  define CURL_MASK_USIZE_T  CURL_MASK_ULONG
100 #elif (SIZEOF_SIZE_T == CURL_SIZEOF_CURL_OFF_T)
101 #  define CURL_MASK_SSIZE_T  CURL_MASK_SCOFFT
102 #  define CURL_MASK_USIZE_T  CURL_MASK_UCOFFT
103 #else
104 #  error "SIZEOF_SIZE_T not defined"
105 #endif
106
107 /*
108 ** unsigned long to unsigned short
109 */
110
111 unsigned short curlx_ultous(unsigned long ulnum)
112 {
113 #ifdef __INTEL_COMPILER
114 #  pragma warning(push)
115 #  pragma warning(disable:810) /* conversion may lose significant bits */
116 #endif
117
118   return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
119
120 #ifdef __INTEL_COMPILER
121 #  pragma warning(pop)
122 #endif
123 }
124
125 /*
126 ** unsigned long to unsigned char
127 */
128
129 unsigned char curlx_ultouc(unsigned long ulnum)
130 {
131 #ifdef __INTEL_COMPILER
132 #  pragma warning(push)
133 #  pragma warning(disable:810) /* conversion may lose significant bits */
134 #endif
135
136   return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);
137
138 #ifdef __INTEL_COMPILER
139 #  pragma warning(pop)
140 #endif
141 }
142
143 /*
144 ** unsigned size_t to signed int
145 */
146
147 int curlx_uztosi(size_t uznum)
148 {
149 #ifdef __INTEL_COMPILER
150 #  pragma warning(push)
151 #  pragma warning(disable:810) /* conversion may lose significant bits */
152 #endif
153
154   return (int)(uznum & (size_t) CURL_MASK_SINT);
155
156 #ifdef __INTEL_COMPILER
157 #  pragma warning(pop)
158 #endif
159 }
160
161 /*
162 ** signed long to signed int
163 */
164
165 int curlx_sltosi(long slnum)
166 {
167 #ifdef __INTEL_COMPILER
168 #  pragma warning(push)
169 #  pragma warning(disable:810) /* conversion may lose significant bits */
170 #endif
171
172   DEBUGASSERT(slnum >= 0);
173   return (int)(slnum & (long) CURL_MASK_SINT);
174
175 #ifdef __INTEL_COMPILER
176 #  pragma warning(pop)
177 #endif
178 }
179
180 /*
181 ** signed long to unsigned int
182 */
183
184 unsigned int curlx_sltoui(long slnum)
185 {
186 #ifdef __INTEL_COMPILER
187 #  pragma warning(push)
188 #  pragma warning(disable:810) /* conversion may lose significant bits */
189 #endif
190
191   DEBUGASSERT(slnum >= 0);
192   return (unsigned int)(slnum & (long) CURL_MASK_UINT);
193
194 #ifdef __INTEL_COMPILER
195 #  pragma warning(pop)
196 #endif
197 }
198
199 /*
200 ** signed long to unsigned short
201 */
202
203 unsigned short curlx_sltous(long slnum)
204 {
205 #ifdef __INTEL_COMPILER
206 #  pragma warning(push)
207 #  pragma warning(disable:810) /* conversion may lose significant bits */
208 #endif
209
210   DEBUGASSERT(slnum >= 0);
211   return (unsigned short)(slnum & (long) CURL_MASK_USHORT);
212
213 #ifdef __INTEL_COMPILER
214 #  pragma warning(pop)
215 #endif
216 }
217
218 /*
219 ** unsigned size_t to signed ssize_t
220 */
221
222 ssize_t curlx_uztosz(size_t uznum)
223 {
224 #ifdef __INTEL_COMPILER
225 #  pragma warning(push)
226 #  pragma warning(disable:810) /* conversion may lose significant bits */
227 #endif
228
229   return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T);
230
231 #ifdef __INTEL_COMPILER
232 #  pragma warning(pop)
233 #endif
234 }
235
236 /*
237 ** signed curl_off_t to unsigned size_t
238 */
239
240 size_t curlx_sotouz(curl_off_t sonum)
241 {
242 #ifdef __INTEL_COMPILER
243 #  pragma warning(push)
244 #  pragma warning(disable:810) /* conversion may lose significant bits */
245 #endif
246
247   DEBUGASSERT(sonum >= 0);
248   return (size_t)(sonum & (curl_off_t) CURL_MASK_USIZE_T);
249
250 #ifdef __INTEL_COMPILER
251 #  pragma warning(pop)
252 #endif
253 }