Added function to create RWops from const memory: SDL_RWFromConstMem()
authorSam Lantinga <slouken@libsdl.org>
Sun, 04 Jan 2004 15:18:08 +0000
changeset 764974c0fb74bf8
parent 763 51b5e0be61c3
child 765 4c2ba6161939
Added function to create RWops from const memory: SDL_RWFromConstMem()
WhatsNew
include/SDL_rwops.h
src/file/SDL_rwops.c
src/main/beos/exports/SDL.exp
src/main/macos/exports/SDL.x
src/main/macosx/exports/SDL.x
src/main/win32/exports/SDL.def
     1.1 --- a/WhatsNew	Sun Jan 04 15:11:35 2004 +0000
     1.2 +++ b/WhatsNew	Sun Jan 04 15:18:08 2004 +0000
     1.3 @@ -6,6 +6,7 @@
     1.4  1.2.7:
     1.5  	Added CPU feature detection functions to SDL_cpuinfo.h:
     1.6  		SDL_HasRDTSC(), SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE()
     1.7 +	Added function to create RWops from const memory: SDL_RWFromConstMem()
     1.8  
     1.9  1.2.6:
    1.10  	Added SDL_LoadObject(), SDL_LoadFunction(), and SDL_UnloadObject()
     2.1 --- a/include/SDL_rwops.h	Sun Jan 04 15:11:35 2004 +0000
     2.2 +++ b/include/SDL_rwops.h	Sun Jan 04 15:18:08 2004 +0000
     2.3 @@ -92,6 +92,7 @@
     2.4  extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose);
     2.5  
     2.6  extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size);
     2.7 +extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size);
     2.8  
     2.9  extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void);
    2.10  extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
     3.1 --- a/src/file/SDL_rwops.c	Sun Jan 04 15:11:35 2004 +0000
     3.2 +++ b/src/file/SDL_rwops.c	Sun Jan 04 15:18:08 2004 +0000
     3.3 @@ -129,6 +129,11 @@
     3.4  	context->hidden.mem.here += num*size;
     3.5  	return(num);
     3.6  }
     3.7 +static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
     3.8 +{
     3.9 +	SDL_SetError("Can't write to read-only memory");
    3.10 +	return(-1);
    3.11 +}
    3.12  static int mem_close(SDL_RWops *context)
    3.13  {
    3.14  	if ( context ) {
    3.15 @@ -258,6 +263,23 @@
    3.16  	return(rwops);
    3.17  }
    3.18  
    3.19 +SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
    3.20 +{
    3.21 +	SDL_RWops *rwops;
    3.22 +
    3.23 +	rwops = SDL_AllocRW();
    3.24 +	if ( rwops != NULL ) {
    3.25 +		rwops->seek = mem_seek;
    3.26 +		rwops->read = mem_read;
    3.27 +		rwops->write = mem_writeconst;
    3.28 +		rwops->close = mem_close;
    3.29 +		rwops->hidden.mem.base = (Uint8 *)mem;
    3.30 +		rwops->hidden.mem.here = rwops->hidden.mem.base;
    3.31 +		rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
    3.32 +	}
    3.33 +	return(rwops);
    3.34 +}
    3.35 +
    3.36  SDL_RWops *SDL_AllocRW(void)
    3.37  {
    3.38  	SDL_RWops *area;
     4.1 --- a/src/main/beos/exports/SDL.exp	Sun Jan 04 15:11:35 2004 +0000
     4.2 +++ b/src/main/beos/exports/SDL.exp	Sun Jan 04 15:18:08 2004 +0000
     4.3 @@ -112,6 +112,7 @@
     4.4  _SDL_RWFromFile
     4.5  _SDL_RWFromFP
     4.6  _SDL_RWFromMem
     4.7 +_SDL_RWFromConstMem
     4.8  _SDL_AllocRW
     4.9  _SDL_FreeRW
    4.10  _SDL_GetWMInfo
     5.1 --- a/src/main/macos/exports/SDL.x	Sun Jan 04 15:11:35 2004 +0000
     5.2 +++ b/src/main/macos/exports/SDL.x	Sun Jan 04 15:18:08 2004 +0000
     5.3 @@ -111,6 +111,7 @@
     5.4  	SDL_RWFromFile
     5.5  	SDL_RWFromFP
     5.6  	SDL_RWFromMem
     5.7 +	SDL_RWFromConstMem
     5.8  	SDL_AllocRW
     5.9  	SDL_FreeRW
    5.10  	SDL_GetWMInfo
     6.1 --- a/src/main/macosx/exports/SDL.x	Sun Jan 04 15:11:35 2004 +0000
     6.2 +++ b/src/main/macosx/exports/SDL.x	Sun Jan 04 15:18:08 2004 +0000
     6.3 @@ -112,6 +112,7 @@
     6.4  	_SDL_RWFromFile
     6.5  	_SDL_RWFromFP
     6.6  	_SDL_RWFromMem
     6.7 +	_SDL_RWFromConstMem
     6.8  	_SDL_AllocRW
     6.9  	_SDL_FreeRW
    6.10  	_SDL_GetWMInfo
     7.1 --- a/src/main/win32/exports/SDL.def	Sun Jan 04 15:11:35 2004 +0000
     7.2 +++ b/src/main/win32/exports/SDL.def	Sun Jan 04 15:18:08 2004 +0000
     7.3 @@ -112,6 +112,7 @@
     7.4  	SDL_RWFromFile
     7.5  	SDL_RWFromFP
     7.6  	SDL_RWFromMem
     7.7 +	SDL_RWFromConstMem
     7.8  	SDL_AllocRW
     7.9  	SDL_FreeRW
    7.10  	SDL_GetWMInfo