DRAFT

SDL_RWread

Use this function to read from a data source -or- *call the function pointed to by an SDL_RWops structure's read member.*

Syntax

size_t SDL_RWread(struct SDL_RWops* context,
                  void*             ptr,
                  size_t            size,
                  size_t            maxnum)

Function Parameters

context

a pointer to an SDL_RWops structure containing the read function???

ptr

*a pointer to an area of memory to read data into*

size

*the size of each block of memory to read*

maxnum

*the maximum number of memory blocks to read (it may read less)*

I think ptr is an exception to the 'pointer rule'.

Return Value

Returns the number of objects read, or 0 at error or end of file; call SDL_GetError() for more information.

-or-

*Returns the number of memory blocks read, or -1 if the read failed*; call SDL_GetError() for more information.

Code Examples

*

#include <stdio.h>
#include "SDL_rwops.h"
int main()
{
  int blocks;
  char buf[256];
  SDL_RWops *rw=SDL_RWFromFile("file.bin","rb");
  if(rw==NULL)
  {
    fprintf(stderr,"Couldn't open file.bin\n");
    return(1);
  }

  blocks=SDL_RWread(rw,buf,16,256/16);
  SDL_RWclose(rw);
  if(blocks<0)
  {
    fprintf(stderr,"Couldn't read from file.bin\n");
    return(2);
  }

  fprintf(stderr,"Read %d 16-byte blocks\n",blocks);
  return(0);
}

*

Remarks

*
This is not a built in function. This is a C macro that calls whatever function happens to be in the 'read' member of the SDL_RWops structure.
*

SDL_RWread reads up to maxnum objects each of size size from the data source to the area pointed at by ptr. Should SDL_RWread have () like a function even though it's a macro?

Should the current read and write functions (not macros) be listed?


CategoryAPI, CategoryIO

SDL_RWread (last edited 2010-10-13 18:56:23 by SheenaSmith)

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