ares_nowarn: add conditional inclusion of assert.h header
[platform/upstream/c-ares.git] / ares_nowarn.c
1
2 /* Copyright (C) 2010 by Daniel Stenberg
3  *
4  * Permission to use, copy, modify, and distribute this
5  * software and its documentation for any purpose and without
6  * fee is hereby granted, provided that the above copyright
7  * notice appear in all copies and that both that copyright
8  * notice and this permission notice appear in supporting
9  * documentation, and that the name of M.I.T. not be used in
10  * advertising or publicity pertaining to distribution of the
11  * software without specific, written prior permission.
12  * M.I.T. makes no representations about the suitability of
13  * this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  */
16
17
18 #include "ares_setup.h"
19
20 #ifdef HAVE_ASSERT_H
21 #  include <assert.h>
22 #endif
23
24 #include "ares_nowarn.h"
25
26 #if (SIZEOF_INT == 2)
27 #  define CARES_MASK_SINT  0x7FFF
28 #  define CARES_MASK_UINT  0xFFFF
29 #elif (SIZEOF_INT == 4)
30 #  define CARES_MASK_SINT  0x7FFFFFFF
31 #  define CARES_MASK_UINT  0xFFFFFFFF
32 #elif (SIZEOF_INT == 8)
33 #  define CARES_MASK_SINT  0x7FFFFFFFFFFFFFFF
34 #  define CARES_MASK_UINT  0xFFFFFFFFFFFFFFFF
35 #elif (SIZEOF_INT == 16)
36 #  define CARES_MASK_SINT  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
37 #  define CARES_MASK_UINT  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
38 #endif
39
40 /*
41 ** unsigned size_t to signed int
42 */
43
44 int aresx_uztosi(size_t uznum)
45 {
46 #ifdef __INTEL_COMPILER
47 #  pragma warning(push)
48 #  pragma warning(disable:810) /* conversion may lose significant bits */
49 #endif
50
51   return (int)(uznum & (size_t) CARES_MASK_SINT);
52
53 #ifdef __INTEL_COMPILER
54 #  pragma warning(pop)
55 #endif
56 }
57
58 /*
59 ** signed long to signed int
60 */
61
62 int aresx_sltosi(long slnum)
63 {
64 #ifdef __INTEL_COMPILER
65 #  pragma warning(push)
66 #  pragma warning(disable:810) /* conversion may lose significant bits */
67 #endif
68
69   DEBUGASSERT(slnum >= 0);
70   return (int)(slnum & (long) CARES_MASK_SINT);
71
72 #ifdef __INTEL_COMPILER
73 #  pragma warning(pop)
74 #endif
75 }
76
77 /*
78 ** signed ssize_t to signed int
79 */
80
81 int aresx_sztosi(ssize_t sznum)
82 {
83 #ifdef __INTEL_COMPILER
84 #  pragma warning(push)
85 #  pragma warning(disable:810) /* conversion may lose significant bits */
86 #endif
87
88   DEBUGASSERT(sznum >= 0);
89   return (int)(sznum & (ssize_t) CARES_MASK_SINT);
90
91 #ifdef __INTEL_COMPILER
92 #  pragma warning(pop)
93 #endif
94 }
95
96 /*
97 ** signed ssize_t to unsigned int
98 */
99
100 unsigned int aresx_sztoui(ssize_t sznum)
101 {
102 #ifdef __INTEL_COMPILER
103 #  pragma warning(push)
104 #  pragma warning(disable:810) /* conversion may lose significant bits */
105 #endif
106
107   DEBUGASSERT(sznum >= 0);
108   return (unsigned int)(sznum & (ssize_t) CARES_MASK_UINT);
109
110 #ifdef __INTEL_COMPILER
111 #  pragma warning(pop)
112 #endif
113 }