SDL: Fixed building without HAVE_LIBC on Windows

From ff01d0b56853958c4e3d9cd0bef32407ec550947 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 17 Feb 2024 08:12:10 -0800
Subject: [PATCH] Fixed building without HAVE_LIBC on Windows

Fixes https://github.com/libsdl-org/SDL/issues/9064
---
 src/stdlib/SDL_memcpy.c  |  4 ++--
 src/stdlib/SDL_memmove.c | 18 ++++++++++++++++++
 src/stdlib/SDL_memset.c  |  4 ++--
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/stdlib/SDL_memcpy.c b/src/stdlib/SDL_memcpy.c
index 139eb420d4f0..d8cc81bdcfa3 100644
--- a/src/stdlib/SDL_memcpy.c
+++ b/src/stdlib/SDL_memcpy.c
@@ -81,7 +81,7 @@ void *SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void
 
 /* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls.
    We will provide our own implementation if we're not building with a C runtime. */
-#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(_MT)
+#ifndef HAVE_LIBC
 /* NOLINTNEXTLINE(readability-redundant-declaration) */
 extern void *memcpy(void *dst, const void *src, size_t len);
 #ifndef __INTEL_LLVM_COMPILER
@@ -96,4 +96,4 @@ void *memcpy(void *dst, const void *src, size_t len)
 {
     return SDL_memcpy(dst, src, len);
 }
-#endif /* (_MSC_VER >= 1400) && !defined(_MT) */
+#endif /* !HAVE_LIBC */
diff --git a/src/stdlib/SDL_memmove.c b/src/stdlib/SDL_memmove.c
index 1daed2ffb4a2..675869105868 100644
--- a/src/stdlib/SDL_memmove.c
+++ b/src/stdlib/SDL_memmove.c
@@ -53,3 +53,21 @@ void *SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void
 #endif /* HAVE_MEMMOVE */
 }
 
+
+#ifndef HAVE_LIBC
+/* NOLINTNEXTLINE(readability-redundant-declaration) */
+extern void *memmove(void *dst, const void *src, size_t len);
+#ifndef __INTEL_LLVM_COMPILER
+#pragma intrinsic(memmove)
+#endif
+
+#ifndef __clang__
+#pragma function(memmove)
+#endif
+/* NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) */
+void *memmove(void *dst, const void *src, size_t len)
+{
+    return SDL_memmove(dst, src, len);
+}
+#endif /* !HAVE_LIBC */
+
diff --git a/src/stdlib/SDL_memset.c b/src/stdlib/SDL_memset.c
index 0c3579f86e2e..61ad5e8347df 100644
--- a/src/stdlib/SDL_memset.c
+++ b/src/stdlib/SDL_memset.c
@@ -118,7 +118,7 @@ void *SDL_memset4(void *dst, Uint32 val, size_t dwords)
 
 /* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls.
    We will provide our own implementation if we're not building with a C runtime. */
-#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(_MT)
+#ifndef HAVE_LIBC
 /* NOLINTNEXTLINE(readability-redundant-declaration) */
 extern void *memset(void *dst, int c, size_t len);
 #ifndef __INTEL_LLVM_COMPILER
@@ -133,5 +133,5 @@ void *memset(void *dst, int c, size_t len)
 {
     return SDL_memset(dst, c, len);
 }
-#endif /* (_MSC_VER >= 1400) && !defined(_MT) */
+#endif /* !HAVE_LIBC */