diff options
author | Ryan C. Gordon <icculus@icculus.org> | 2007-07-10 19:06:02 +0000 |
---|---|---|
committer | Ryan C. Gordon <icculus@icculus.org> | 2007-07-10 19:06:02 +0000 |
commit | fe87971b628819ba5870863de6b9d21c68871aca (patch) | |
tree | cebdda52e963e937882da2db9494442fe3e2e648 /src/file | |
parent | 892d73c0611bdf617396fb4d4c90302561974918 (diff) |
Merged r3201:3204 from branches/SDL-1.2: win32 rwops tweaks.
Diffstat (limited to 'src/file')
-rw-r--r-- | src/file/SDL_rwops.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index d2166fc5b8..d43aaee0f2 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -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 */ @@ -77,6 +82,12 @@ 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; @@ -84,8 +95,10 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode) 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), @@ -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 |