Path: blob/master/thirdparty/sdl/hidapi/SDL_hidapi_libusb.h
9898 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/* Define standard library functions in terms of SDL */2223/* #pragma push_macro/pop_macro works correctly only as of gcc >= 4.4.324clang-3.0 _seems_ to be OK. */25#pragma push_macro("calloc")26#pragma push_macro("malloc")27#pragma push_macro("realloc")28#pragma push_macro("free")29#pragma push_macro("iconv_t")30#pragma push_macro("iconv")31#pragma push_macro("iconv_open")32#pragma push_macro("iconv_close")33#pragma push_macro("setlocale")34#pragma push_macro("snprintf")35#pragma push_macro("strcmp")36#pragma push_macro("strdup")37#pragma push_macro("strncpy")38#pragma push_macro("tolower")39#pragma push_macro("wcscmp")40#pragma push_macro("wcsdup")41#pragma push_macro("wcsncpy")4243#undef calloc44#undef malloc45#undef realloc46#undef free47#undef iconv_t48#undef iconv49#undef iconv_open50#undef iconv_close51#undef setlocale52#undef snprintf53#undef strcmp54#undef strdup55#undef strncpy56#undef tolower57#undef wcscmp58#undef wcsdup59#undef wcsncpy6061#define calloc SDL_calloc62#define malloc SDL_malloc63#define realloc SDL_realloc64#define free SDL_free65#define iconv_t SDL_iconv_t66#ifndef ICONV_CONST67#define ICONV_CONST68#define UNDEF_ICONV_CONST69#endif70#define iconv(a,b,c,d,e) SDL_iconv(a, (const char **)b, c, d, e)71#define iconv_open SDL_iconv_open72#define iconv_close SDL_iconv_close73#define setlocale(X, Y) NULL74#define snprintf SDL_snprintf75#define strcmp SDL_strcmp76#define strdup SDL_strdup77#define strncpy SDL_strlcpy78#define tolower SDL_tolower79#define wcscmp SDL_wcscmp80#define wcsdup SDL_wcsdup81#define wcsncpy SDL_wcslcpy828384#ifndef SDL_PLATFORM_FREEBSD85/* this is awkwardly inlined, so we need to re-implement it here86* so we can override the libusb_control_transfer call */87static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,88uint8_t descriptor_index, uint16_t lang_id,89unsigned char *data, int length)90{91return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id,92data, (uint16_t)length, 1000); /* Endpoint 0 IN */93}94#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor95#endif /* SDL_PLATFORM_FREEBSD */9697#define HIDAPI_THREAD_MODEL_INCLUDE "hidapi_thread_sdl.h"98#ifndef LIBUSB_API_VERSION99#ifdef LIBUSBX_API_VERSION100#define LIBUSB_API_VERSION LIBUSBX_API_VERSION101#else102#define LIBUSB_API_VERSION 0x0103#endif104#endif105/* we need libusb >= 1.0.16 because of libusb_get_port_numbers */106/* we don't need libusb_wrap_sys_device: */107#define HIDAPI_TARGET_LIBUSB_API_VERSION 0x01000102108109#undef HIDAPI_H__110#include "libusb/hid.c"111112/* restore libc function macros */113#ifdef UNDEF_ICONV_CONST114#undef ICONV_CONST115#undef UNDEF_ICONV_CONST116#endif117#pragma pop_macro("calloc")118#pragma pop_macro("malloc")119#pragma pop_macro("realloc")120#pragma pop_macro("free")121#pragma pop_macro("iconv_t")122#pragma pop_macro("iconv")123#pragma pop_macro("iconv_open")124#pragma pop_macro("iconv_close")125#pragma pop_macro("setlocale")126#pragma pop_macro("snprintf")127#pragma pop_macro("strcmp")128#pragma pop_macro("strdup")129#pragma pop_macro("strncpy")130#pragma pop_macro("tolower")131#pragma pop_macro("wcscmp")132#pragma pop_macro("wcsdup")133#pragma pop_macro("wcsncpy")134135136