diff src/file/SDL_rwops.c @ 764:974c0fb74bf8

Added function to create RWops from const memory: SDL_RWFromConstMem()
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Jan 2004 15:18:08 +0000
parents 522e5202014d
children b8d311d90021
line wrap: on
line diff
--- 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;