Added function to create RWops from const memory: SDL_RWFromConstMem()
authorSam Lantinga <slouken@libsdl.org>
Sun, 04 Jan 2004 15:18:08 +0000
changeset 764 974c0fb74bf8
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
--- a/WhatsNew	Sun Jan 04 15:11:35 2004 +0000
+++ b/WhatsNew	Sun Jan 04 15:18:08 2004 +0000
@@ -6,6 +6,7 @@
 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()
--- a/include/SDL_rwops.h	Sun Jan 04 15:11:35 2004 +0000
+++ b/include/SDL_rwops.h	Sun Jan 04 15:18:08 2004 +0000
@@ -92,6 +92,7 @@
 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);
--- a/src/file/SDL_rwops.c	Sun Jan 04 15:11:35 2004 +0000
+++ b/src/file/SDL_rwops.c	Sun Jan 04 15:18:08 2004 +0000
@@ -129,6 +129,11 @@
 	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 @@
 	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;
--- a/src/main/beos/exports/SDL.exp	Sun Jan 04 15:11:35 2004 +0000
+++ b/src/main/beos/exports/SDL.exp	Sun Jan 04 15:18:08 2004 +0000
@@ -112,6 +112,7 @@
 _SDL_RWFromFile
 _SDL_RWFromFP
 _SDL_RWFromMem
+_SDL_RWFromConstMem
 _SDL_AllocRW
 _SDL_FreeRW
 _SDL_GetWMInfo
--- a/src/main/macos/exports/SDL.x	Sun Jan 04 15:11:35 2004 +0000
+++ b/src/main/macos/exports/SDL.x	Sun Jan 04 15:18:08 2004 +0000
@@ -111,6 +111,7 @@
 	SDL_RWFromFile
 	SDL_RWFromFP
 	SDL_RWFromMem
+	SDL_RWFromConstMem
 	SDL_AllocRW
 	SDL_FreeRW
 	SDL_GetWMInfo
--- a/src/main/macosx/exports/SDL.x	Sun Jan 04 15:11:35 2004 +0000
+++ b/src/main/macosx/exports/SDL.x	Sun Jan 04 15:18:08 2004 +0000
@@ -112,6 +112,7 @@
 	_SDL_RWFromFile
 	_SDL_RWFromFP
 	_SDL_RWFromMem
+	_SDL_RWFromConstMem
 	_SDL_AllocRW
 	_SDL_FreeRW
 	_SDL_GetWMInfo
--- a/src/main/win32/exports/SDL.def	Sun Jan 04 15:11:35 2004 +0000
+++ b/src/main/win32/exports/SDL.def	Sun Jan 04 15:18:08 2004 +0000
@@ -112,6 +112,7 @@
 	SDL_RWFromFile
 	SDL_RWFromFP
 	SDL_RWFromMem
+	SDL_RWFromConstMem
 	SDL_AllocRW
 	SDL_FreeRW
 	SDL_GetWMInfo