Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
file if opening for write. --HG-- branch : SDL-1.2 extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402470
This commit is contained in:
parent
bfef646388
commit
a37ebaa8e6
1 changed files with 15 additions and 9 deletions
|
@ -57,6 +57,11 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
|
||||||
|
|
||||||
if (!context)
|
if (!context)
|
||||||
return -1; /* failed (invalid call) */
|
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 */
|
/* "r" = reading, file must exist */
|
||||||
/* "w" = writing, truncate existing, file may not exist */
|
/* "w" = writing, truncate existing, file may not exist */
|
||||||
|
@ -74,6 +79,12 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
|
||||||
if (!r_right && !w_right) /* inconsistent mode */
|
if (!r_right && !w_right) /* inconsistent mode */
|
||||||
return -1; /* failed (invalid call) */
|
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
|
#ifdef _WIN32_WCE
|
||||||
{
|
{
|
||||||
size_t size = SDL_strlen(filename)+1;
|
size_t size = SDL_strlen(filename)+1;
|
||||||
|
@ -82,6 +93,8 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
|
||||||
if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
|
if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
|
||||||
SDL_SetError("Unable to convert filename to Unicode");
|
SDL_SetError("Unable to convert filename to Unicode");
|
||||||
SDL_stack_free(filenameW);
|
SDL_stack_free(filenameW);
|
||||||
|
SDL_free(context->hidden.win32io.buffer.data);
|
||||||
|
context->hidden.win32io.buffer.data = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ,
|
h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ,
|
||||||
|
@ -101,20 +114,13 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
|
||||||
|
|
||||||
if (h==INVALID_HANDLE_VALUE) {
|
if (h==INVALID_HANDLE_VALUE) {
|
||||||
SDL_SetError("Couldn't open %s",filename);
|
SDL_SetError("Couldn't open %s",filename);
|
||||||
|
SDL_free(context->hidden.win32io.buffer.data);
|
||||||
|
context->hidden.win32io.buffer.data = NULL;
|
||||||
return -2; /* failed (CreateFile) */
|
return -2; /* failed (CreateFile) */
|
||||||
}
|
}
|
||||||
context->hidden.win32io.h = h;
|
context->hidden.win32io.h = h;
|
||||||
context->hidden.win32io.append = a_mode;
|
context->hidden.win32io.append = a_mode;
|
||||||
|
|
||||||
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 */
|
return 0; /* ok */
|
||||||
}
|
}
|
||||||
static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence)
|
static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue