From f3aceefe8451bebb07d1fe63e9e396827e1a3a69 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Wed, 18 Oct 2017 12:30:44 -0400 Subject: [PATCH] win32: use W-functions for nbio file IO too --- libretro-common/file/nbio/nbio_stdio.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libretro-common/file/nbio/nbio_stdio.c b/libretro-common/file/nbio/nbio_stdio.c index 826d7a496d..f7c46a48e5 100644 --- a/libretro-common/file/nbio/nbio_stdio.c +++ b/libretro-common/file/nbio/nbio_stdio.c @@ -2,6 +2,16 @@ #include #include +#include + +/* Assume W-functions do not work below VC2005 and Xbox platforms */ +#if defined(_MSC_VER) && _MSC_VER < 1400 || defined(_XBOX) + +#ifndef LEGACY_WIN32 +#define LEGACY_WIN32 +#endif + +#endif struct nbio_t { @@ -19,14 +29,26 @@ struct nbio_t signed char mode; }; +#if !defined(_WIN32) || defined(LEGACY_WIN32) static const char * modes[]={ "rb", "wb", "r+b", "rb", "wb", "r+b" }; +#else +static const wchar_t * modes[]={ L"rb", L"wb", L"r+b", L"rb", L"wb", L"r+b" }; +#endif struct nbio_t* nbio_open(const char * filename, unsigned mode) { void *buf = NULL; struct nbio_t* handle = NULL; size_t len = 0; +#if !defined(_WIN32) || defined(LEGACY_WIN32) FILE* f = fopen(filename, modes[mode]); +#else + wchar_t *filename_wide = utf8_to_utf16_string_alloc(filename); + FILE* f = _wfopen(filename_wide, modes[mode]); + + if (filename_wide) + free(filename_wide); +#endif if (!f) return NULL;