Added function to create RWops from const memory: SDL_RWFromConstMem()

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40765
This commit is contained in:
Sam Lantinga 2004-01-04 15:18:08 +00:00
parent 9c03bae4f8
commit 028eb83878
7 changed files with 28 additions and 0 deletions

View file

@ -129,6 +129,11 @@ static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
context->hidden.mem.here += num*size;
return(num);
}
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);
}
static int mem_close(SDL_RWops *context)
{
if ( context ) {
@ -258,6 +263,23 @@ SDL_RWops *SDL_RWFromMem(void *mem, int size)
return(rwops);
}
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);
}
SDL_RWops *SDL_AllocRW(void)
{
SDL_RWops *area;