Added SIZEOF_INT and SIZEOF_SHORT definitions for non-configure systems
[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  * $Id$
22  ***************************************************************************/
23
24 #include "setup.h"
25
26 #include "warnless.h"
27
28 #define CURL_MASK_SCHAR  0x7F
29 #define CURL_MASK_UCHAR  0xFF
30
31 #if (SIZEOF_SHORT == 2)
32 #  define CURL_MASK_SSHORT  0x7FFF
33 #  define CURL_MASK_USHORT  0xFFFF
34 #elif (SIZEOF_SHORT == 4)
35 #  define CURL_MASK_SSHORT  0x7FFFFFFF
36 #  define CURL_MASK_USHORT  0xFFFFFFFF
37 #elif (SIZEOF_SHORT == 8)
38 #  define CURL_MASK_SSHORT  0x7FFFFFFFFFFFFFFF
39 #  define CURL_MASK_USHORT  0xFFFFFFFFFFFFFFFF
40 #endif
41
42 #if (SIZEOF_INT == 2)
43 #  define CURL_MASK_SINT  0x7FFF
44 #  define CURL_MASK_UINT  0xFFFF
45 #elif (SIZEOF_INT == 4)
46 #  define CURL_MASK_SINT  0x7FFFFFFF
47 #  define CURL_MASK_UINT  0xFFFFFFFF
48 #elif (SIZEOF_INT == 8)
49 #  define CURL_MASK_SINT  0x7FFFFFFFFFFFFFFF
50 #  define CURL_MASK_UINT  0xFFFFFFFFFFFFFFFF
51 #elif (SIZEOF_INT == 16)
52 #  define CURL_MASK_SINT  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
53 #  define CURL_MASK_UINT  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
54 #endif
55
56 #if (CURL_SIZEOF_LONG == 2)
57 #  define CURL_MASK_SLONG  0x7FFFL
58 #  define CURL_MASK_ULONG  0xFFFFUL
59 #elif (SIZEOF_LONG == 4)
60 #  define CURL_MASK_SLONG  0x7FFFFFFFL
61 #  define CURL_MASK_ULONG  0xFFFFFFFFUL
62 #elif (SIZEOF_LONG == 8)
63 #  define CURL_MASK_SLONG  0x7FFFFFFFFFFFFFFFL
64 #  define CURL_MASK_ULONG  0xFFFFFFFFFFFFFFFFUL
65 #elif (SIZEOF_LONG == 16)
66 #  define CURL_MASK_SLONG  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
67 #  define CURL_MASK_ULONG  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
68 #endif
69
70 /*
71 ** unsigned long to unsigned short
72 */
73
74 unsigned short curlx_ultous(unsigned long ulnum)
75 {
76 #ifdef __INTEL_COMPILER
77 #  pragma warning(push)
78 #  pragma warning(disable:810) /* conversion may lose significant bits */
79 #endif
80
81   return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
82
83 #ifdef __INTEL_COMPILER
84 #  pragma warning(pop)
85 #endif
86 }
87
88 /*
89 ** unsigned long to unsigned char
90 */
91
92 unsigned char curlx_ultouc(unsigned long ulnum)
93 {
94 #ifdef __INTEL_COMPILER
95 #  pragma warning(push)
96 #  pragma warning(disable:810) /* conversion may lose significant bits */
97 #endif
98
99   return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);
100
101 #ifdef __INTEL_COMPILER
102 #  pragma warning(pop)
103 #endif
104 }
105
106 /*
107 ** size_t to signed int
108 */
109
110 int curlx_uztosi(size_t uznum)
111 {
112 #ifdef __INTEL_COMPILER
113 #  pragma warning(push)
114 #  pragma warning(disable:810) /* conversion may lose significant bits */
115 #endif
116
117   return (int)(uznum & (size_t) CURL_MASK_SINT);
118
119 #ifdef __INTEL_COMPILER
120 #  pragma warning(pop)
121 #endif
122 }