mirror of
https://github.com/libretro/RetroArch
synced 2025-04-25 00:02:31 +00:00
use wide fopen() on windows
This commit is contained in:
parent
8adafa9249
commit
187e1fc71b
@ -66,6 +66,7 @@
|
|||||||
|
|
||||||
#include <streams/file_stream.h>
|
#include <streams/file_stream.h>
|
||||||
#include <memmap.h>
|
#include <memmap.h>
|
||||||
|
#include <retro_miscellaneous.h>
|
||||||
|
|
||||||
struct RFILE
|
struct RFILE
|
||||||
{
|
{
|
||||||
@ -76,6 +77,18 @@ struct RFILE
|
|||||||
|
|
||||||
#define HAVE_BUFFERED_IO 1
|
#define HAVE_BUFFERED_IO 1
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#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+"
|
||||||
|
#else
|
||||||
|
#define MODE_STR_READ "r"
|
||||||
|
#define MODE_STR_READ_UNBUF "rb"
|
||||||
|
#define MODE_STR_WRITE_UNBUF "wb"
|
||||||
|
#define MODE_STR_WRITE_PLUS "w+"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
#endif
|
#endif
|
||||||
@ -104,7 +117,12 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
int flags = 0;
|
int flags = 0;
|
||||||
int mode_int = 0;
|
int mode_int = 0;
|
||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
|
#ifdef _WIN32
|
||||||
|
const wchar_t *mode_str = NULL;
|
||||||
|
wchar_t path_wide[PATH_MAX_LENGTH] = {0};
|
||||||
|
#else
|
||||||
const char *mode_str = NULL;
|
const char *mode_str = NULL;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
RFILE *stream = (RFILE*)calloc(1, sizeof(*stream));
|
RFILE *stream = (RFILE*)calloc(1, sizeof(*stream));
|
||||||
|
|
||||||
@ -132,7 +150,7 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
#else
|
#else
|
||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||||
mode_str = "r";
|
mode_str = MODE_STR_READ;
|
||||||
#endif
|
#endif
|
||||||
/* No "else" here */
|
/* No "else" here */
|
||||||
flags = O_RDONLY;
|
flags = O_RDONLY;
|
||||||
@ -145,7 +163,7 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
#else
|
#else
|
||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||||
mode_str = "rb";
|
mode_str = MODE_STR_READ_UNBUF;
|
||||||
#endif
|
#endif
|
||||||
/* No "else" here */
|
/* No "else" here */
|
||||||
flags = O_RDONLY;
|
flags = O_RDONLY;
|
||||||
@ -158,7 +176,7 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
#else
|
#else
|
||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||||
mode_str = "wb";
|
mode_str = MODE_STR_WRITE_UNBUF;
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -176,7 +194,7 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
#else
|
#else
|
||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||||
mode_str = "w+";
|
mode_str = MODE_STR_WRITE_PLUS;
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -195,13 +213,19 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, path, -1, path_wide, sizeof(path_wide) / sizeof(path_wide[0]));
|
||||||
|
stream->fp = _wfopen(path_wide, mode_str);
|
||||||
|
#else
|
||||||
stream->fp = fopen(path, mode_str);
|
stream->fp = fopen(path, mode_str);
|
||||||
|
#endif
|
||||||
if (!stream->fp)
|
if (!stream->fp)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
/* FIXME: HAVE_BUFFERED_IO is always 1, but if it is ever changed, open() needs to be changed to _wopen() for WIndows. */
|
||||||
stream->fd = open(path, flags);
|
stream->fd = open(path, flags);
|
||||||
if (stream->fd == -1)
|
if (stream->fd == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user