From 4d249acdee22b524ddbe8fd37370fcfd05b2c498 Mon Sep 17 00:00:00 2001 From: David Reid Date: Thu, 19 Dec 2019 18:41:11 +1000 Subject: [PATCH] Try fixing some compilation errors when compiling with MinGW. Public issue #114. --- miniaudio.h | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index dec5b081..ab101430 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -3342,8 +3342,11 @@ IMPLEMENTATION #include /* For INT_MAX */ #include /* sin(), etc. */ -#if defined(MA_DEBUG_OUTPUT) -#include /* for printf() for debug output */ +#if !defined(MA_NO_STDIO) || defined(MA_DEBUG_OUTPUT) +#include +#if !defined(_MSC_VER) && !defined(__DMC__) +#include /* For strcasecmp(). */ +#include /* For wcslen(), wcsrtombs() */ #endif #ifdef MA_WIN32 @@ -34862,13 +34865,6 @@ ma_result ma_decoder_init_memory_raw(const void* pData, size_t dataSize, const m return ma_decoder_init_raw__internal(pConfigIn, &config, pDecoder); } -#ifndef MA_NO_STDIO -#include -#if !defined(_MSC_VER) && !defined(__DMC__) -#include /* For strcasecmp(). */ -#include /* For wcsrtombs() */ -#endif - const char* ma_path_file_name(const char* path) { const char* fileName; @@ -35079,6 +35075,23 @@ ma_result ma_decoder__preinit_file(const char* pFilePath, const ma_decoder_confi return MA_SUCCESS; } +/* +_wfopen() isn't always available in all compilation environments. + + * Windows only. + * MSVC seems to support it universally as far back as VC6 from what I can tell (haven't checked further back). + * MinGW-64 (both 32- and 64-bit) seems to support it. + * MinGW wraps it in !defined(__STRICT_ANSI__). + +This can be reviewed as compatibility issues arise. The preference is to use _wfopen_s() and _wfopen() as opposed to the wcsrtombs() +fallback, so if you notice your compiler not detecting this properly I'm happy to look at adding support. +*/ +#if defined(_WIN32) + #if defined(_MSC_VER) || defined(__MINGW64__) || !defined(__STRICT_ANSI__) + #define MA_HAS_WFOPEN + #endif +#endif + ma_result ma_decoder__preinit_file_w(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { FILE* pFile; @@ -35093,7 +35106,7 @@ ma_result ma_decoder__preinit_file_w(const wchar_t* pFilePath, const ma_decoder_ return MA_INVALID_ARGS; } -#if defined(_WIN32) +#if defined(MA_HAS_WFOPEN) /* Use _wfopen() on Windows. */ #if defined(_MSC_VER) && _MSC_VER >= 1400 if (_wfopen_s(&pFile, pFilePath, L"rb") != 0) {