Wiki Page Content

Differences between revisions 4 and 5
Revision 4 as of 2013-06-15 16:18:57
Size: 2381
Comment: Changed signature to match SDL_main.h.
Revision 5 as of 2013-08-08 18:35:27
Size: 1503
Editor: RyanGordon
Comment: Updated
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
||<tablewidth="100%" style="color: #FF0000;" :> DRAFT||
Line 6: Line 5:
Use this function to read from a data source ''-or-'' *call the function pointed to by an SDL_RWops structure's read member.* Use this function to read from a data source.
Line 19: Line 18:
||'''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)*||

<<Color2(green,I think '''ptr''' is an exception to the 'pointer rule'.)>>
||'''context'''||a pointer to an SDL_RWops structure||
||'''ptr'''||a pointer to a buffer to read data into||
||'''size'''||the size of each object to read, in bytes||
||'''maxnum'''||the maximum number of objects to be read||
Line 29: Line 26:
''-or-''

*Returns the number of memory blocks read, or -1 if the read failed*; call [[SDL_GetError]]() for more information.
Line 34: Line 27:
*
Line 36: Line 28:
#include <stdio.h>
#include "SDL_rwops.h"

int main(int argc, char *argv[])
{
  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_RWops *rw = SDL_RWFromFile("test.bin","r");
if (rw != NULL) {
  extern Uint8 buf[256];
  SDL_RWread(rw, buf, sizeof (buf));
Line 52: Line 33:
  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);
Line 62: Line 35:
*
Line 65: Line 37:
*<<BR>>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.<<BR>>* This function reads up to '''maxnum''' objects each of size '''size''' from the data source to the area pointed at by '''ptr'''. This function may read less objects than requested. It will return zero when there has been an error or the data stream is completely read.
Line 67: Line 39:
[[SDL_RWread]] reads up to '''maxnum''' objects each of size '''size''' from the data source to the area pointed at by '''ptr'''. <<Color2(green,Should SDL_RWread have () like a function even though it's a macro?)>> SDL_RWread is actually a macro that calls the SDL_RWops's '''read''' method appropriately, to simplify application development.
Line 70: Line 42:
 .[[SDL_RWclose]] (Macro) *
 .[[SDL_RWFromFile]] *
 .[[SDL_RWseek]](Macro) *
 .[[SDL_RWwrite]] (Macro) *

<<Color2(green,Should the current read and write functions (not macros) be listed?)>>
 .[[SDL_RWclose]]
 .[[SDL_RWseek]]
 .[[SDL_RWwrite]]

SDL_RWread

Use this function to read from a data source.

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

ptr

a pointer to a buffer to read data into

size

the size of each object to read, in bytes

maxnum

the maximum number of objects to be read

Return Value

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

Code Examples

SDL_RWops *rw = SDL_RWFromFile("test.bin","r");
if (rw != NULL) {
  extern Uint8 buf[256];
  SDL_RWread(rw, buf, sizeof (buf));
  SDL_RWclose(rw);
}

Remarks

This function reads up to maxnum objects each of size size from the data source to the area pointed at by ptr. This function may read less objects than requested. It will return zero when there has been an error or the data stream is completely read.

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


CategoryAPI, CategoryIO

None: SDL_RWread (last edited 2015-09-17 21:55:16 by PhilippWiesemann)

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