include/SDL_rwops.h
changeset 0 74212992fb08
child 251 b8688cfdc232
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_rwops.h	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,113 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* This file provides a general interface for SDL to read and write
    1.32 +   data sources.  It can easily be extended to files, memory, etc.
    1.33 +*/
    1.34 +
    1.35 +#ifndef _SDL_RWops_h
    1.36 +#define _SDL_RWops_h
    1.37 +
    1.38 +#include <stdio.h>
    1.39 +
    1.40 +#include "SDL_types.h"
    1.41 +
    1.42 +#include "begin_code.h"
    1.43 +/* Set up for C function definitions, even when using C++ */
    1.44 +#ifdef __cplusplus
    1.45 +extern "C" {
    1.46 +#endif
    1.47 +
    1.48 +/* This is the read/write operation structure -- very basic */
    1.49 +
    1.50 +typedef struct SDL_RWops {
    1.51 +	/* Seek to 'offset' relative to whence, one of stdio's whence values:
    1.52 +		SEEK_SET, SEEK_CUR, SEEK_END
    1.53 +	   Returns the final offset in the data source.
    1.54 +	 */
    1.55 +	int (*seek)(struct SDL_RWops *context, int offset, int whence);
    1.56 +
    1.57 +	/* Read up to 'num' objects each of size 'objsize' from the data
    1.58 +	   source to the area pointed at by 'ptr'.
    1.59 +	   Returns the number of objects read, or -1 if the read failed.
    1.60 +	 */
    1.61 +	int (*read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
    1.62 +
    1.63 +	/* Write exactly 'num' objects each of size 'objsize' from the area
    1.64 +	   pointed at by 'ptr' to data source.
    1.65 +	   Returns 'num', or -1 if the write failed.
    1.66 +	 */
    1.67 +	int (*write)(struct SDL_RWops *context, const void *ptr, int size, int num);
    1.68 +
    1.69 +	/* Close and free an allocated SDL_FSops structure */
    1.70 +	int (*close)(struct SDL_RWops *context);
    1.71 +
    1.72 +	Uint32 type;
    1.73 +	union {
    1.74 +	    struct {
    1.75 +		int autoclose;
    1.76 +	 	FILE *fp;
    1.77 +	    } stdio;
    1.78 +	    struct {
    1.79 +		Uint8 *base;
    1.80 +	 	Uint8 *here;
    1.81 +		Uint8 *stop;
    1.82 +	    } mem;
    1.83 +	    struct {
    1.84 +		void *data1;
    1.85 +	    } unknown;
    1.86 +	} hidden;
    1.87 +
    1.88 +} SDL_RWops;
    1.89 +
    1.90 +
    1.91 +/* Functions to create SDL_RWops structures from various data sources */
    1.92 +
    1.93 +extern DECLSPEC SDL_RWops * SDL_RWFromFile(const char *file, const char *mode);
    1.94 +
    1.95 +extern DECLSPEC SDL_RWops * SDL_RWFromFP(FILE *fp, int autoclose);
    1.96 +
    1.97 +extern DECLSPEC SDL_RWops * SDL_RWFromMem(void *mem, int size);
    1.98 +
    1.99 +extern DECLSPEC SDL_RWops * SDL_AllocRW(void);
   1.100 +extern DECLSPEC void SDL_FreeRW(SDL_RWops *area);
   1.101 +
   1.102 +/* Macros to easily read and write from an SDL_RWops structure */
   1.103 +#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
   1.104 +#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, SEEK_CUR)
   1.105 +#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
   1.106 +#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
   1.107 +#define SDL_RWclose(ctx)		(ctx)->close(ctx)
   1.108 +
   1.109 +
   1.110 +/* Ends C function definitions when using C++ */
   1.111 +#ifdef __cplusplus
   1.112 +}
   1.113 +#endif
   1.114 +#include "close_code.h"
   1.115 +
   1.116 +#endif /* _SDL_RWops_h */