Date: Tue, 24 May 2005 00:43:05 -0400 From: Antonio SJ Musumeci To: sdl@libsdl.org Subject: [SDL] SDL_RWops bug fixes SDL_RWops changes Bugs: -Reading from memory was not consistant with how reading from files worked. A file of 55 bytes stored into 'ptr' by using 6 sets of 10 bytes would copy 55 bytes into 'ptr' and SDL_RWread would return 5. But the same act done on mem RWop would result in 50 bytes copied and 5 returned. -Seems that SDL_RWclose should return fclose's return value instead of 0 -Since there is no feof or ferror wrappers... if read or write return less than requested... it was not known why. Added SDL_RWeof, SDL_RWerror, and SDL_RWclearerr -mem_writeconst() would return a -1... but fwrite nor mem_write would return a -1 on an error... especially since the concept of knowing an error occured didnt exist... return 0 now and sets flags as error. -since it is obvious RWops is based off stdio FILE's... it would make sense to use the same data types. > ftell returns a long... RWseek returns ftell so RWseek returns long > seek's offset argument is now a long > read and write take size_t's instead of int's and return size_t's -where RWop was free'd in RWclose functions... appears it should have been using SDL_FreeRW since RWFromX's use SDL_AllocRW -In unix_to_mac function... called from SDL_RWFromFile with a const char* file = NULL would try to strlen(NULL) -No check on the malloc used in unix_to_mac... put in check. -mem_read and mem_write didnt check for overflows the same way fread/fwrite do (at least how dietlibc impliments them)... if num or size are 0 return 0... if ((num * size) / num) != size) return 0 Misc: -Fixed some comments in SDL_rwops.h -renamed a few arguments for consistancy -SDL_RWops.type is completely unused... removed. -SDL_RWops.unknown also unused... removed. -Added SDL_OutOfMemory error setting to any malloc's -unknown values for 'whence' now also set RWerror Enhancements: -Added the concept of SDL_RWeof, SDL_RWerror, and SDL_RWclearerr -Created SDL_RWFromMallocedMem(void* ptr, size_t size) If 'ptr' is NULL... it allocates 'size' bytes for you, otherwise 'ptr' must be from standard malloc. If you attempt to write past the end of the buffer it will realloc the buffer. You may also treat it like a file stream works... you can seek past the actual end and when you attempt to write data it will realloc and copy the data. Area between the original end and the seeked position will contain '\0''s just as a write performed on a file which was seeked past it's end. If realloc fails the buffer stays the same and the error flag is set.