2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2006-02-01 06:32:25 +00:00
|
|
|
Copyright (C) 1997-2006 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* This file provides a general interface for SDL to read and write
|
|
|
|
data sources. It can easily be extended to files, memory, etc.
|
|
|
|
*/
|
|
|
|
|
2006-02-09 09:38:05 +00:00
|
|
|
#include "SDL_endian.h"
|
2006-02-07 09:29:18 +00:00
|
|
|
#include "SDL_rwops.h"
|
2006-02-06 08:28:51 +00:00
|
|
|
|
2006-02-09 09:38:05 +00:00
|
|
|
|
2006-02-06 08:28:51 +00:00
|
|
|
#ifdef HAVE_STDIO_H
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Functions to read/write stdio file pointers */
|
|
|
|
|
|
|
|
static int stdio_seek(SDL_RWops *context, int offset, int whence)
|
|
|
|
{
|
|
|
|
if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) {
|
|
|
|
return(ftell(context->hidden.stdio.fp));
|
|
|
|
} else {
|
|
|
|
SDL_Error(SDL_EFSEEK);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static int stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
|
|
|
|
{
|
|
|
|
size_t nread;
|
|
|
|
|
|
|
|
nread = fread(ptr, size, maxnum, context->hidden.stdio.fp);
|
|
|
|
if ( nread == 0 && ferror(context->hidden.stdio.fp) ) {
|
|
|
|
SDL_Error(SDL_EFREAD);
|
|
|
|
}
|
|
|
|
return(nread);
|
|
|
|
}
|
|
|
|
static int stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
|
|
|
|
{
|
|
|
|
size_t nwrote;
|
|
|
|
|
|
|
|
nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
|
|
|
|
if ( nwrote == 0 && ferror(context->hidden.stdio.fp) ) {
|
|
|
|
SDL_Error(SDL_EFWRITE);
|
|
|
|
}
|
|
|
|
return(nwrote);
|
|
|
|
}
|
|
|
|
static int stdio_close(SDL_RWops *context)
|
|
|
|
{
|
|
|
|
if ( context ) {
|
|
|
|
if ( context->hidden.stdio.autoclose ) {
|
|
|
|
/* WARNING: Check the return value here! */
|
|
|
|
fclose(context->hidden.stdio.fp);
|
|
|
|
}
|
2005-12-12 10:54:41 +00:00
|
|
|
SDL_FreeRW(context);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-02-06 08:28:51 +00:00
|
|
|
#endif /* HAVE_STDIO_H */
|
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
/* Functions to read/write memory pointers */
|
|
|
|
|
|
|
|
static int mem_seek(SDL_RWops *context, int offset, int whence)
|
|
|
|
{
|
|
|
|
Uint8 *newpos;
|
|
|
|
|
|
|
|
switch (whence) {
|
2006-02-06 08:28:51 +00:00
|
|
|
case RW_SEEK_SET:
|
2001-04-26 16:45:43 +00:00
|
|
|
newpos = context->hidden.mem.base+offset;
|
|
|
|
break;
|
2006-02-06 08:28:51 +00:00
|
|
|
case RW_SEEK_CUR:
|
2001-04-26 16:45:43 +00:00
|
|
|
newpos = context->hidden.mem.here+offset;
|
|
|
|
break;
|
2006-02-06 08:28:51 +00:00
|
|
|
case RW_SEEK_END:
|
2001-04-26 16:45:43 +00:00
|
|
|
newpos = context->hidden.mem.stop+offset;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SDL_SetError("Unknown value for 'whence'");
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
if ( newpos < context->hidden.mem.base ) {
|
|
|
|
newpos = context->hidden.mem.base;
|
|
|
|
}
|
|
|
|
if ( newpos > context->hidden.mem.stop ) {
|
|
|
|
newpos = context->hidden.mem.stop;
|
|
|
|
}
|
|
|
|
context->hidden.mem.here = newpos;
|
|
|
|
return(context->hidden.mem.here-context->hidden.mem.base);
|
|
|
|
}
|
|
|
|
static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
|
|
|
|
{
|
Patch from Antonio SJ Musumeci:
"
This code with SDL-1.2.8 and CVS:
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int
main(int argc, char** argv)
{
char alphabet[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char buffer_file[27] = {0};
char buffer_mem[27] = {0};
int rv_file;
int rv_mem;
FILE* file_ptr;
SDL_RWops* rwop_file;
SDL_RWops* rwop_mem;
file_ptr = fopen("./blah", "w");
fwrite(alphabet, 1, sizeof(alphabet), file_ptr);
fclose(file_ptr);
rwop_mem = SDL_RWFromMem(alphabet, sizeof(alphabet));
rwop_file = SDL_RWFromFile("./blah", "r");
rv_mem = SDL_RWread(rwop_mem , buffer_mem, 5, 6);
rv_file = SDL_RWread(rwop_file, buffer_file, 5, 6);
printf("From File: %d %s\n"
"From Mem: %d %s\n",
rv_file,
buffer_file,
rv_mem,
buffer_mem);
printf("Seek end of File: %d\n"
"Seek end of Mem: %d\n",
SDL_RWseek(rwop_file, 0, SEEK_END),
SDL_RWseek(rwop_mem , 0, SEEK_END));
SDL_RWclose(rwop_file);
SDL_RWclose(rwop_mem);
return 0;
}
Produces this output:
From File: 5 ABCDEFGHIJKLMNOPQRSTUVWXYZ
From Mem: 5 ABCDEFGHIJKLMNOPQRSTUVWXY
Seek end of File: 26
Seek end of Mem: 26
"
--ryan.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401079
2005-06-24 12:48:38 +00:00
|
|
|
int total_bytes;
|
|
|
|
int mem_available;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
Patch from Antonio SJ Musumeci:
"
This code with SDL-1.2.8 and CVS:
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int
main(int argc, char** argv)
{
char alphabet[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char buffer_file[27] = {0};
char buffer_mem[27] = {0};
int rv_file;
int rv_mem;
FILE* file_ptr;
SDL_RWops* rwop_file;
SDL_RWops* rwop_mem;
file_ptr = fopen("./blah", "w");
fwrite(alphabet, 1, sizeof(alphabet), file_ptr);
fclose(file_ptr);
rwop_mem = SDL_RWFromMem(alphabet, sizeof(alphabet));
rwop_file = SDL_RWFromFile("./blah", "r");
rv_mem = SDL_RWread(rwop_mem , buffer_mem, 5, 6);
rv_file = SDL_RWread(rwop_file, buffer_file, 5, 6);
printf("From File: %d %s\n"
"From Mem: %d %s\n",
rv_file,
buffer_file,
rv_mem,
buffer_mem);
printf("Seek end of File: %d\n"
"Seek end of Mem: %d\n",
SDL_RWseek(rwop_file, 0, SEEK_END),
SDL_RWseek(rwop_mem , 0, SEEK_END));
SDL_RWclose(rwop_file);
SDL_RWclose(rwop_mem);
return 0;
}
Produces this output:
From File: 5 ABCDEFGHIJKLMNOPQRSTUVWXYZ
From Mem: 5 ABCDEFGHIJKLMNOPQRSTUVWXY
Seek end of File: 26
Seek end of Mem: 26
"
--ryan.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401079
2005-06-24 12:48:38 +00:00
|
|
|
total_bytes = (maxnum * size);
|
|
|
|
if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) {
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
Patch from Antonio SJ Musumeci:
"
This code with SDL-1.2.8 and CVS:
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int
main(int argc, char** argv)
{
char alphabet[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char buffer_file[27] = {0};
char buffer_mem[27] = {0};
int rv_file;
int rv_mem;
FILE* file_ptr;
SDL_RWops* rwop_file;
SDL_RWops* rwop_mem;
file_ptr = fopen("./blah", "w");
fwrite(alphabet, 1, sizeof(alphabet), file_ptr);
fclose(file_ptr);
rwop_mem = SDL_RWFromMem(alphabet, sizeof(alphabet));
rwop_file = SDL_RWFromFile("./blah", "r");
rv_mem = SDL_RWread(rwop_mem , buffer_mem, 5, 6);
rv_file = SDL_RWread(rwop_file, buffer_file, 5, 6);
printf("From File: %d %s\n"
"From Mem: %d %s\n",
rv_file,
buffer_file,
rv_mem,
buffer_mem);
printf("Seek end of File: %d\n"
"Seek end of Mem: %d\n",
SDL_RWseek(rwop_file, 0, SEEK_END),
SDL_RWseek(rwop_mem , 0, SEEK_END));
SDL_RWclose(rwop_file);
SDL_RWclose(rwop_mem);
return 0;
}
Produces this output:
From File: 5 ABCDEFGHIJKLMNOPQRSTUVWXYZ
From Mem: 5 ABCDEFGHIJKLMNOPQRSTUVWXY
Seek end of File: 26
Seek end of Mem: 26
"
--ryan.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401079
2005-06-24 12:48:38 +00:00
|
|
|
|
|
|
|
mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
|
|
|
|
if (total_bytes > mem_available) {
|
|
|
|
total_bytes = mem_available;
|
|
|
|
}
|
|
|
|
|
2006-02-07 06:59:48 +00:00
|
|
|
SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
|
Patch from Antonio SJ Musumeci:
"
This code with SDL-1.2.8 and CVS:
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int
main(int argc, char** argv)
{
char alphabet[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char buffer_file[27] = {0};
char buffer_mem[27] = {0};
int rv_file;
int rv_mem;
FILE* file_ptr;
SDL_RWops* rwop_file;
SDL_RWops* rwop_mem;
file_ptr = fopen("./blah", "w");
fwrite(alphabet, 1, sizeof(alphabet), file_ptr);
fclose(file_ptr);
rwop_mem = SDL_RWFromMem(alphabet, sizeof(alphabet));
rwop_file = SDL_RWFromFile("./blah", "r");
rv_mem = SDL_RWread(rwop_mem , buffer_mem, 5, 6);
rv_file = SDL_RWread(rwop_file, buffer_file, 5, 6);
printf("From File: %d %s\n"
"From Mem: %d %s\n",
rv_file,
buffer_file,
rv_mem,
buffer_mem);
printf("Seek end of File: %d\n"
"Seek end of Mem: %d\n",
SDL_RWseek(rwop_file, 0, SEEK_END),
SDL_RWseek(rwop_mem , 0, SEEK_END));
SDL_RWclose(rwop_file);
SDL_RWclose(rwop_mem);
return 0;
}
Produces this output:
From File: 5 ABCDEFGHIJKLMNOPQRSTUVWXYZ
From Mem: 5 ABCDEFGHIJKLMNOPQRSTUVWXY
Seek end of File: 26
Seek end of Mem: 26
"
--ryan.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401079
2005-06-24 12:48:38 +00:00
|
|
|
context->hidden.mem.here += total_bytes;
|
|
|
|
|
|
|
|
return (total_bytes / size);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
|
|
|
|
{
|
|
|
|
if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
|
|
|
|
num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
|
|
|
|
}
|
2006-02-07 06:59:48 +00:00
|
|
|
SDL_memcpy(context->hidden.mem.here, ptr, num*size);
|
2001-04-26 16:45:43 +00:00
|
|
|
context->hidden.mem.here += num*size;
|
|
|
|
return(num);
|
|
|
|
}
|
2004-01-04 15:18:08 +00:00
|
|
|
static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
|
|
|
|
{
|
|
|
|
SDL_SetError("Can't write to read-only memory");
|
|
|
|
return(-1);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
static int mem_close(SDL_RWops *context)
|
|
|
|
{
|
|
|
|
if ( context ) {
|
2005-12-12 10:54:41 +00:00
|
|
|
SDL_FreeRW(context);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Functions to create SDL_RWops structures from various data sources */
|
2006-02-21 08:46:50 +00:00
|
|
|
#ifdef __WIN32__
|
2001-04-26 16:45:43 +00:00
|
|
|
/* Aggh. You can't (apparently) open a file in an application and
|
|
|
|
read from it in a DLL.
|
|
|
|
*/
|
|
|
|
static int in_sdl = 0;
|
|
|
|
#endif
|
|
|
|
|
2006-02-21 08:46:50 +00:00
|
|
|
#ifdef __MACOS__
|
2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
* translate unix-style slash-separated filename to mac-style colon-separated
|
|
|
|
* name; return malloced string
|
|
|
|
*/
|
|
|
|
static char *unix_to_mac(const char *file)
|
|
|
|
{
|
2006-02-07 06:59:48 +00:00
|
|
|
int flen = SDL_strlen(file);
|
|
|
|
char *path = SDL_malloc(flen + 2);
|
2001-04-26 16:45:43 +00:00
|
|
|
const char *src = file;
|
|
|
|
char *dst = path;
|
|
|
|
if(*src == '/') {
|
|
|
|
/* really depends on filesystem layout, hope for the best */
|
|
|
|
src++;
|
|
|
|
} else {
|
|
|
|
/* Check if this is a MacOS path to begin with */
|
|
|
|
if(*src != ':')
|
|
|
|
*dst++ = ':'; /* relative paths begin with ':' */
|
|
|
|
}
|
|
|
|
while(src < file + flen) {
|
2006-02-07 06:59:48 +00:00
|
|
|
const char *end = SDL_strchr(src, '/');
|
2001-04-26 16:45:43 +00:00
|
|
|
int len;
|
|
|
|
if(!end)
|
|
|
|
end = file + flen; /* last component */
|
|
|
|
len = end - src;
|
|
|
|
if(len == 0 || (len == 1 && src[0] == '.')) {
|
|
|
|
/* remove repeated slashes and . */
|
|
|
|
} else {
|
|
|
|
if(len == 2 && src[0] == '.' && src[1] == '.') {
|
|
|
|
/* replace .. with the empty string */
|
|
|
|
} else {
|
2006-02-07 06:59:48 +00:00
|
|
|
SDL_memcpy(dst, src, len);
|
2001-04-26 16:45:43 +00:00
|
|
|
dst += len;
|
|
|
|
}
|
|
|
|
if(end < file + flen)
|
|
|
|
*dst++ = ':';
|
|
|
|
}
|
|
|
|
src = end + 1;
|
|
|
|
}
|
|
|
|
*dst++ = '\0';
|
|
|
|
return path;
|
|
|
|
}
|
2006-02-21 08:46:50 +00:00
|
|
|
#endif /* __MACOS__ */
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
|
|
|
|
{
|
2006-02-06 08:28:51 +00:00
|
|
|
SDL_RWops *rwops = NULL;
|
|
|
|
#ifdef HAVE_STDIO_H
|
2001-04-26 16:45:43 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
2006-02-21 08:46:50 +00:00
|
|
|
#ifdef __MACOS__
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
|
|
|
char *mpath = unix_to_mac(file);
|
|
|
|
fp = fopen(mpath, mode);
|
2006-02-07 06:59:48 +00:00
|
|
|
SDL_free(mpath);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
fp = fopen(file, mode);
|
|
|
|
#endif
|
|
|
|
if ( fp == NULL ) {
|
|
|
|
SDL_SetError("Couldn't open %s", file);
|
|
|
|
} else {
|
2006-02-21 08:46:50 +00:00
|
|
|
#ifdef __WIN32__
|
2001-04-26 16:45:43 +00:00
|
|
|
in_sdl = 1;
|
|
|
|
rwops = SDL_RWFromFP(fp, 1);
|
|
|
|
in_sdl = 0;
|
|
|
|
#else
|
|
|
|
rwops = SDL_RWFromFP(fp, 1);
|
|
|
|
#endif
|
|
|
|
}
|
2006-02-06 08:28:51 +00:00
|
|
|
#endif /* HAVE_STDIO_H */
|
2001-04-26 16:45:43 +00:00
|
|
|
return(rwops);
|
|
|
|
}
|
|
|
|
|
2006-02-06 08:28:51 +00:00
|
|
|
#ifdef HAVE_STDIO_H
|
2001-04-26 16:45:43 +00:00
|
|
|
SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
|
|
|
|
{
|
2006-02-06 08:28:51 +00:00
|
|
|
SDL_RWops *rwops = NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-21 08:46:50 +00:00
|
|
|
#ifdef __WIN32__
|
2001-04-26 16:45:43 +00:00
|
|
|
if ( ! in_sdl ) {
|
2006-01-26 06:10:34 +00:00
|
|
|
/* It's when SDL and the app are compiled with different C runtimes */
|
2002-11-17 18:59:10 +00:00
|
|
|
SDL_SetError("You can't pass a FILE pointer to a DLL (?)");
|
2001-04-26 16:45:43 +00:00
|
|
|
/*return(NULL);*/
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rwops = SDL_AllocRW();
|
|
|
|
if ( rwops != NULL ) {
|
|
|
|
rwops->seek = stdio_seek;
|
|
|
|
rwops->read = stdio_read;
|
|
|
|
rwops->write = stdio_write;
|
|
|
|
rwops->close = stdio_close;
|
|
|
|
rwops->hidden.stdio.fp = fp;
|
|
|
|
rwops->hidden.stdio.autoclose = autoclose;
|
|
|
|
}
|
|
|
|
return(rwops);
|
|
|
|
}
|
2006-02-06 08:28:51 +00:00
|
|
|
#endif /* HAVE_STDIO_H */
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
SDL_RWops *SDL_RWFromMem(void *mem, int size)
|
|
|
|
{
|
|
|
|
SDL_RWops *rwops;
|
|
|
|
|
|
|
|
rwops = SDL_AllocRW();
|
|
|
|
if ( rwops != NULL ) {
|
|
|
|
rwops->seek = mem_seek;
|
|
|
|
rwops->read = mem_read;
|
|
|
|
rwops->write = mem_write;
|
|
|
|
rwops->close = mem_close;
|
|
|
|
rwops->hidden.mem.base = (Uint8 *)mem;
|
|
|
|
rwops->hidden.mem.here = rwops->hidden.mem.base;
|
|
|
|
rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
|
|
|
|
}
|
|
|
|
return(rwops);
|
|
|
|
}
|
|
|
|
|
2004-01-04 15:18:08 +00:00
|
|
|
SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
|
|
|
|
{
|
|
|
|
SDL_RWops *rwops;
|
|
|
|
|
|
|
|
rwops = SDL_AllocRW();
|
|
|
|
if ( rwops != NULL ) {
|
|
|
|
rwops->seek = mem_seek;
|
|
|
|
rwops->read = mem_read;
|
|
|
|
rwops->write = mem_writeconst;
|
|
|
|
rwops->close = mem_close;
|
|
|
|
rwops->hidden.mem.base = (Uint8 *)mem;
|
|
|
|
rwops->hidden.mem.here = rwops->hidden.mem.base;
|
|
|
|
rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
|
|
|
|
}
|
|
|
|
return(rwops);
|
|
|
|
}
|
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
SDL_RWops *SDL_AllocRW(void)
|
|
|
|
{
|
|
|
|
SDL_RWops *area;
|
|
|
|
|
2006-02-07 06:59:48 +00:00
|
|
|
area = (SDL_RWops *)SDL_malloc(sizeof *area);
|
2001-04-26 16:45:43 +00:00
|
|
|
if ( area == NULL ) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
}
|
|
|
|
return(area);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDL_FreeRW(SDL_RWops *area)
|
|
|
|
{
|
2006-02-07 06:59:48 +00:00
|
|
|
SDL_free(area);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-02-09 09:38:05 +00:00
|
|
|
|
|
|
|
/* Functions for dynamically reading and writing endian-specific values */
|
|
|
|
|
|
|
|
Uint16 SDL_ReadLE16 (SDL_RWops *src)
|
|
|
|
{
|
|
|
|
Uint16 value;
|
|
|
|
|
|
|
|
SDL_RWread(src, &value, (sizeof value), 1);
|
|
|
|
return(SDL_SwapLE16(value));
|
|
|
|
}
|
|
|
|
Uint16 SDL_ReadBE16 (SDL_RWops *src)
|
|
|
|
{
|
|
|
|
Uint16 value;
|
|
|
|
|
|
|
|
SDL_RWread(src, &value, (sizeof value), 1);
|
|
|
|
return(SDL_SwapBE16(value));
|
|
|
|
}
|
|
|
|
Uint32 SDL_ReadLE32 (SDL_RWops *src)
|
|
|
|
{
|
|
|
|
Uint32 value;
|
|
|
|
|
|
|
|
SDL_RWread(src, &value, (sizeof value), 1);
|
|
|
|
return(SDL_SwapLE32(value));
|
|
|
|
}
|
|
|
|
Uint32 SDL_ReadBE32 (SDL_RWops *src)
|
|
|
|
{
|
|
|
|
Uint32 value;
|
|
|
|
|
|
|
|
SDL_RWread(src, &value, (sizeof value), 1);
|
|
|
|
return(SDL_SwapBE32(value));
|
|
|
|
}
|
|
|
|
Uint64 SDL_ReadLE64 (SDL_RWops *src)
|
|
|
|
{
|
|
|
|
Uint64 value;
|
|
|
|
|
|
|
|
SDL_RWread(src, &value, (sizeof value), 1);
|
|
|
|
return(SDL_SwapLE64(value));
|
|
|
|
}
|
|
|
|
Uint64 SDL_ReadBE64 (SDL_RWops *src)
|
|
|
|
{
|
|
|
|
Uint64 value;
|
|
|
|
|
|
|
|
SDL_RWread(src, &value, (sizeof value), 1);
|
|
|
|
return(SDL_SwapBE64(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value)
|
|
|
|
{
|
|
|
|
value = SDL_SwapLE16(value);
|
|
|
|
return(SDL_RWwrite(dst, &value, (sizeof value), 1));
|
|
|
|
}
|
|
|
|
int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value)
|
|
|
|
{
|
|
|
|
value = SDL_SwapBE16(value);
|
|
|
|
return(SDL_RWwrite(dst, &value, (sizeof value), 1));
|
|
|
|
}
|
|
|
|
int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value)
|
|
|
|
{
|
|
|
|
value = SDL_SwapLE32(value);
|
|
|
|
return(SDL_RWwrite(dst, &value, (sizeof value), 1));
|
|
|
|
}
|
|
|
|
int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value)
|
|
|
|
{
|
|
|
|
value = SDL_SwapBE32(value);
|
|
|
|
return(SDL_RWwrite(dst, &value, (sizeof value), 1));
|
|
|
|
}
|
|
|
|
int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value)
|
|
|
|
{
|
|
|
|
value = SDL_SwapLE64(value);
|
|
|
|
return(SDL_RWwrite(dst, &value, (sizeof value), 1));
|
|
|
|
}
|
|
|
|
int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value)
|
|
|
|
{
|
|
|
|
value = SDL_SwapBE64(value);
|
|
|
|
return(SDL_RWwrite(dst, &value, (sizeof value), 1));
|
|
|
|
}
|