Wiki Page Content

Revision 1 as of 2010-07-15 18:41:58

Clear message

DRAFT

SDL_RWread

Use this function (macro) to *call the function pointed to by an SDL_RWops structure's read member.* green

Syntax

SDL_RWread(ctx, ptr, size, n)

green

  • (ctx)->read(ctx, ptr, size, n)

Function Parameters

ctx

*a pointer to an SDL_RWops structure*

ptr

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

size

*the size of each block of memory to read*

n

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

Return Value

*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

*Note: 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.

{i} Bug: until SDL 1.2.9 this function returned inconsistent values, that depend on type of underlying stream. This bug is now solved.*

green


CategoryAPI, CategoryIO

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