SDL_RWseek

Name

SDL_RWseek -- Helper macro to simplify seeking in an SDL_RWops

Synopsis

#include "SDL_rwops.h"

#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)

Description

SDL_RWseek is a macro that calls the seek function pointer in an SDL_RWops structure. It takes the same 3 parameters as the function pointer:

  1. A pointer to an SDL_RWops structure
  2. An offset in bytes. This can be a negative value.
  3. SEEK_SET, SEEK_CUR, or SEEK_END. SEEK_SET seeks from the beginning of the file, SEEK_CUR from the current position, and SEEK_END from the end of the file.

Return Value

It should return the final offset in the data source.

Note: This is not a predefined function, just a macro that calls whatever seek function has been placed in the SDL_RWops structure.

Example

#include <stdio.h>
#include "SDL_rwops.h"

int main()
{
  int length;
  SDL_RWops *rw=SDL_RWFromFile("myfile.bin","rb");
  if(rw==NULL)
  {
    fprintf(stderr,"Couldn't open myfile.bin\n");
    return(1);
  }

  /* Seek to 0 bytes from the end of the file -- i.e. the exact end of file */
  length=SDL_RWseek(rw,0,SEEK_END);
  SDL_RWclose(rw);
  if(length<0)
  {
    fprintf(stderr,"Could not seek inside myfile.bin\n");
    return(2);
  }

  fprintf(stderr,"myfile.bin is %d bytes long\n",length);
  return(0);
}

See Also

SDL_RWread, SDL_RWwrite, SDL_RWclose

SDL_RWseek (last edited 2008-04-17 08:18:10 by localhost)