Wiki Page Content

Differences between revisions 19 and 20
Revision 19 as of 2014-09-23 19:48:42
Size: 1721
Comment: Fixed formatting.
Revision 20 as of 2014-09-23 19:51:55
Size: 1728
Comment: Fixed constant name in example (Feedback 2014-09-23) so no C standard include needed.
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:
SDL_RWops *rw = SDL_RWFromFile("myfile.bin","rb"); SDL_RWops *rw = SDL_RWFromFile("myfile.bin", "rb");
Line 29: Line 29:
    Sint64 length = SDL_RWseek(rw,0,SEEK_END);     Sint64 length = SDL_RWseek(rw, 0, RW_SEEK_END);
Line 34: Line 34:
        printf("myfile.bin is %d bytes long\n",length);         printf("myfile.bin is %d bytes long\n", length);


Use this function to seek within an SDL_RWops data stream.


Sint64 SDL_RWseek(SDL_RWops* context,
                  Sint64     offset,
                  int        whence)

Function Parameters


A pointer to an SDL_RWops structure


an offset in bytes, relative to whence location; can be negative


any of RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END; see Remarks for details

Return Value

Returns the final offset in the data stream after the seek or -1 on error.

Code Examples

SDL_RWops *rw = SDL_RWFromFile("myfile.bin", "rb");
if (rw != NULL) {
    /* Seek to 0 bytes from the end of the file */
    Sint64 length = SDL_RWseek(rw, 0, RW_SEEK_END);
    if (length < 0) {
        printf("Could not seek inside myfile.bin\n");
    } else {
        printf("myfile.bin is %d bytes long\n", length);


This function seeks to offset relative to whence

whence may be any of the following values:


seek from the beginning of data


seek relative to current read point


seek relative to the end of data

If this stream can not seek, it will return -1.

SDL_RWseek is actually a macro that calls the SDL_RWops's seek method appropriately, to simplify application development.

CategoryAPI, CategoryIO

None: SDL_RWseek (last edited 2015-06-20 20:01:11 by PhilippWiesemann)

Please include your contact information if you'd like to receive a reply.