From 9f94041c09eb54ac89dc2a027b642bfdbdf58071 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Thu, 2 Apr 2020 15:06:14 -0400 Subject: [PATCH] VS2010 SDL_stdlib buildfixes --- mojoshader_common.c | 2 +- mojoshader_internal.h | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mojoshader_common.c b/mojoshader_common.c index bddacc25..8993ec69 100644 --- a/mojoshader_common.c +++ b/mojoshader_common.c @@ -578,7 +578,7 @@ int errorlist_add_va(ErrorList *list, const char *_fname, // In this case we make another copy of va and fetch the length only // with another call to _vscprintf -#ifdef _WIN32 +#if defined(_WIN32) && !defined(MOJOSHADER_USE_SDL_STDLIB) if (len == -1) { va_copy(ap, va); diff --git a/mojoshader_internal.h b/mojoshader_internal.h index 5ae4385c..6c26fb84 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -11,6 +11,9 @@ #ifdef MOJOSHADER_USE_SDL_STDLIB #include #include +#ifdef _MSC_VER +#include /* Needed for alloca :( */ +#endif /* stdint.h */ typedef Uint8 uint8; @@ -70,6 +73,11 @@ typedef Uint64 uint64; #undef memset #endif #define memset SDL_memset +#ifdef strcat +#undef strcat +#endif +/* TODO: Move MojoShader away from strcat! This len is awful! */ +#define strcat(dst, src) SDL_strlcat(dst, src, SDL_strlen(src) + 1) #ifdef strcpy #undef strcpy #endif @@ -183,17 +191,20 @@ typedef unsigned int uint; // this is a printf() helper. don't use for code. // Locale-independent float printing replacement for snprintf size_t MOJOSHADER_printFloat(char *text, size_t maxlen, float arg); -#ifndef MOJOSHADER_USE_SDL_STDLIB #ifdef _MSC_VER #include -#include -#define va_copy(a, b) a = b -#define snprintf _snprintf // !!! FIXME: not a safe replacement! -#define vsnprintf _vsnprintf // !!! FIXME: not a safe replacement! #define isnan _isnan // !!! FIXME: not a safe replacement! #if _MSC_VER < 1900 // pre MSVC 2015 #define isinf(x) (!_finite(x)) // FIXME: not a safe replacement! #endif +#define va_copy(a, b) a = b +#endif + +#ifndef MOJOSHADER_USE_SDL_STDLIB +#ifdef _MSC_VER +#include +#define snprintf _snprintf // !!! FIXME: not a safe replacement! +#define vsnprintf _vsnprintf // !!! FIXME: not a safe replacement! #define strcasecmp stricmp #define strncasecmp strnicmp typedef unsigned __int8 uint8;