xsens_compat.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to 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 "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef __XSENS_LINUX_H
66 #define __XSENS_LINUX_H
67 
68 /* #undef HAVE_STRTOK_S */
69 /* #undef HAVE_STRTOK_R */
70 /* #undef HAVE__WCSICMP */
71 /* #undef HAVE_WCSICMP */
72 /* #undef HAVE__WCSNICMP */
73 /* #undef HAVE_WCSNICMP */
74 #define HAVE_WCSNCASECMP 1
75 #define HAVE_WCSCASECMP 1
76 /* #undef HAVE_SPRINTF_S */
77 /* #undef HAVE_STRCPY_S */
78 /* #undef HAVE_STRCAT_S */
79 /* #undef HAVE_STRNCPY_S */
80 /* #undef HAVE_FOPEN_S */
81 /* #undef HAVE_STRICMP */
82 /* #undef HAVE__STRICMP */
83 #define HAVE_STRCASECMP 1
84 /* #undef HAVE_STRNICMP */
85 /* #undef HAVE__STRNICMP */
86 #define HAVE_STRNCASECMP 1
87 /* #undef HAVE_WFOPEN */
88 /* #undef HAVE__WFOPEN */
89 /* #undef HAVE__STRDUP */
90 #define HAVE_STRDUP 1
91 /* #undef HAVE__WCSDUP */
92 #define HAVE_WCSDUP 1
93 /* #undef HAVE__FULLPATH */
94 /* #undef HAVE_FULLPATH */
95 #define HAVE_REALPATH 1
96 /* #undef HAVE_WFULLPATH */
97 /* #undef HAVE_WFREOPEN */
98 /* #undef HAVE__UNLINK */
99 #define HAVE_UNLINK 1
100 /* #undef HAVE__ISNAN */
101 #define HAVE_ISNAN 1
102 /* #undef HAVE__FILENO */
103 #define HAVE_FILENO 1
104 /* #undef HAVE_VSNPRINTF_S */
105 /* #undef HAVE_VSPRINTF_S */
106 /* #undef HAVE___DEBUGBREAK */
107 
108 #ifdef __GNUC__
109 
110 #include "pstdint.h"
111 #include <stdio.h>
112 #include <stdlib.h>
113 #include <string.h>
114 #include <errno.h>
115 #include <wchar.h>
116 #include <assert.h>
117 #include <pthread.h>
118 #include <unistd.h>
119 
120 #include "xstypedefs.h"
121 
122 #define LPSTR char *
123 #define _T(x) (x)
124 
125 #define _ASSERT assert
126 #define _ASSERTE assert
127 #define HMODULE void *
128 
129 #define LINUX_MBS_LENGTH 256
130 #define LINUX_MBS_MODELENGTH 5
131 
132 #ifdef __cplusplus
133 #define XSEXTC extern "C"
134 #else
135 #define XSEXTC
136 #endif
137 
138 #define __compat_always_deprecated(msg) __attribute__((deprecated(msg)))
139 #if 0
140 #define __compat_deprecated(msg) __compat_always_deprecated(msg)
141 #else
142 #define __compat_deprecated(msg)
143 #endif
144 #define __compat_defdeprecated __compat_deprecated("compat should be nicely merged into xstypes")
145 
146 #ifndef HAVE_SPRINTF_S
147 XSEXTC int32_t sprintf_s(char *dest, uint32_t num, const char *fmt, ...) __compat_defdeprecated;
148 #endif
149 
150 #ifndef HAVE_STRCPY_S
151 XSEXTC int32_t strcpy_s(char *dest, uint32_t size, const char *src) __compat_defdeprecated;
152 
153 #ifdef __cplusplus
154 template <uint32_t size>
155 int32_t strcpy_s(char (&dest)[size], const char *src) __compat_defdeprecated;
156 template <uint32_t size>
157 int32_t strcpy_s(char (&dest)[size], const char *src)
158 {
159  if (!src) return EINVAL;
160  if (size == 0 || size < strlen(src) + 1) return ERANGE;
161 
162  strcpy(dest, src);
163 
164  return 0;
165 }
166 #endif
167 #endif
168 
169 #ifndef HAVE_STRCAT_S
170 XSEXTC int32_t strcat_s(char *dest, uint32_t size, const char *src) __compat_defdeprecated;
171 
172 #ifdef __cplusplus
173 template <uint32_t size>
174 int32_t strncpy_s(char (&dest)[size], const char *src, uint32_t count) __compat_defdeprecated;
175 template <uint32_t size>
176 int32_t strncpy_s(char (&dest)[size], const char *src, uint32_t count)
177 {
178  if (!src) return EINVAL;
179  size_t itemsToAdd = (count < strlen(src) ? count : strlen(src));
180  if (size == 0 || size < itemsToAdd + 1) return ERANGE;
181 
182  strncpy(dest, src, count);
183 
184  return 0;
185 }
186 #endif
187 #endif
188 
189 #ifndef HAVE_STRNCPY_S
190 XSEXTC int32_t strncpy_s(char *dest, uint32_t size, const char *src, uint32_t count) __compat_defdeprecated;
191 
192 #ifdef __cplusplus
193 template <uint32_t size>
194 int32_t strcat_s(char (&dest)[size], const char *src) __compat_defdeprecated;
195 template <uint32_t size>
196 int32_t strcat_s(char (&dest)[size], const char *src)
197 {
198  if (!src) return EINVAL;
199  if (size == 0 || size < strlen(src) + strlen(dest) + 1) return ERANGE;
200 
201  strcat (dest, src);
202 
203  return 0;
204 }
205 #endif
206 #endif
207 
208 #ifndef HAVE_FOPEN_S
209 XSEXTC int fopen_s(FILE **file, const char *filename, const char *mode) __compat_deprecated("Use XsFile instead");
210 #endif
211 
212 #ifndef HAVE__STRICMP
213 #define _stricmp strcasecmp
214 #endif
215 #ifndef HAVE_STRICMP
216 #define stricmp strcasecmp
217 #endif
218 #ifndef HAVE__STRNICMP
219 #define _strnicmp strncasecmp
220 #endif
221 #ifndef HAVE_STRICMP
222 #define strnicmp strncasecmp
223 #endif
224 
225 /* not available on cygwin */
226 #ifdef HAVE_WCSCASECMP
227 #define _wcsicmp wcscasecmp
228 #else
229 #define _wcsicmp(s1, s2) compat_wcsnicmp(s1, s2, 0x7fffffff)
230 XSEXTC int compat_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t length) __compat_defdeprecated;
231 #endif
232 
233 /* not available on cygwin */
234 #ifdef HAVE_WCSNCASECMP
235 #define _wcsnicmp wcsncasecmp
236 #else
237 #define _wcsnicmp(s1, s2, n) compat_wcsnicmp(s1, s2, n)
238 XSEXTC int compat_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t length) __compat_defdeprecated;
239 #endif
240 
241 #define _wfopen wfopen
242 #ifndef HAVE_WFOPEN
243 #define wfopen compat_wfopen
244 XSEXTC FILE *compat_wfopen(const wchar_t *filename, const wchar_t *mode) __compat_deprecated("Use XsFile instead");
245 #endif
246 
247 #define _wfreopen wfreopen
248 #ifndef HAVE_WFREOPEN
249 #define wfreopen compat_wfreopen
250 XSEXTC FILE *compat_wfreopen(const wchar_t *path, const wchar_t *mode, FILE *) __compat_deprecated("Use XsFile instead");
251 #endif
252 
253 #define _set_printf_count_output(x)
254 
255 #ifndef HAVE__STRDUP
256 #define _strdup strdup
257 #endif
258 
259 #ifndef HAVE__WCSDUP
260 #ifdef HAVE_WCSDUP
261 #define _wcsdup wcsdup
262 #else
263 #define _wcsdup compat_wcsdup
264 #endif
265 #endif
266 XSEXTC wchar_t *compat_wcsdup(const wchar_t *data) __compat_defdeprecated;
267 
268 #ifndef HAVE_FULLPATH
269 #define fullpath(src,dest,len) realpath(src,dest)
270 #endif
271 #ifndef HAVE__FULLPATH
272 #define _fullpath fullpath
273 #endif
274 
275 #ifndef HAVE__WFULLPATH
276 #define _wfullpath compat_wfullpath
277 XSEXTC int32_t compat_wfullpath(wchar_t *resolvedPath, const wchar_t *path, size_t length) __compat_deprecated("Use Xsfile_fullPath instead");
278 #endif
279 
280 #ifndef HAVE_STRTOK_S
281 XSEXTC char *strtok_s(char *token, const char *delim, char **context) __compat_defdeprecated;
282 #endif
283 
284 #ifndef _finite
285 #define _finite compat_finite
286 XSEXTC int compat_finite(XsReal x) __compat_deprecated("Use XsMath_isFinite instead");
287 #endif
288 
289 #define LOBYTE(w) ((uint8_t)((w) & 0xff))
290 #define HIBYTE(w) ((uint8_t)(((w) >> 8) & 0xff))
291 
292 #define __assume(val)
293 
294 #if !defined(HAVE_CDECL)
295 # if !defined(__cdecl)
296 # if defined(__x86_64__)
297 # define __cdecl
298 # else
299 # define __cdecl __attribute__((cdecl))
300 # endif
301 # endif
302 # if !defined(__stdcall)
303 # if defined(__x86_64__)
304 # define __stdcall
305 # else
306 # define __stdcall __attribute__((stdcall))
307 # endif
308 # endif
309 #endif
310 
311 #ifndef HAVE__UNLINK
312 #define _unlink unlink
313 #endif
314 #ifndef HAVE___DEBUGBREAK
315 #define __debugbreak()
316 #endif
317 #ifndef HAVE__FILENO
318 #define _fileno fileno
319 #endif
320 #ifndef HAVE__STRDUP
321 #define _strdup strdup
322 #endif
323 #ifndef HAVE__ISNAN
324 #define _isnan isnan
325 #endif
326 
327 #ifndef GetRValue
328 /* The others will most likely not be defined either */
329 #define GetRValue(rgb) ((uint8_t)(rgb))
330 #define GetGValue(rgb) ((uint8_t)(((uint32_t)(rgb)) >> 8))
331 #define GetBValue(rgb) ((uint8_t)(((uint32_t)(rgb)) >> 16))
332 #endif
333 
334 typedef pthread_mutex_t CRITICAL_SECTION __compat_deprecated("Use XsMutex instead");
335 
336 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
337 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
338 static inline void EnterCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
339 static inline int TryEnterCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
340 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
341 
342 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_init(cs, 0); }
343 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_destroy(cs); }
344 static inline void EnterCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_lock(cs); }
345 static inline int TryEnterCriticalSection(CRITICAL_SECTION *cs) { return (pthread_mutex_trylock(cs) == 0); }
346 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_unlock(cs); }
347 
348 #ifndef DWORD
349 # define DWORD uint32_t
350 #endif
351 
352 XSEXTC int IsBadWritePtr(void *p, size_t size);
353 
354 #ifndef HAVE_VSNPRINTF_S
355 #define _TRUNCATE 1
356 #define vsnprintf_s(str, size, thingy, fmt, vp) vsnprintf(str, size, fmt, vp)
357 #endif
358 #ifndef HAVE_VSPRINTF_S
359 #define vsprintf_s(str, size, format, args) vsprintf(str, format, args)
360 #endif
361 
362 // MRO (10/24/2013): Linux compiler does not support override keyword yet
363 // \todo Remove override define when linux compiler supports it
364 #ifdef __GNUC__
365 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 7)
366  // override keyword supported
367 #else
368  #define override
369 #endif
370 #endif
371 
372 #endif // __GNUC__
373 #endif // __XSENS_LINUX_H
xstypedefs.h
strcat_s
#define strcat_s(dst, len, src)
Definition: stackwalker.cpp:255
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
XsReal
double XsReal
Defines the floating point type used by the Xsens libraries.
Definition: xstypedefs.h:73
pstdint.h
strcpy_s
#define strcpy_s
Definition: stackwalker.cpp:254
int32_t
signed int int32_t
Definition: pstdint.h:515
assert.h


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20