(file_stream.c) Cleanups; buildfix

This commit is contained in:
twinaphex 2017-12-10 22:10:32 +01:00
parent 1298a257ae
commit d19eaeaab8
1 changed files with 10 additions and 26 deletions

View File

@ -147,22 +147,16 @@ void filestream_set_size(RFILE *stream)
RFILE *filestream_open(const char *path, unsigned mode, ssize_t unused) RFILE *filestream_open(const char *path, unsigned mode, ssize_t unused)
{ {
int flags = 0; int flags = 0;
int mode_int = 0;
#if !defined(_WIN32) || defined(LEGACY_WIN32) #if !defined(_WIN32) || defined(LEGACY_WIN32)
const char *mode_str = NULL; const char *mode_str = NULL;
#else #else
const wchar_t *mode_str = NULL; const wchar_t *mode_str = NULL;
#endif #endif
RFILE *stream = (RFILE*)calloc(1, sizeof(*stream)); RFILE *stream = (RFILE*)calloc(1, sizeof(*stream));
#if defined(_WIN32) && !defined(_XBOX)
char *path_local = NULL;
wchar_t *path_wide = NULL;
#endif
if (!stream) if (!stream)
return NULL; return NULL;
(void)mode_int;
(void)flags; (void)flags;
stream->hints = mode; stream->hints = mode;
@ -176,12 +170,6 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t unused)
switch (mode & 0xff) switch (mode & 0xff)
{ {
case RFILE_MODE_READ_TEXT:
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
mode_str = MODE_STR_READ;
/* No "else" here */
flags = O_RDONLY;
break;
case RFILE_MODE_READ: case RFILE_MODE_READ:
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
mode_str = MODE_STR_READ_UNBUF; mode_str = MODE_STR_READ_UNBUF;
@ -215,15 +203,13 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t unused)
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0 && mode_str) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0 && mode_str)
{ {
#if defined(_WIN32) && !defined(_XBOX) #if defined(_WIN32) && !defined(_XBOX)
(void)path_local;
(void)path_wide;
#if defined(LEGACY_WIN32) #if defined(LEGACY_WIN32)
path_local = utf8_to_local_string_alloc(path); char *path_local = utf8_to_local_string_alloc(path);
stream->fp = fopen(path_local, mode_str); stream->fp = fopen(path_local, mode_str);
if (path_local) if (path_local)
free(path_local); free(path_local);
#else #else
path_wide = utf8_to_utf16_string_alloc(path); wchar_t * path_wide = utf8_to_utf16_string_alloc(path);
stream->fp = _wfopen(path_wide, mode_str); stream->fp = _wfopen(path_wide, mode_str);
if (path_wide) if (path_wide)
free(path_wide); free(path_wide);
@ -252,20 +238,18 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t unused)
{ {
#if defined(_WIN32) && !defined(_XBOX) #if defined(_WIN32) && !defined(_XBOX)
#if defined(LEGACY_WIN32) #if defined(LEGACY_WIN32)
(void)path_wide; char *path_local = utf8_to_local_string_alloc(path);
path_local = utf8_to_local_string_alloc(path); stream->fd = open(path_local, flags, 0);
stream->fd = open(path_local, flags, mode_int);
if (path_local) if (path_local)
free(path_local); free(path_local);
#else #else
(void)path_local; wchar_t * path_wide = utf8_to_utf16_string_alloc(path);
path_wide = utf8_to_utf16_string_alloc(path); stream->fd = _wopen(path_wide, flags, 0);
stream->fd = _wopen(path_wide, flags, mode_int);
if (path_wide) if (path_wide)
free(path_wide); free(path_wide);
#endif #endif
#else #else
stream->fd = open(path, flags, mode_int); stream->fd = open(path, flags, 0);
#endif #endif
if (stream->fd == -1) if (stream->fd == -1)
@ -532,7 +516,7 @@ int filestream_vprintf(RFILE *stream, const char* format, va_list args)
else if (num_chars == 0) else if (num_chars == 0)
return 0; return 0;
return filestream_write(stream, buffer, numChars); return filestream_write(stream, buffer, num_chars);
} }
int filestream_printf(RFILE *stream, const char* format, ...) int filestream_printf(RFILE *stream, const char* format, ...)