1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
27 #define CURL_MASK_SCHAR 0x7F
28 #define CURL_MASK_UCHAR 0xFF
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
40 # error "SIZEOF_SHORT not defined"
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
56 # error "SIZEOF_INT not defined"
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
72 # error "CURL_SIZEOF_LONG not defined"
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)
88 # error "CURL_SIZEOF_CURL_OFF_T not defined"
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
104 # error "SIZEOF_SIZE_T not defined"
108 ** unsigned long to unsigned short
111 unsigned short curlx_ultous(unsigned long ulnum)
113 #ifdef __INTEL_COMPILER
114 # pragma warning(push)
115 # pragma warning(disable:810) /* conversion may lose significant bits */
118 return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
120 #ifdef __INTEL_COMPILER
121 # pragma warning(pop)
126 ** unsigned long to unsigned char
129 unsigned char curlx_ultouc(unsigned long ulnum)
131 #ifdef __INTEL_COMPILER
132 # pragma warning(push)
133 # pragma warning(disable:810) /* conversion may lose significant bits */
136 return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);
138 #ifdef __INTEL_COMPILER
139 # pragma warning(pop)
144 ** unsigned size_t to signed int
147 int curlx_uztosi(size_t uznum)
149 #ifdef __INTEL_COMPILER
150 # pragma warning(push)
151 # pragma warning(disable:810) /* conversion may lose significant bits */
154 return (int)(uznum & (size_t) CURL_MASK_SINT);
156 #ifdef __INTEL_COMPILER
157 # pragma warning(pop)
162 ** signed long to signed int
165 int curlx_sltosi(long slnum)
167 #ifdef __INTEL_COMPILER
168 # pragma warning(push)
169 # pragma warning(disable:810) /* conversion may lose significant bits */
172 DEBUGASSERT(slnum >= 0);
173 return (int)(slnum & (long) CURL_MASK_SINT);
175 #ifdef __INTEL_COMPILER
176 # pragma warning(pop)
181 ** signed long to unsigned int
184 unsigned int curlx_sltoui(long slnum)
186 #ifdef __INTEL_COMPILER
187 # pragma warning(push)
188 # pragma warning(disable:810) /* conversion may lose significant bits */
191 DEBUGASSERT(slnum >= 0);
192 return (unsigned int)(slnum & (long) CURL_MASK_UINT);
194 #ifdef __INTEL_COMPILER
195 # pragma warning(pop)
200 ** signed long to unsigned short
203 unsigned short curlx_sltous(long slnum)
205 #ifdef __INTEL_COMPILER
206 # pragma warning(push)
207 # pragma warning(disable:810) /* conversion may lose significant bits */
210 DEBUGASSERT(slnum >= 0);
211 return (unsigned short)(slnum & (long) CURL_MASK_USHORT);
213 #ifdef __INTEL_COMPILER
214 # pragma warning(pop)
219 ** unsigned size_t to signed ssize_t
222 ssize_t curlx_uztosz(size_t uznum)
224 #ifdef __INTEL_COMPILER
225 # pragma warning(push)
226 # pragma warning(disable:810) /* conversion may lose significant bits */
229 return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T);
231 #ifdef __INTEL_COMPILER
232 # pragma warning(pop)
237 ** signed curl_off_t to unsigned size_t
240 size_t curlx_sotouz(curl_off_t sonum)
242 #ifdef __INTEL_COMPILER
243 # pragma warning(push)
244 # pragma warning(disable:810) /* conversion may lose significant bits */
247 DEBUGASSERT(sonum >= 0);
248 return (size_t)(sonum & (curl_off_t) CURL_MASK_USIZE_T);
250 #ifdef __INTEL_COMPILER
251 # pragma warning(pop)