Debian Codegraph @

3rdparty/xspublic/xstypes/xsens_compat.h

raw
1
2 // Copyright (c) 2003-2019 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 #ifndef __XSENS_LINUX_H
34 #define __XSENS_LINUX_H
35
36 /* #undef HAVE_STRTOK_S */
37 /* #undef HAVE_STRTOK_R */
38 /* #undef HAVE__WCSICMP */
39 /* #undef HAVE_WCSICMP */
40 /* #undef HAVE__WCSNICMP */
41 /* #undef HAVE_WCSNICMP */
42 #define HAVE_WCSNCASECMP 1
43 #define HAVE_WCSCASECMP 1
44 /* #undef HAVE_SPRINTF_S */
45 /* #undef HAVE_STRCPY_S */
46 /* #undef HAVE_STRCAT_S */
47 /* #undef HAVE_STRNCPY_S */
48 /* #undef HAVE_FOPEN_S */
49 /* #undef HAVE_STRICMP */
50 /* #undef HAVE__STRICMP */
51 #define HAVE_STRCASECMP 1
52 /* #undef HAVE_STRNICMP */
53 /* #undef HAVE__STRNICMP */
54 #define HAVE_STRNCASECMP 1
55 /* #undef HAVE_WFOPEN */
56 /* #undef HAVE__WFOPEN */
57 /* #undef HAVE__STRDUP */
58 #define HAVE_STRDUP 1
59 /* #undef HAVE__WCSDUP */
60 #define HAVE_WCSDUP 1
61 /* #undef HAVE__FULLPATH */
62 /* #undef HAVE_FULLPATH */
63 #define HAVE_REALPATH 1
64 /* #undef HAVE_WFULLPATH */
65 /* #undef HAVE_WFREOPEN */
66 /* #undef HAVE__UNLINK */
67 #define HAVE_UNLINK 1
68 /* #undef HAVE__ISNAN */
69 #define HAVE_ISNAN 1
70 /* #undef HAVE__FILENO */
71 #define HAVE_FILENO 1
72 /* #undef HAVE_VSNPRINTF_S */
73 /* #undef HAVE_VSPRINTF_S */
74 /* #undef HAVE___DEBUGBREAK */
75
76 #ifdef __GNUC__
77
78 #include "pstdint.h"
79 #include <stdio.h>
80 #include <stdlib.h>
81 #include <string.h>
82 #include <errno.h>
83 #include <wchar.h>
84 #include <assert.h>
85 #include <pthread.h>
86 #include <unistd.h>
87
88 #include "xstypedefs.h"
89
90 #define LPSTR char *
91 #define _T
92
93 #define _ASSERT assert
94 #define _ASSERTE assert
95 #define HMODULE void *
96
97 #define LINUX_MBS_LENGTH 256
98 #define LINUX_MBS_MODELENGTH 5
99
100 #ifdef __cplusplus
101 #define XSEXTC extern "C"
102 #else
103 #define XSEXTC
104 #endif
105
106 #define __compat_always_deprecated(msg) __attribute__((deprecated(msg)))
107 #if 0
108 #define __compat_deprecated(msg) __compat_always_deprecated(msg)
109 #else
110 #define __compat_deprecated(msg)
111 #endif
112 #define __compat_defdeprecated __compat_deprecated("compat should be nicely merged into xstypes")
113
114 #ifndef HAVE_SPRINTF_S
115 XSEXTC int32_t sprintf_s(char *dest, uint32_t num, const char *fmt, ...) __compat_defdeprecated;
116 #endif
117
118 #ifndef HAVE_STRCPY_S
119 XSEXTC int32_t strcpy_s(char *dest, uint32_t size, const char *src) __compat_defdeprecated;
120
121 #ifdef __cplusplus
122 template <uint32_t size>
123 int32_t strcpy_s(char (&dest)[size], const char *src) __compat_defdeprecated;
124 template <uint32_t size>
125 int32_t strcpy_s(char (&dest)[size], const char *src)
126 {
127 if (!src) return EINVAL;
128 if (size == 0 || size < strlen(src) + 1) return ERANGE;
129
130 strcpy(dest, src);
131
132 return 0;
133 }
134 #endif
135 #endif
136
137 #ifndef HAVE_STRCAT_S
138 XSEXTC int32_t strcat_s(char *dest, uint32_t size, const char *src) __compat_defdeprecated;
139
140 #ifdef __cplusplus
141 template <uint32_t size>
142 int32_t strncpy_s(char (&dest)[size], const char *src, uint32_t count) __compat_defdeprecated;
143 template <uint32_t size>
144 int32_t strncpy_s(char (&dest)[size], const char *src, uint32_t count)
145 {
146 if (!src) return EINVAL;
147 uint32_t itemsToAdd = (count < strlen(src) ? count : strlen(src));
148 if (size == 0 || size < itemsToAdd + 1) return ERANGE;
149
150 strncpy(dest, src, count);
151
152 return 0;
153 }
154 #endif
155 #endif
156
157 #ifndef HAVE_STRNCPY_S
158 XSEXTC int32_t strncpy_s(char *dest, uint32_t size, const char *src, uint32_t count) __compat_defdeprecated;
159
160 #ifdef __cplusplus
161 template <uint32_t size>
162 int32_t strcat_s(char (&dest)[size], const char *src) __compat_defdeprecated;
163 template <uint32_t size>
164 int32_t strcat_s(char (&dest)[size], const char *src)
165 {
166 if (!src) return EINVAL;
167 if (size == 0 || size < strlen(src) + strlen(dest) + 1) return ERANGE;
168
169 strcat (dest, src);
170
171 return 0;
172 }
173 #endif
174 #endif
175
176 #ifndef HAVE_FOPEN_S
177 XSEXTC int fopen_s(FILE **file, const char *filename, const char *mode) __compat_deprecated("Use XsFile instead");
178 #endif
179
180 #ifndef HAVE__STRICMP
181 #define _stricmp strcasecmp
182 #endif
183 #ifndef HAVE_STRICMP
184 #define stricmp strcasecmp
185 #endif
186 #ifndef HAVE__STRNICMP
187 #define _strnicmp strncasecmp
188 #endif
189 #ifndef HAVE_STRICMP
190 #define strnicmp strncasecmp
191 #endif
192
193 /* not available on cygwin */
194 #ifdef HAVE_WCSCASECMP
195 #define _wcsicmp wcscasecmp
196 #else
197 #define _wcsicmp(s1, s2) compat_wcsnicmp(s1, s2, 0x7fffffff)
198 XSEXTC int compat_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t length) __compat_defdeprecated;
199 #endif
200
201 /* not available on cygwin */
202 #ifdef HAVE_WCSNCASECMP
203 #define _wcsnicmp wcsncasecmp
204 #else
205 #define _wcsnicmp(s1, s2, n) compat_wcsnicmp(s1, s2, n)
206 XSEXTC int compat_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t length) __compat_defdeprecated;
207 #endif
208
209 #define _wfopen wfopen
210 #ifndef HAVE_WFOPEN
211 #define wfopen compat_wfopen
212 XSEXTC FILE *compat_wfopen(const wchar_t *filename, const wchar_t *mode) __compat_deprecated("Use XsFile instead");
213 #endif
214
215 #define _wfreopen wfreopen
216 #ifndef HAVE_WFREOPEN
217 #define wfreopen compat_wfreopen
218 XSEXTC FILE *compat_wfreopen(const wchar_t *path, const wchar_t *mode, FILE *) __compat_deprecated("Use XsFile instead");
219 #endif
220
221 #define _set_printf_count_output(x)
222
223 #ifndef HAVE__STRDUP
224 #define _strdup strdup
225 #endif
226
227 #ifndef HAVE__WCSDUP
228 #ifdef HAVE_WCSDUP
229 #define _wcsdup wcsdup
230 #else
231 #define _wcsdup compat_wcsdup
232 #endif
233 #endif
234 XSEXTC wchar_t *compat_wcsdup(const wchar_t *data) __compat_defdeprecated;
235
236 #ifndef HAVE_FULLPATH
237 #define fullpath(src,dest,len) realpath(src,dest)
238 #endif
239 #ifndef HAVE__FULLPATH
240 #define _fullpath fullpath
241 #endif
242
243 #ifndef HAVE__WFULLPATH
244 #define _wfullpath compat_wfullpath
245 XSEXTC int32_t compat_wfullpath(wchar_t *resolvedPath, const wchar_t *path, size_t length) __compat_deprecated("Use Xsfile_fullPath instead");
246 #endif
247
248 #ifndef HAVE_STRTOK_S
249 XSEXTC char *strtok_s(char *token, const char *delim, char **context) __compat_defdeprecated;
250 #endif
251
252 #ifndef _finite
253 #define _finite compat_finite
254 XSEXTC int compat_finite(XsReal x) __compat_deprecated("Use XsMath_isFinite instead");
255 #endif
256
257 #define LOBYTE(w) ((uint8_t)((w) & 0xff))
258 #define HIBYTE(w) ((uint8_t)(((w) >> 8) & 0xff))
259
260 #define __assume(val)
261
262 #if !defined(HAVE_CDECL)
263 # if !defined(__cdecl)
264 # if defined(__x86_64__)
265 # define __cdecl
266 # else
267 # define __cdecl __attribute__((cdecl))
268 # endif
269 # endif
270 # if !defined(__stdcall)
271 # if defined(__x86_64__)
272 # define __stdcall
273 # else
274 # define __stdcall __attribute__((stdcall))
275 # endif
276 # endif
277 #endif
278
279 #ifndef HAVE__UNLINK
280 #define _unlink unlink
281 #endif
282 #ifndef HAVE___DEBUGBREAK
283 #define __debugbreak()
284 #endif
285 #ifndef HAVE__FILENO
286 #define _fileno fileno
287 #endif
288 #ifndef HAVE__STRDUP
289 #define _strdup strdup
290 #endif
291 #ifndef HAVE__ISNAN
292 #define _isnan isnan
293 #endif
294
295 #ifndef GetRValue
296 /* The others will most likely not be defined either */
297 #define GetRValue(rgb) ((uint8_t)(rgb))
298 #define GetGValue(rgb) ((uint8_t)(((uint32_t)(rgb)) >> 8))
299 #define GetBValue(rgb) ((uint8_t)(((uint32_t)(rgb)) >> 16))
300 #endif
301
302 typedef pthread_mutex_t CRITICAL_SECTION __compat_deprecated("Use XsMutex instead");
303
304 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
305 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
306 static inline void EnterCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
307 static inline int TryEnterCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
308 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs) __compat_deprecated("Use XsMutex instead");
309
310 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_init(cs, 0); }
311 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_destroy(cs); }
312 static inline void EnterCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_lock(cs); }
313 static inline int TryEnterCriticalSection(CRITICAL_SECTION *cs) { return (pthread_mutex_trylock(cs) == 0); }
314 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_unlock(cs); }
315
316 #ifndef DWORD
317 # define DWORD uint32_t
318 #endif
319
320 XSEXTC int IsBadWritePtr(void *p, size_t size);
321
322 #ifndef HAVE_VSNPRINTF_S
323 #define _TRUNCATE 1
324 #define vsnprintf_s(str, size, thingy, fmt, vp) vsnprintf(str, size, fmt, vp)
325 #endif
326 #ifndef HAVE_VSPRINTF_S
327 #define vsprintf_s(str, size, format, args) vsprintf(str, format, args)
328 #endif
329
330 // MRO (10/24/2013): Linux compiler does not support override keyword yet
331 // \todo Remove override define when linux compiler supports it
332 #ifdef __GNUC__
333 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 7)
334 // override keyword supported
335 #else
336 #define override
337 #endif
338 #endif
339
340 #endif // __GNUC__
341 #endif // __XSENS_LINUX_H