65 #ifndef __XSENS_LINUX_H
66 #define __XSENS_LINUX_H
74 #define HAVE_WCSNCASECMP 1
75 #define HAVE_WCSCASECMP 1
83 #define HAVE_STRCASECMP 1
86 #define HAVE_STRNCASECMP 1
95 #define HAVE_REALPATH 1
103 #define HAVE_FILENO 1
125 #define _ASSERT assert
126 #define _ASSERTE assert
127 #define HMODULE void *
129 #define LINUX_MBS_LENGTH 256
130 #define LINUX_MBS_MODELENGTH 5
133 #define XSEXTC extern "C"
138 #define __compat_always_deprecated(msg) __attribute__((deprecated(msg)))
140 #define __compat_deprecated(msg) __compat_always_deprecated(msg)
142 #define __compat_deprecated(msg)
144 #define __compat_defdeprecated __compat_deprecated("compat should be nicely merged into xstypes")
146 #ifndef HAVE_SPRINTF_S
147 XSEXTC
int32_t sprintf_s(
char *dest,
uint32_t num,
const char *fmt, ...) __compat_defdeprecated;
150 #ifndef HAVE_STRCPY_S
154 template <u
int32_t size>
155 int32_t strcpy_s(
char (&dest)[size],
const char *src) __compat_defdeprecated;
156 template <u
int32_t size>
159 if (!src)
return EINVAL;
160 if (size == 0 || size < strlen(src) + 1)
return ERANGE;
169 #ifndef HAVE_STRCAT_S
173 template <u
int32_t size>
174 int32_t strncpy_s(
char (&dest)[size],
const char *src,
uint32_t count) __compat_defdeprecated;
175 template <u
int32_t size>
178 if (!src)
return EINVAL;
179 size_t itemsToAdd = (count < strlen(src) ? count : strlen(src));
180 if (size == 0 || size < itemsToAdd + 1)
return ERANGE;
182 strncpy(dest, src, count);
189 #ifndef HAVE_STRNCPY_S
193 template <u
int32_t size>
194 int32_t strcat_s(
char (&dest)[size],
const char *src) __compat_defdeprecated;
195 template <u
int32_t size>
198 if (!src)
return EINVAL;
199 if (size == 0 || size < strlen(src) + strlen(dest) + 1)
return ERANGE;
209 XSEXTC
int fopen_s(FILE **file,
const char *filename,
const char *mode) __compat_deprecated(
"Use XsFile instead");
212 #ifndef HAVE__STRICMP
213 #define _stricmp strcasecmp
216 #define stricmp strcasecmp
218 #ifndef HAVE__STRNICMP
219 #define _strnicmp strncasecmp
222 #define strnicmp strncasecmp
226 #ifdef HAVE_WCSCASECMP
227 #define _wcsicmp wcscasecmp
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;
234 #ifdef HAVE_WCSNCASECMP
235 #define _wcsnicmp wcsncasecmp
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;
241 #define _wfopen wfopen
243 #define wfopen compat_wfopen
244 XSEXTC FILE *compat_wfopen(
const wchar_t *filename,
const wchar_t *mode) __compat_deprecated(
"Use XsFile instead");
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");
253 #define _set_printf_count_output(x)
256 #define _strdup strdup
261 #define _wcsdup wcsdup
263 #define _wcsdup compat_wcsdup
266 XSEXTC
wchar_t *compat_wcsdup(
const wchar_t *data) __compat_defdeprecated;
268 #ifndef HAVE_FULLPATH
269 #define fullpath(src,dest,len) realpath(src,dest)
271 #ifndef HAVE__FULLPATH
272 #define _fullpath fullpath
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");
280 #ifndef HAVE_STRTOK_S
281 XSEXTC
char *strtok_s(
char *token,
const char *delim,
char **context) __compat_defdeprecated;
285 #define _finite compat_finite
286 XSEXTC
int compat_finite(
XsReal x) __compat_deprecated(
"Use XsMath_isFinite instead");
289 #define LOBYTE(w) ((uint8_t)((w) & 0xff))
290 #define HIBYTE(w) ((uint8_t)(((w) >> 8) & 0xff))
292 #define __assume(val)
294 #if !defined(HAVE_CDECL)
295 # if !defined(__cdecl)
296 # if defined(__x86_64__)
299 # define __cdecl __attribute__((cdecl))
302 # if !defined(__stdcall)
303 # if defined(__x86_64__)
306 # define __stdcall __attribute__((stdcall))
312 #define _unlink unlink
314 #ifndef HAVE___DEBUGBREAK
315 #define __debugbreak()
318 #define _fileno fileno
321 #define _strdup strdup
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))
334 typedef pthread_mutex_t CRITICAL_SECTION __compat_deprecated(
"Use XsMutex instead");
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");
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); }
349 # define DWORD uint32_t
352 XSEXTC
int IsBadWritePtr(
void *p,
size_t size);
354 #ifndef HAVE_VSNPRINTF_S
356 #define vsnprintf_s(str, size, thingy, fmt, vp) vsnprintf(str, size, fmt, vp)
358 #ifndef HAVE_VSPRINTF_S
359 #define vsprintf_s(str, size, format, args) vsprintf(str, format, args)
365 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 7)
373 #endif // __XSENS_LINUX_H