Commit 1330dc92 authored by Sam Lantinga's avatar Sam Lantinga

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

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402457
parent 8daaa10d
...@@ -46,26 +46,29 @@ extern "C" { ...@@ -46,26 +46,29 @@ extern "C" {
typedef struct SDL_RWops typedef struct SDL_RWops
{ {
/* Seek to 'offset' relative to whence, one of stdio's whence values: /* 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. 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 /* Read up to 'num' objects each of size 'objsize' from the data
source to the area pointed at by 'ptr'. 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, size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
int maxnum); size_t size, size_t maxnum);
/* Write exactly 'num' objects each of size 'objsize' from the area /* Write exactly 'num' objects each of size 'objsize' from the area
pointed at by 'ptr' to data source. 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, size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
int size, int num); 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); int (SDLCALL * close) (struct SDL_RWops * context);
Uint32 type; Uint32 type;
...@@ -74,7 +77,7 @@ typedef struct SDL_RWops ...@@ -74,7 +77,7 @@ typedef struct SDL_RWops
#ifdef __WIN32__ #ifdef __WIN32__
struct struct
{ {
int append; SDL_bool append;
void *h; void *h;
struct struct
{ {
...@@ -87,7 +90,7 @@ typedef struct SDL_RWops ...@@ -87,7 +90,7 @@ typedef struct SDL_RWops
#ifdef HAVE_STDIO_H #ifdef HAVE_STDIO_H
struct struct
{ {
int autoclose; SDL_bool autoclose;
FILE *fp; FILE *fp;
} stdio; } stdio;
#endif #endif
......
...@@ -128,11 +128,11 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode) ...@@ -128,11 +128,11 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
return 0; /* ok */ return 0; /* ok */
} }
static int SDLCALL static long SDLCALL
win32_file_seek(SDL_RWops * context, int offset, int whence) win32_file_seek(SDL_RWops * context, long offset, int whence)
{ {
DWORD win32whence; DWORD win32whence;
int file_pos; long file_pos;
if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) { if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) {
SDL_SetError("win32_file_seek: invalid context/file not opened"); SDL_SetError("win32_file_seek: invalid context/file not opened");
...@@ -169,18 +169,18 @@ win32_file_seek(SDL_RWops * context, int offset, int whence) ...@@ -169,18 +169,18 @@ win32_file_seek(SDL_RWops * context, int offset, int whence)
SDL_Error(SDL_EFSEEK); SDL_Error(SDL_EFSEEK);
return -1; /* error */ return -1; /* error */
} }
static int SDLCALL static size_t SDLCALL
win32_file_read(SDL_RWops * context, void *ptr, int size, int maxnum) win32_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{ {
int total_need; size_t total_need;
int total_read = 0; size_t total_read = 0;
int read_ahead; size_t read_ahead;
DWORD byte_read; DWORD byte_read;
total_need = size * maxnum; total_need = size * maxnum;
if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE
|| total_need <= 0 || !size) || !total_need)
return 0; return 0;
if (context->hidden.win32io.buffer.left > 0) { if (context->hidden.win32io.buffer.left > 0) {
...@@ -221,11 +221,12 @@ win32_file_read(SDL_RWops * context, void *ptr, int size, int maxnum) ...@@ -221,11 +221,12 @@ win32_file_read(SDL_RWops * context, void *ptr, int size, int maxnum)
} }
return (total_read / size); return (total_read / size);
} }
static int SDLCALL static size_t SDLCALL
win32_file_write(SDL_RWops * context, const void *ptr, int size, int num) 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; DWORD byte_written, nwritten;
total_bytes = size * num; total_bytes = size * num;
...@@ -282,8 +283,8 @@ win32_file_close(SDL_RWops * context) ...@@ -282,8 +283,8 @@ win32_file_close(SDL_RWops * context)
/* Functions to read/write stdio file pointers */ /* Functions to read/write stdio file pointers */
static int SDLCALL static long SDLCALL
stdio_seek(SDL_RWops * context, int offset, int whence) stdio_seek(SDL_RWops * context, long offset, int whence)
{ {
if (fseek(context->hidden.stdio.fp, offset, whence) == 0) { if (fseek(context->hidden.stdio.fp, offset, whence) == 0) {
return (ftell(context->hidden.stdio.fp)); return (ftell(context->hidden.stdio.fp));
...@@ -292,8 +293,8 @@ stdio_seek(SDL_RWops * context, int offset, int whence) ...@@ -292,8 +293,8 @@ stdio_seek(SDL_RWops * context, int offset, int whence)
return (-1); return (-1);
} }
} }
static int SDLCALL static size_t SDLCALL
stdio_read(SDL_RWops * context, void *ptr, int size, int maxnum) stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{ {
size_t nread; size_t nread;
...@@ -303,8 +304,8 @@ stdio_read(SDL_RWops * context, void *ptr, int size, int maxnum) ...@@ -303,8 +304,8 @@ stdio_read(SDL_RWops * context, void *ptr, int size, int maxnum)
} }
return (nread); return (nread);
} }
static int SDLCALL static size_t SDLCALL
stdio_write(SDL_RWops * context, const void *ptr, int size, int num) stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
{ {
size_t nwrote; size_t nwrote;
...@@ -317,21 +318,25 @@ stdio_write(SDL_RWops * context, const void *ptr, int size, int num) ...@@ -317,21 +318,25 @@ stdio_write(SDL_RWops * context, const void *ptr, int size, int num)
static int SDLCALL static int SDLCALL
stdio_close(SDL_RWops * context) stdio_close(SDL_RWops * context)
{ {
int status = 0;
if (context) { if (context) {
if (context->hidden.stdio.autoclose) { if (context->hidden.stdio.autoclose) {
/* WARNING: Check the return value here! */ /* 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); SDL_FreeRW(context);
} }
return (0); return status;
} }
#endif /* !HAVE_STDIO_H */ #endif /* !HAVE_STDIO_H */
/* Functions to read/write memory pointers */ /* Functions to read/write memory pointers */
static int SDLCALL static long SDLCALL
mem_seek(SDL_RWops * context, int offset, int whence) mem_seek(SDL_RWops * context, long offset, int whence)
{ {
Uint8 *newpos; Uint8 *newpos;
...@@ -358,8 +363,8 @@ mem_seek(SDL_RWops * context, int offset, int whence) ...@@ -358,8 +363,8 @@ mem_seek(SDL_RWops * context, int offset, int whence)
context->hidden.mem.here = newpos; context->hidden.mem.here = newpos;
return (context->hidden.mem.here - context->hidden.mem.base); return (context->hidden.mem.here - context->hidden.mem.base);
} }
static int SDLCALL static size_t SDLCALL
mem_read(SDL_RWops * context, void *ptr, int size, int maxnum) mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{ {
size_t total_bytes; size_t total_bytes;
size_t mem_available; size_t mem_available;
...@@ -380,8 +385,8 @@ mem_read(SDL_RWops * context, void *ptr, int size, int maxnum) ...@@ -380,8 +385,8 @@ mem_read(SDL_RWops * context, void *ptr, int size, int maxnum)
return (total_bytes / size); return (total_bytes / size);
} }
static int SDLCALL static size_t SDLCALL
mem_write(SDL_RWops * context, const void *ptr, int size, int num) 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) { if ((context->hidden.mem.here + (num * size)) > context->hidden.mem.stop) {
num = (context->hidden.mem.stop - context->hidden.mem.here) / size; 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) ...@@ -390,8 +395,8 @@ mem_write(SDL_RWops * context, const void *ptr, int size, int num)
context->hidden.mem.here += num * size; context->hidden.mem.here += num * size;
return (num); return (num);
} }
static int SDLCALL static size_t SDLCALL
mem_writeconst(SDL_RWops * context, const void *ptr, int size, int num) mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
{ {
SDL_SetError("Can't write to read-only memory"); SDL_SetError("Can't write to read-only memory");
return (-1); return (-1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment