fix compiler warning: conversion may lose significant bits
[platform/upstream/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 "SIZEOF_LONG not defined"
73 #endif
74
75 /*
76 ** unsigned long to unsigned short
77 */
78
79 unsigned short curlx_ultous(unsigned long ulnum)
80 {
81 #ifdef __INTEL_COMPILER
82 #  pragma warning(push)
83 #  pragma warning(disable:810) /* conversion may lose significant bits */
84 #endif
85
86   return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
87
88 #ifdef __INTEL_COMPILER
89 #  pragma warning(pop)
90 #endif
91 }
92
93 /*
94 ** unsigned long to unsigned char
95 */
96
97 unsigned char curlx_ultouc(unsigned long ulnum)
98 {
99 #ifdef __INTEL_COMPILER
100 #  pragma warning(push)
101 #  pragma warning(disable:810) /* conversion may lose significant bits */
102 #endif
103
104   return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);
105
106 #ifdef __INTEL_COMPILER
107 #  pragma warning(pop)
108 #endif
109 }
110
111 /*
112 ** size_t to signed int
113 */
114
115 int curlx_uztosi(size_t uznum)
116 {
117 #ifdef __INTEL_COMPILER
118 #  pragma warning(push)
119 #  pragma warning(disable:810) /* conversion may lose significant bits */
120 #endif
121
122   return (int)(uznum & (size_t) CURL_MASK_SINT);
123
124 #ifdef __INTEL_COMPILER
125 #  pragma warning(pop)
126 #endif
127 }
128
129 /*
130 ** signed long to signed int
131 */
132
133 int curlx_sltosi(long slnum)
134 {
135 #ifdef __INTEL_COMPILER
136 #  pragma warning(push)
137 #  pragma warning(disable:810) /* conversion may lose significant bits */
138 #endif
139
140   return (int)(slnum & (long) CURL_MASK_SINT);
141
142 #ifdef __INTEL_COMPILER
143 #  pragma warning(pop)
144 #endif
145 }
146
147 /*
148 ** signed long to unsigned int
149 */
150
151 unsigned int curlx_sltoui(long slnum)
152 {
153 #ifdef __INTEL_COMPILER
154 #  pragma warning(push)
155 #  pragma warning(disable:810) /* conversion may lose significant bits */
156 #endif
157
158   return (unsigned int)(slnum & (long) CURL_MASK_UINT);
159
160 #ifdef __INTEL_COMPILER
161 #  pragma warning(pop)
162 #endif
163 }
164
165 /*
166 ** signed long to unsigned short
167 */
168
169 unsigned short curlx_sltous(long slnum)
170 {
171 #ifdef __INTEL_COMPILER
172 #  pragma warning(push)
173 #  pragma warning(disable:810) /* conversion may lose significant bits */
174 #endif
175
176   return (unsigned short)(slnum & (long) CURL_MASK_USHORT);
177
178 #ifdef __INTEL_COMPILER
179 #  pragma warning(pop)
180 #endif
181 }