src/file/SDL_rwops.c
changeset 764 974c0fb74bf8
parent 543 522e5202014d
child 769 b8d311d90021
     1.1 --- a/src/file/SDL_rwops.c	Sun Jan 04 15:11:35 2004 +0000
     1.2 +++ b/src/file/SDL_rwops.c	Sun Jan 04 15:18:08 2004 +0000
     1.3 @@ -129,6 +129,11 @@
     1.4  	context->hidden.mem.here += num*size;
     1.5  	return(num);
     1.6  }
     1.7 +static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
     1.8 +{
     1.9 +	SDL_SetError("Can't write to read-only memory");
    1.10 +	return(-1);
    1.11 +}
    1.12  static int mem_close(SDL_RWops *context)
    1.13  {
    1.14  	if ( context ) {
    1.15 @@ -258,6 +263,23 @@
    1.16  	return(rwops);
    1.17  }
    1.18  
    1.19 +SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
    1.20 +{
    1.21 +	SDL_RWops *rwops;
    1.22 +
    1.23 +	rwops = SDL_AllocRW();
    1.24 +	if ( rwops != NULL ) {
    1.25 +		rwops->seek = mem_seek;
    1.26 +		rwops->read = mem_read;
    1.27 +		rwops->write = mem_writeconst;
    1.28 +		rwops->close = mem_close;
    1.29 +		rwops->hidden.mem.base = (Uint8 *)mem;
    1.30 +		rwops->hidden.mem.here = rwops->hidden.mem.base;
    1.31 +		rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
    1.32 +	}
    1.33 +	return(rwops);
    1.34 +}
    1.35 +
    1.36  SDL_RWops *SDL_AllocRW(void)
    1.37  {
    1.38  	SDL_RWops *area;