XED
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xed-portability.h
Go to the documentation of this file.
1 /*BEGIN_LEGAL
2 Intel Open Source License
3 
4 Copyright (c) 2002-2014 Intel Corporation. All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9 
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer. Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution. Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 END_LEGAL */
33 
34 #ifndef _XED_PORTABILITY_H_
35 # define _XED_PORTABILITY_H_
36 # include "xed-common-hdrs.h"
37 # include "xed-types.h"
38 
39 
40 #define XED_STATIC_CAST(x,y) ((x) (y))
41 #define XED_REINTERPRET_CAST(x,y) ((x) (y))
42 #define XED_CAST(x,y) ((x) (y))
43 
44 
45 
46 XED_DLL_EXPORT xed_uint_t xed_strlen(const char* s);
47 XED_DLL_EXPORT void xed_strcat(char* dst, const char* src);
48 XED_DLL_EXPORT void xed_strcpy(char* dst, const char* src);
49 
52 XED_DLL_EXPORT int xed_strncpy(char* dst, const char* src, int len);
53 
56 XED_DLL_EXPORT int xed_strncat(char* dst, const char* src, int len);
57 
58 #if defined(__INTEL_COMPILER)
59 # if defined(_WIN32) && defined(_MSC_VER)
60 # if _MSC_VER >= 1400
61 # define XED_MSVC8_OR_LATER 1
62 # endif
63 # endif
64 #endif
65 
66 /* recognize VC98 */
67 #if !defined(__INTEL_COMPILER)
68 # if defined(_WIN32) && defined(_MSC_VER)
69 # if _MSC_VER == 1200
70 # define XED_MSVC6 1
71 # endif
72 # endif
73 # if defined(_WIN32) && defined(_MSC_VER)
74 # if _MSC_VER == 1310
75 # define XED_MSVC7 1
76 # endif
77 # endif
78 # if defined(_WIN32) && defined(_MSC_VER)
79 # if _MSC_VER >= 1400
80 # define XED_MSVC8_OR_LATER 1
81 # endif
82 # if _MSC_VER == 1400
83 # define XED_MSVC8 1
84 # endif
85 # if _MSC_VER == 1500
86 # define XED_MSVC9 1
87 # endif
88 # if _MSC_VER >= 1500
89 # define XED_MSVC9_OR_LATER 1
90 # endif
91 # if _MSC_VER == 1600
92 # define XED_MSVC10 1
93 # endif
94 # if _MSC_VER >= 1600
95 # define XED_MSVC10_OR_LATER 1
96 # endif
97 # endif
98 #endif
99 
100 /* I've had compatibilty problems here so I'm using a trivial indirection */
101 #if defined(__GNUC__)
102 # if defined(__CYGWIN__)
103  /* cygwin's gcc 3.4.4 on windows complains */
104 # define XED_FMT_X "%lx"
105 # define XED_FMT_08X "%08lx"
106 # define XED_FMT_D "%ld"
107 # define XED_FMT_U "%lu"
108 # define XED_FMT_9U "%9lu"
109 # else
110 # define XED_FMT_X "%x"
111 # define XED_FMT_08X "%08x"
112 # define XED_FMT_D "%d"
113 # define XED_FMT_U "%u"
114 # define XED_FMT_9U "%9u"
115 # endif
116 #else
117 # define XED_FMT_X "%x"
118 # define XED_FMT_08X "%08x"
119 # define XED_FMT_D "%d"
120 # define XED_FMT_U "%u"
121 # define XED_FMT_9U "%9u"
122 #endif
123 
124 // Go write portable code... Sigh
125 #if defined(__APPLE__) // clang *32b* and 64b
126 # define XED_FMT_SIZET "%lu"
127 #elif defined(__LP64__) // 64b gcc, icc
128 # define XED_FMT_SIZET "%lu"
129 #elif defined (_M_X64) // 64b msvs, ICL
130  // MSVS/x64 accepts %llu or %lu, icl/x64 does not)
131 # define XED_FMT_SIZET "%llu"
132 #else // 32b everything else
133 # define XED_FMT_SIZET "%u"
134 #endif
135 
136 #if defined(__GNUC__) && defined(__LP64__) && !defined(__APPLE__)
137 # define XED_FMT_LX "%lx"
138 # define XED_FMT_LU "%lu"
139 # define XED_FMT_LU12 "%12lu"
140 # define XED_FMT_LD "%ld"
141 # define XED_FMT_LX16 "%016lx"
142 #else
143 # define XED_FMT_LX "%llx"
144 # define XED_FMT_LU "%llu"
145 # define XED_FMT_LU12 "%12llu"
146 # define XED_FMT_LD "%lld"
147 # define XED_FMT_LX16 "%016llx"
148 #endif
149 
150 #if defined(__LP64__) || defined (_M_X64)
151 # define XED_64B 1
152 #endif
153 
154 #if defined(_M_IA64)
155 # define XED_IPF
156 # define XED_FMT_SIZET "%lu"
157 #endif
158 
159 #if defined(__GNUC__)
160  /* gcc4.2.x has a bug with c99/gnu99 inlining */
161 # if __GNUC__ == 4 && __GNUC_MINOR__ == 2
162 # define XED_INLINE inline
163 # else
164 # if __GNUC__ == 2
165 # define XED_INLINE
166 # else
167 # define XED_INLINE inline
168 # endif
169 # endif
170 # define XED_NORETURN __attribute__ ((noreturn))
171 # if __GNUC__ == 2
172 # define XED_NOINLINE
173 # else
174 # define XED_NOINLINE __attribute__ ((noinline))
175 # endif
176 #else
177 # define XED_INLINE __inline
178 # if defined(XED_MSVC6)
179 # define XED_NOINLINE
180 # else
181 # define XED_NOINLINE __declspec(noinline)
182 # endif
183 # define XED_NORETURN __declspec(noreturn)
184 #endif
185 
186 
187 
188 #define XED_MAX(a, b) (((a) > (b)) ? (a):(b))
189 #define XED_MIN(a, b) (((a) < (b)) ? (a):(b))
190 
191 
192 
193 
194 #endif // _XED_PORTABILITY_H_
195 
XED_DLL_EXPORT void xed_strcat(char *dst, const char *src)
XED_DLL_EXPORT xed_uint_t xed_strlen(const char *s)
XED_DLL_EXPORT int xed_strncpy(char *dst, const char *src, int len)
returns the number of bytes remaining for the next use of xed_strncpy() or xed_strncat() ...
unsigned int xed_uint_t
Definition: xed-types.h:65
XED_DLL_EXPORT int xed_strncat(char *dst, const char *src, int len)
returns the number of bytes remaining for the next use of xed_strncpy() or xed_strncat() ...
XED_DLL_EXPORT void xed_strcpy(char *dst, const char *src)
#define XED_DLL_EXPORT