Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Merged r3201:3204 from branches/SDL-1.2: win32 rwops tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 10, 2007
1 parent 88f1cb5 commit 8b2b8b1
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/file/SDL_rwops.c
Expand Up @@ -59,6 +59,11 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
if (!context)
return -1; /* failed (invalid call) */

context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
context->hidden.win32io.buffer.data = NULL;
context->hidden.win32io.buffer.size = 0;
context->hidden.win32io.buffer.left = 0;

/* "r" = reading, file must exist */
/* "w" = writing, truncate existing, file may not exist */
/* "r+"= reading or writing, file must exist */
Expand All @@ -77,15 +82,23 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
if (!r_right && !w_right) /* inconsistent mode */
return -1; /* failed (invalid call) */

context->hidden.win32io.buffer.data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE);
if (!context->hidden.win32io.buffer.data) {
SDL_OutOfMemory();
return -1;
}

#ifdef _WIN32_WCE
{
size_t size = SDL_strlen(filename) + 1;
wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);

if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) ==
0) {
SDL_SetError("Unable to convert filename to Unicode");
SDL_stack_free(filenameW);
SDL_free(context->hidden.win32io.buffer.data);
context->hidden.win32io.buffer.data = NULL;
SDL_SetError("Unable to convert filename to Unicode");
return -1;
}
h = CreateFile(filenameW, (w_right | r_right),
Expand All @@ -109,22 +122,14 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
#endif /* _WIN32_WCE */

if (h == INVALID_HANDLE_VALUE) {
SDL_free(context->hidden.win32io.buffer.data);
context->hidden.win32io.buffer.data = NULL;
SDL_SetError("Couldn't open %s", filename);
return -2; /* failed (CreateFile) */
}
context->hidden.win32io.h = h;
context->hidden.win32io.append = a_mode ? SDL_TRUE : SDL_FALSE;

context->hidden.win32io.buffer.data =
(char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
if (!context->hidden.win32io.buffer.data) {
SDL_OutOfMemory();
CloseHandle(context->hidden.win32io.h);
return -1;
}
context->hidden.win32io.buffer.size = 0;
context->hidden.win32io.buffer.left = 0;

return 0; /* ok */
}
static long SDLCALL
Expand Down

0 comments on commit 8b2b8b1

Please sign in to comment.