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 "SIZEOF_LONG not defined"
76 ** unsigned long to unsigned short
79 unsigned short curlx_ultous(unsigned long ulnum)
81 #ifdef __INTEL_COMPILER
82 # pragma warning(push)
83 # pragma warning(disable:810) /* conversion may lose significant bits */
86 return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
88 #ifdef __INTEL_COMPILER
94 ** unsigned long to unsigned char
97 unsigned char curlx_ultouc(unsigned long ulnum)
99 #ifdef __INTEL_COMPILER
100 # pragma warning(push)
101 # pragma warning(disable:810) /* conversion may lose significant bits */
104 return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);
106 #ifdef __INTEL_COMPILER
107 # pragma warning(pop)
112 ** size_t to signed int
115 int curlx_uztosi(size_t uznum)
117 #ifdef __INTEL_COMPILER
118 # pragma warning(push)
119 # pragma warning(disable:810) /* conversion may lose significant bits */
122 return (int)(uznum & (size_t) CURL_MASK_SINT);
124 #ifdef __INTEL_COMPILER
125 # pragma warning(pop)
130 ** signed long to signed int
133 int curlx_sltosi(long slnum)
135 #ifdef __INTEL_COMPILER
136 # pragma warning(push)
137 # pragma warning(disable:810) /* conversion may lose significant bits */
140 return (int)(slnum & (long) CURL_MASK_SINT);
142 #ifdef __INTEL_COMPILER
143 # pragma warning(pop)
148 ** signed long to unsigned int
151 unsigned int curlx_sltoui(long slnum)
153 #ifdef __INTEL_COMPILER
154 # pragma warning(push)
155 # pragma warning(disable:810) /* conversion may lose significant bits */
158 return (unsigned int)(slnum & (long) CURL_MASK_UINT);
160 #ifdef __INTEL_COMPILER
161 # pragma warning(pop)
166 ** signed long to unsigned short
169 unsigned short curlx_sltous(long slnum)
171 #ifdef __INTEL_COMPILER
172 # pragma warning(push)
173 # pragma warning(disable:810) /* conversion may lose significant bits */
176 return (unsigned short)(slnum & (long) CURL_MASK_USHORT);
178 #ifdef __INTEL_COMPILER
179 # pragma warning(pop)