src/file/SDL_rwops.c
changeset 1078 e2ef6b7001fd
parent 769 b8d311d90021
child 1202 0748fbb272e7
equal deleted inserted replaced
1077:f122afdfa025 1078:e2ef6b7001fd
   108 	context->hidden.mem.here = newpos;
   108 	context->hidden.mem.here = newpos;
   109 	return(context->hidden.mem.here-context->hidden.mem.base);
   109 	return(context->hidden.mem.here-context->hidden.mem.base);
   110 }
   110 }
   111 static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   111 static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   112 {
   112 {
   113 	int num;
   113 	int total_bytes;
   114 
   114 	int mem_available;
   115 	num = maxnum;
   115 
   116 	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
   116 	total_bytes = (maxnum * size);
   117 		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
   117 	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) {
   118 	}
   118 		return 0;
   119 	memcpy(ptr, context->hidden.mem.here, num*size);
   119 	}
   120 	context->hidden.mem.here += num*size;
   120 
   121 	return(num);
   121 	mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
       
   122 	if (total_bytes > mem_available) {
       
   123 		total_bytes = mem_available;
       
   124 	}
       
   125 
       
   126 	memcpy(ptr, context->hidden.mem.here, total_bytes);
       
   127 	context->hidden.mem.here += total_bytes;
       
   128 
       
   129 	return (total_bytes / size);
   122 }
   130 }
   123 static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
   131 static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
   124 {
   132 {
   125 	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
   133 	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
   126 		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
   134 		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;