Wiki Page Content

Differences between revisions 3 and 13 (spanning 10 versions)
Revision 3 as of 2010-09-22 22:43:29
Size: 1471
Editor: SheenaSmith
Comment: update content - standard return value
Revision 13 as of 2015-06-20 19:55:24
Size: 1477
Comment: Added links to SDL_RWops.
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 close and free an allocated SDL_RWops structure ''-or-'' *call the close function in an SDL_RWops structure*. Use this function to close and free an allocated [[SDL_RWops]] structure.
Line 16: Line 15:
||'''context'''||a pointer to an SDL_RWops structure|| ||'''context'''||[[SDL_RWops]] structure to close||
Line 21: Line 20:
<<Color2(purple,If a write error occurs when flushing data it returns -1.)>>
Line 24: Line 21:
*
Line 26: Line 22:
#include <stdio.h>
#include "SDL_rwops.h"

int main()
{
  SDL_RWops *rw=SDL_RWFromFile("test.bin","r");
  if(rw==NULL)
  {
    fprintf(stderr,"Couldn't open test.bin\n");
    return(1);
  }
  fprintf(stderr,"Opened test.bin\n");
  SDL_RWclose(rw);
  fprintf(stderr,"Closed test.bin\n");
  return(0);
Uint8 buf[256];
SDL_RWops *rw = SDL_RWFromFile("test.bin", "r");
if (rw != NULL) {
    SDL_RWread(rw, buf, sizeof (buf), 1);
    SDL_RWclose(rw);
Line 42: Line 28:
// Go on and use the data in buf...
Line 43: Line 30:
*
Line 46: Line 32:
*<<BR>>This is not a built-in function. This is a macro that calls whatever close function happens to be pointed to by an SDL_RWops structure.<<BR>>* SDL_RWclose() closes and cleans up the [[SDL_RWops]] stream. It releases any resources used by the stream and frees the SDL_RWops itself with [[SDL_FreeRW]](). This returns 0 on success, or -1 if the stream failed to flush to its output (e.g. to disk).

Note that if this fails to flush the stream to disk, this function reports an error, but the SDL_RWops is still invalid once this function returns.

SDL_RWclose() is actually a macro that calls the SDL_RWops's '''close''' method appropriately, to simplify application development.
Line 49: Line 39:
 .[[SDL_RWFromFile]] *
 .[[SDL_RWread]] (Macro) *
 .[[SDL_RWseek]](Macro) *
 .[[SDL_RWwrite]] (Macro) *

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

SDL_RWclose

Use this function to close and free an allocated SDL_RWops structure.

Syntax

int SDL_RWclose(struct SDL_RWops* context)

Function Parameters

context

SDL_RWops structure to close

Return Value

Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.

Code Examples

Uint8 buf[256];
SDL_RWops *rw = SDL_RWFromFile("test.bin", "r");
if (rw != NULL) {
    SDL_RWread(rw, buf, sizeof (buf), 1);
    SDL_RWclose(rw);
}
// Go on and use the data in buf...

Remarks

SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any resources used by the stream and frees the SDL_RWops itself with SDL_FreeRW(). This returns 0 on success, or -1 if the stream failed to flush to its output (e.g. to disk).

Note that if this fails to flush the stream to disk, this function reports an error, but the SDL_RWops is still invalid once this function returns.

SDL_RWclose() is actually a macro that calls the SDL_RWops's close method appropriately, to simplify application development.


CategoryAPI, CategoryIO

None: SDL_RWclose (last edited 2015-06-20 19:55:24 by PhilippWiesemann)

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