Wiki Page Content

Differences between revisions 1 and 2
Revision 1 as of 2010-07-15 18:41:58
Size: 2227
Editor: SheenaSmith
Comment: create page, add content (Wed Mar 10 ver; changeset 4428)
Revision 2 as of 2010-08-22 20:31:17
Size: 2241
Editor: SheenaSmith
Comment: update content (from Sam)
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
Use this function ^(macro)^ to *call the function pointed to by an SDL_RWops structure's '''read''' member.*  <<Color2(green,Should read be bold here?)>> Use this function to read from a data source ''-or-'' *call the function pointed to by an SDL_RWops structure's read member.*
Line 12: Line 12:
SDL_RWread(ctx, ptr, size, n) size_t SDL_RWread(struct SDL_RWops* context,
                  void* ptr,
                  size_t size,
                  size_t maxnum)
Line 15: Line 18:
<<Color2(green,Should there be anything to indicate a RV at the beginning of the syntax? Should the 4 params be on separate lines like a regular function even though the rest of the syntax is different? Should the following be included in the syntax section?)>>
 {{{(ctx)->read(ctx, ptr, size, n)}}}
Line 19: Line 19:
||'''ctx'''||*a pointer to an SDL_RWops structure*|| ||'''context'''||a pointer to an SDL_RWops structure||
Line 22: Line 22:
||'''n'''||*the maximum number of memory blocks to read (it may read less)*|| ||'''maxnum'''||*the maximum number of memory blocks to read (it may read less)*||
Line 25: Line 25:
Returns the number of objects read, or 0 at error or end of file; call [[SDL_GetError]]() for more information.

''-or-''
Line 58: Line 62:
*,,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. *<<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>>*
Line 60: Line 64:
{i} ''Bug'': until SDL 1.2.9 this function returned inconsistent values, that depend on type of underlying stream. This bug is now solved.* [[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?)>>
Line 63: Line 67:
 .[[SDL_RWclose]] (Macro) *???
 .[[SDL_RWFromFile]] *???
 .[[SDL_RWseek]](Macro) *???
 .[[SDL_RWwrite]] (Macro) *???
 .[[SDL_RWclose]] (Macro) *
 .[[SDL_RWFromFile]] *
 .[[SDL_RWseek]](Macro) *
 .[[SDL_RWwrite]] (Macro) *

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

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)*

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. green

green


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