Simple Directmedia Layer
at main 4.3 kB view raw
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22/* Define standard library functions in terms of SDL */ 23 24/* #pragma push_macro/pop_macro works correctly only as of gcc >= 4.4.3 25 clang-3.0 _seems_ to be OK. */ 26#pragma push_macro("calloc") 27#pragma push_macro("malloc") 28#pragma push_macro("realloc") 29#pragma push_macro("free") 30#pragma push_macro("iconv_t") 31#pragma push_macro("iconv") 32#pragma push_macro("iconv_open") 33#pragma push_macro("iconv_close") 34#pragma push_macro("setlocale") 35#pragma push_macro("snprintf") 36#pragma push_macro("strcmp") 37#pragma push_macro("strdup") 38#pragma push_macro("strncpy") 39#pragma push_macro("tolower") 40#pragma push_macro("wcscmp") 41#pragma push_macro("wcsdup") 42#pragma push_macro("wcsncpy") 43 44#undef calloc 45#undef malloc 46#undef realloc 47#undef free 48#undef iconv_t 49#undef iconv 50#undef iconv_open 51#undef iconv_close 52#undef setlocale 53#undef snprintf 54#undef strcmp 55#undef strdup 56#undef strncpy 57#undef tolower 58#undef wcscmp 59#undef wcsdup 60#undef wcsncpy 61 62#define calloc SDL_calloc 63#define malloc SDL_malloc 64#define realloc SDL_realloc 65#define free SDL_free 66#define iconv_t SDL_iconv_t 67#ifndef ICONV_CONST 68#define ICONV_CONST 69#define UNDEF_ICONV_CONST 70#endif 71#define iconv(a,b,c,d,e) SDL_iconv(a, (const char **)b, c, d, e) 72#define iconv_open SDL_iconv_open 73#define iconv_close SDL_iconv_close 74#define setlocale(X, Y) NULL 75#define snprintf SDL_snprintf 76#define strcmp SDL_strcmp 77#define strdup SDL_strdup 78#define strncpy SDL_strlcpy 79#define tolower SDL_tolower 80#define wcscmp SDL_wcscmp 81#define wcsdup SDL_wcsdup 82#define wcsncpy SDL_wcslcpy 83 84 85#ifndef SDL_PLATFORM_FREEBSD 86/* this is awkwardly inlined, so we need to re-implement it here 87 * so we can override the libusb_control_transfer call */ 88static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev, 89 uint8_t descriptor_index, uint16_t lang_id, 90 unsigned char *data, int length) 91{ 92 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id, 93 data, (uint16_t)length, 1000); /* Endpoint 0 IN */ 94} 95#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor 96#endif /* SDL_PLATFORM_FREEBSD */ 97 98#define HIDAPI_THREAD_MODEL_INCLUDE "hidapi_thread_sdl.h" 99#ifndef LIBUSB_API_VERSION 100#ifdef LIBUSBX_API_VERSION 101#define LIBUSB_API_VERSION LIBUSBX_API_VERSION 102#else 103#define LIBUSB_API_VERSION 0x0 104#endif 105#endif 106/* we need libusb >= 1.0.16 because of libusb_get_port_numbers */ 107/* we don't need libusb_wrap_sys_device: */ 108#define HIDAPI_TARGET_LIBUSB_API_VERSION 0x01000102 109 110#undef HIDAPI_H__ 111#include "libusb/hid.c" 112 113/* restore libc function macros */ 114#ifdef UNDEF_ICONV_CONST 115#undef ICONV_CONST 116#undef UNDEF_ICONV_CONST 117#endif 118#pragma pop_macro("calloc") 119#pragma pop_macro("malloc") 120#pragma pop_macro("realloc") 121#pragma pop_macro("free") 122#pragma pop_macro("iconv_t") 123#pragma pop_macro("iconv") 124#pragma pop_macro("iconv_open") 125#pragma pop_macro("iconv_close") 126#pragma pop_macro("setlocale") 127#pragma pop_macro("snprintf") 128#pragma pop_macro("strcmp") 129#pragma pop_macro("strdup") 130#pragma pop_macro("strncpy") 131#pragma pop_macro("tolower") 132#pragma pop_macro("wcscmp") 133#pragma pop_macro("wcsdup") 134#pragma pop_macro("wcsncpy")