SDL_RWwrite

Name

SDL_RWwrite -- Helper macro that calls the write function in an SDL_RWops structure

Synopsis

#include "SDL_rwops.h"

#define SDL_RWwrite(ctx, ptr, size, n)  (ctx)->write(ctx, ptr, size, n)

Description

SDL_RWwrite is a macro that calls the write function in an SDL_RWops structure. It takes the same parameters as the write function given in the SDL_RWops structure:

  1. A pointer to an SDL_RWops structure
  2. A pointer to an area in memory to read data from
  3. The size of the memory blocks to write
  4. The exact number of memory blocks to write

Return Value

On success, it returns the number of memory blocks you told it to write. If it couldn't write that exact number of blocks, or the write didn't work at all, it returns -1.

Note: This is not a built-in function. This is a macro that calls whatever write function happens to be in the SDL_RWops structure.

Example

#include <stdio.h>
#include <string.h>
#include "SDL_rwops.h"

int main()
{
  int written;
  char *str="Hello World";

  SDL_RWops *rw=SDL_RWFromFile("test.bin","wb");
  if(rw==NULL)
  {
    fprintf(stderr,"Couldn't open test.bin\n");
    return(1);
  }

  written=SDL_RWwrite(rw,str,1,strlen(str));
  SDL_RWclose(rw);
  if(written<0)
  {
    fprintf(stderr,"Couldn't write to test.bin\n");
    return(2);
  }

  fprintf(stderr,"Wrote %d 1-byte blocks\n",written);
  return(0);
}

See Also

SDL_RWseek, SDL_RWread, SDL_RWclose, SDL_RWFromFile

SDL_RWwrite (last edited 2008-04-17 08:18:56 by localhost)