2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 /* This file provides a general interface for SDL to read and write
24 data sources. It can easily be extended to files, memory, etc.
30 #include "SDL_config.h"
36 #include "SDL_types.h"
38 #include "begin_code.h"
39 /* Set up for C function definitions, even when using C++ */
44 /* This is the read/write operation structure -- very basic */
46 typedef struct SDL_RWops {
47 /* Seek to 'offset' relative to whence, one of stdio's whence values:
48 SEEK_SET, SEEK_CUR, SEEK_END
49 Returns the final offset in the data source.
51 int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence);
53 /* Read up to 'num' objects each of size 'objsize' from the data
54 source to the area pointed at by 'ptr'.
55 Returns the number of objects read, or -1 if the read failed.
57 int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
59 /* Write exactly 'num' objects each of size 'objsize' from the area
60 pointed at by 'ptr' to data source.
61 Returns 'num', or -1 if the write failed.
63 int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num);
65 /* Close and free an allocated SDL_FSops structure */
66 int (SDLCALL *close)(struct SDL_RWops *context);
89 /* Functions to create SDL_RWops structures from various data sources */
91 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode);
94 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose);
97 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size);
98 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size);
100 extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void);
101 extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
103 #define RW_SEEK_SET 0 /* Seek from the beginning of data */
104 #define RW_SEEK_CUR 1 /* Seek relative to current read point */
105 #define RW_SEEK_END 2 /* Seek relative to the end of data */
107 /* Macros to easily read and write from an SDL_RWops structure */
108 #define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
109 #define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
110 #define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
111 #define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
112 #define SDL_RWclose(ctx) (ctx)->close(ctx)
115 /* Ends C function definitions when using C++ */
119 #include "close_code.h"
121 #endif /* _SDL_RWops_h */