Skip to content
Permalink
Browse files

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

  • Loading branch information
slouken committed Jan 4, 2004
1 parent f377bab commit 8bce08f1026b6e30e9ada6e291a115a260dba682
@@ -6,6 +6,7 @@ Version 1.0:
1.2.7:
Added CPU feature detection functions to SDL_cpuinfo.h:
SDL_HasRDTSC(), SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE()
Added function to create RWops from const memory: SDL_RWFromConstMem()

1.2.6:
Added SDL_LoadObject(), SDL_LoadFunction(), and SDL_UnloadObject()
@@ -92,6 +92,7 @@ extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose);

extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size);
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size);

extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void);
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
@@ -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;
@@ -112,6 +112,7 @@ _SDL_CondWaitTimeout
_SDL_RWFromFile
_SDL_RWFromFP
_SDL_RWFromMem
_SDL_RWFromConstMem
_SDL_AllocRW
_SDL_FreeRW
_SDL_GetWMInfo
@@ -111,6 +111,7 @@
SDL_RWFromFile
SDL_RWFromFP
SDL_RWFromMem
SDL_RWFromConstMem
SDL_AllocRW
SDL_FreeRW
SDL_GetWMInfo
@@ -112,6 +112,7 @@
_SDL_RWFromFile
_SDL_RWFromFP
_SDL_RWFromMem
_SDL_RWFromConstMem
_SDL_AllocRW
_SDL_FreeRW
_SDL_GetWMInfo
@@ -112,6 +112,7 @@
SDL_RWFromFile
SDL_RWFromFP
SDL_RWFromMem
SDL_RWFromConstMem
SDL_AllocRW
SDL_FreeRW
SDL_GetWMInfo

0 comments on commit 8bce08f

Please sign in to comment.