2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 slouken@devolution.com
25 "@(#) $Id: SDL_rwops.h,v 1.1.1.1 2003/01/04 11:37:22 leo Exp $";
28 /* This file provides a general interface for SDL to read and write
29 data sources. It can easily be extended to files, memory, etc.
37 #include "SDL_types.h"
39 #include "begin_code.h"
40 /* Set up for C function definitions, even when using C++ */
45 /* This is the read/write operation structure -- very basic */
47 typedef struct SDL_RWops
{
48 /* Seek to 'offset' relative to whence, one of stdio's whence values:
49 SEEK_SET, SEEK_CUR, SEEK_END
50 Returns the final offset in the data source.
52 int (*seek
)(struct SDL_RWops
*context
, int offset
, int whence
);
54 /* Read up to 'num' objects each of size 'objsize' from the data
55 source to the area pointed at by 'ptr'.
56 Returns the number of objects read, or -1 if the read failed.
58 int (*read
)(struct SDL_RWops
*context
, void *ptr
, int size
, int maxnum
);
60 /* Write exactly 'num' objects each of size 'objsize' from the area
61 pointed at by 'ptr' to data source.
62 Returns 'num', or -1 if the write failed.
64 int (*write
)(struct SDL_RWops
*context
, const void *ptr
, int size
, int num
);
66 /* Close and free an allocated SDL_FSops structure */
67 int (*close
)(struct SDL_RWops
*context
);
88 /* Functions to create SDL_RWops structures from various data sources */
90 extern DECLSPEC SDL_RWops
* SDL_RWFromFile(const char *file
, const char *mode
);
92 extern DECLSPEC SDL_RWops
* SDL_RWFromFP(FILE *fp
, int autoclose
);
94 extern DECLSPEC SDL_RWops
* SDL_RWFromMem(void *mem
, int size
);
96 extern DECLSPEC SDL_RWops
* SDL_AllocRW(void);
97 extern DECLSPEC
void SDL_FreeRW(SDL_RWops
*area
);
99 /* Macros to easily read and write from an SDL_RWops structure */
100 #define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
101 #define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, SEEK_CUR)
102 #define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
103 #define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
104 #define SDL_RWclose(ctx) (ctx)->close(ctx)
107 /* Ends C function definitions when using C++ */
111 #include "close_code.h"
113 #endif /* _SDL_RWops_h */