diff --git a/libretro-common/streams/file_stream.c b/libretro-common/streams/file_stream.c index 77178b9fc9..12d5498d88 100644 --- a/libretro-common/streams/file_stream.c +++ b/libretro-common/streams/file_stream.c @@ -78,10 +78,17 @@ struct RFILE #define HAVE_BUFFERED_IO 1 +#if (defined(_MSC_VER) && _MSC_VER < 1400) || defined(_XBOX) || !defined(_WIN32) #define MODE_STR_READ "r" #define MODE_STR_READ_UNBUF "rb" #define MODE_STR_WRITE_UNBUF "wb" #define MODE_STR_WRITE_PLUS "w+" +#else +#define MODE_STR_READ L"r" +#define MODE_STR_READ_UNBUF L"rb" +#define MODE_STR_WRITE_UNBUF L"wb" +#define MODE_STR_WRITE_PLUS L"w+" +#endif #if defined(HAVE_BUFFERED_IO) FILE *fp; @@ -138,11 +145,16 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len) int flags = 0; int mode_int = 0; #if defined(HAVE_BUFFERED_IO) +#if (defined(_MSC_VER) && _MSC_VER < 1400) || defined(_XBOX) || !defined(_WIN32) const char *mode_str = NULL; +#else + const wchar_t *mode_str = NULL; +#endif #endif RFILE *stream = (RFILE*)calloc(1, sizeof(*stream)); #if defined(_WIN32) && !defined(_XBOX) char *path_local = NULL; + wchar_t *path_wide = NULL; #endif if (!stream) @@ -233,10 +245,19 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0 && mode_str) { #if defined(_WIN32) && !defined(_XBOX) +#if defined(_MSC_VER) && _MSC_VER < 1400 || defined(_XBOX) + (void)path_wide; path_local = utf8_to_local_string_alloc(path); stream->fp = fopen(path_local, mode_str); if (path_local) free(path_local); +#else + (void)path_local; + path_wide = utf8_to_utf16_string_alloc(path); + stream->fp = _wfopen(path_wide, mode_str); + if (path_wide) + free(path_wide); +#endif #else stream->fp = fopen(path, mode_str); #endif @@ -248,10 +269,19 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len) { /* FIXME: HAVE_BUFFERED_IO is always 1, but if it is ever changed, open() needs to be changed to _wopen() for WIndows. */ #if defined(_WIN32) && !defined(_XBOX) +#if defined(_MSC_VER) && _MSC_VER < 1400 || defined(_XBOX) + (void)path_wide; path_local = utf8_to_local_string_alloc(path); stream->fd = open(path_local, flags, mode_int); if (path_local) free(path_local); +#else + (void)path_local; + path_wide = utf8_to_utf16_string_alloc(path); + stream->fd = _wopen(path_wide, flags, mode_int); + if (path_wide) + free(path_wide); +#endif #else stream->fd = open(path, flags, mode_int); #endif