From b0ba509d8729bcf67b5f65a53f4a7e210b357fbc Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 25 May 2023 20:28:31 -0700
Subject: [PATCH] hidapi/windows: allow building on Windows, using the SDL C
runtime
Signed-off-by: Sam Lantinga <slouken@libsdl.org>
---
src/hidapi/SDL_hidapi_windows.h | 4 ++++
src/hidapi/windows/hid.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/src/hidapi/SDL_hidapi_windows.h b/src/hidapi/SDL_hidapi_windows.h
index c368863d863b..b1b6b4d672f7 100644
--- a/src/hidapi/SDL_hidapi_windows.h
+++ b/src/hidapi/SDL_hidapi_windows.h
@@ -20,10 +20,14 @@
*/
/* Define standard library functions in terms of SDL */
+#define HIDAPI_USING_SDL_RUNTIME
#define calloc SDL_calloc
#define free SDL_free
#define malloc SDL_malloc
#define memcmp SDL_memcmp
+#define snprintf SDL_snprintf
+#define strlen SDL_strlen
+#define _strnicmp SDL_strncasecmp
#define swprintf SDL_swprintf
#define towupper SDL_toupper
#define wcscmp SDL_wcscmp
diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c
index 98d5df4cd3e3..0c992b2d5685 100644
--- a/src/hidapi/windows/hid.c
+++ b/src/hidapi/windows/hid.c
@@ -57,9 +57,11 @@ typedef LONG NTSTATUS;
#include "hidapi_hidclass.h"
#include "hidapi_hidsdi.h"
+#ifndef HIDAPI_USING_SDL_RUNTIME
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#endif
#ifdef MIN
#undef MIN