Updated to use size_t instead of int for amounts of data.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402457
This commit is contained in:
Sam Lantinga 2007-07-10 05:25:19 +00:00
parent 8daaa10d40
commit 1330dc92d3
2 changed files with 47 additions and 39 deletions

View File

@ -46,26 +46,29 @@ extern "C" {
typedef struct SDL_RWops
{
/* Seek to 'offset' relative to whence, one of stdio's whence values:
SEEK_SET, SEEK_CUR, SEEK_END
RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
Returns the final offset in the data source.
*/
int (SDLCALL * seek) (struct SDL_RWops * context, int offset, int whence);
long (SDLCALL * seek) (struct SDL_RWops * context, long offset,
int whence);
/* Read up to 'num' objects each of size 'objsize' from the data
source to the area pointed at by 'ptr'.
Returns the number of objects read, or -1 if the read failed.
Returns the number of objects read, or 0 at error or end of file.
*/
int (SDLCALL * read) (struct SDL_RWops * context, void *ptr, int size,
int maxnum);
size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
size_t size, size_t maxnum);
/* Write exactly 'num' objects each of size 'objsize' from the area
pointed at by 'ptr' to data source.
Returns 'num', or -1 if the write failed.
Returns the number of objects written, or 0 at error or end of file.
*/
int (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
int size, int num);
size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
size_t size, size_t num);
/* Close and free an allocated SDL_FSops structure */
/* Close and free an allocated SDL_RWops structure.
Returns 0 if successful or -1 on write error when flushing data.
*/
int (SDLCALL * close) (struct SDL_RWops * context);
Uint32 type;
@ -74,7 +77,7 @@ typedef struct SDL_RWops
#ifdef __WIN32__
struct
{
int append;
SDL_bool append;
void *h;
struct
{
@ -87,7 +90,7 @@ typedef struct SDL_RWops
#ifdef HAVE_STDIO_H
struct
{
int autoclose;
SDL_bool autoclose;
FILE *fp;
} stdio;
#endif

View File

@ -128,11 +128,11 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
return 0; /* ok */
}
static int SDLCALL
win32_file_seek(SDL_RWops * context, int offset, int whence)
static long SDLCALL
win32_file_seek(SDL_RWops * context, long offset, int whence)
{
DWORD win32whence;
int file_pos;
long file_pos;
if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) {
SDL_SetError("win32_file_seek: invalid context/file not opened");
@ -169,18 +169,18 @@ win32_file_seek(SDL_RWops * context, int offset, int whence)
SDL_Error(SDL_EFSEEK);
return -1; /* error */
}
static int SDLCALL
win32_file_read(SDL_RWops * context, void *ptr, int size, int maxnum)
static size_t SDLCALL
win32_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{
int total_need;
int total_read = 0;
int read_ahead;
size_t total_need;
size_t total_read = 0;
size_t read_ahead;
DWORD byte_read;
total_need = size * maxnum;
if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE
|| total_need <= 0 || !size)
|| !total_need)
return 0;
if (context->hidden.win32io.buffer.left > 0) {
@ -221,11 +221,12 @@ win32_file_read(SDL_RWops * context, void *ptr, int size, int maxnum)
}
return (total_read / size);
}
static int SDLCALL
win32_file_write(SDL_RWops * context, const void *ptr, int size, int num)
static size_t SDLCALL
win32_file_write(SDL_RWops * context, const void *ptr, size_t size,
size_t num)
{
int total_bytes;
size_t total_bytes;
DWORD byte_written, nwritten;
total_bytes = size * num;
@ -282,8 +283,8 @@ win32_file_close(SDL_RWops * context)
/* Functions to read/write stdio file pointers */
static int SDLCALL
stdio_seek(SDL_RWops * context, int offset, int whence)
static long SDLCALL
stdio_seek(SDL_RWops * context, long offset, int whence)
{
if (fseek(context->hidden.stdio.fp, offset, whence) == 0) {
return (ftell(context->hidden.stdio.fp));
@ -292,8 +293,8 @@ stdio_seek(SDL_RWops * context, int offset, int whence)
return (-1);
}
}
static int SDLCALL
stdio_read(SDL_RWops * context, void *ptr, int size, int maxnum)
static size_t SDLCALL
stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{
size_t nread;
@ -303,8 +304,8 @@ stdio_read(SDL_RWops * context, void *ptr, int size, int maxnum)
}
return (nread);
}
static int SDLCALL
stdio_write(SDL_RWops * context, const void *ptr, int size, int num)
static size_t SDLCALL
stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
{
size_t nwrote;
@ -317,21 +318,25 @@ stdio_write(SDL_RWops * context, const void *ptr, int size, int num)
static int SDLCALL
stdio_close(SDL_RWops * context)
{
int status = 0;
if (context) {
if (context->hidden.stdio.autoclose) {
/* WARNING: Check the return value here! */
fclose(context->hidden.stdio.fp);
if (fclose(context->hidden.stdio.fp) != 0) {
SDL_Error(SDL_EFWRITE);
status = -1;
}
}
SDL_FreeRW(context);
}
return (0);
return status;
}
#endif /* !HAVE_STDIO_H */
/* Functions to read/write memory pointers */
static int SDLCALL
mem_seek(SDL_RWops * context, int offset, int whence)
static long SDLCALL
mem_seek(SDL_RWops * context, long offset, int whence)
{
Uint8 *newpos;
@ -358,8 +363,8 @@ mem_seek(SDL_RWops * context, int offset, int whence)
context->hidden.mem.here = newpos;
return (context->hidden.mem.here - context->hidden.mem.base);
}
static int SDLCALL
mem_read(SDL_RWops * context, void *ptr, int size, int maxnum)
static size_t SDLCALL
mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{
size_t total_bytes;
size_t mem_available;
@ -380,8 +385,8 @@ mem_read(SDL_RWops * context, void *ptr, int size, int maxnum)
return (total_bytes / size);
}
static int SDLCALL
mem_write(SDL_RWops * context, const void *ptr, int size, int num)
static size_t SDLCALL
mem_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
{
if ((context->hidden.mem.here + (num * size)) > context->hidden.mem.stop) {
num = (context->hidden.mem.stop - context->hidden.mem.here) / size;
@ -390,8 +395,8 @@ mem_write(SDL_RWops * context, const void *ptr, int size, int num)
context->hidden.mem.here += num * size;
return (num);
}
static int SDLCALL
mem_writeconst(SDL_RWops * context, const void *ptr, int size, int num)
static size_t SDLCALL
mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
{
SDL_SetError("Can't write to read-only memory");
return (-1);