slouken@0
|
1 |
/*
|
slouken@0
|
2 |
SDL - Simple DirectMedia Layer
|
slouken@1312
|
3 |
Copyright (C) 1997-2006 Sam Lantinga
|
slouken@0
|
4 |
|
slouken@0
|
5 |
This library is free software; you can redistribute it and/or
|
slouken@1312
|
6 |
modify it under the terms of the GNU Lesser General Public
|
slouken@0
|
7 |
License as published by the Free Software Foundation; either
|
slouken@1312
|
8 |
version 2.1 of the License, or (at your option) any later version.
|
slouken@0
|
9 |
|
slouken@0
|
10 |
This library is distributed in the hope that it will be useful,
|
slouken@0
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
slouken@0
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
slouken@1312
|
13 |
Lesser General Public License for more details.
|
slouken@0
|
14 |
|
slouken@1312
|
15 |
You should have received a copy of the GNU Lesser General Public
|
slouken@1312
|
16 |
License along with this library; if not, write to the Free Software
|
slouken@1312
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
slouken@0
|
18 |
|
slouken@0
|
19 |
Sam Lantinga
|
slouken@251
|
20 |
slouken@libsdl.org
|
slouken@0
|
21 |
*/
|
slouken@0
|
22 |
|
slouken@0
|
23 |
/* This file provides a general interface for SDL to read and write
|
slouken@0
|
24 |
data sources. It can easily be extended to files, memory, etc.
|
slouken@0
|
25 |
*/
|
slouken@0
|
26 |
|
slouken@1402
|
27 |
#ifndef _SDL_rwops_h
|
slouken@1402
|
28 |
#define _SDL_rwops_h
|
slouken@0
|
29 |
|
slouken@1354
|
30 |
#include "SDL_stdinc.h"
|
slouken@1358
|
31 |
#include "SDL_error.h"
|
slouken@1330
|
32 |
|
slouken@0
|
33 |
#include "begin_code.h"
|
slouken@0
|
34 |
/* Set up for C function definitions, even when using C++ */
|
slouken@0
|
35 |
#ifdef __cplusplus
|
slouken@0
|
36 |
extern "C" {
|
slouken@0
|
37 |
#endif
|
slouken@0
|
38 |
|
slouken@0
|
39 |
/* This is the read/write operation structure -- very basic */
|
slouken@0
|
40 |
|
slouken@0
|
41 |
typedef struct SDL_RWops {
|
slouken@0
|
42 |
/* Seek to 'offset' relative to whence, one of stdio's whence values:
|
slouken@0
|
43 |
SEEK_SET, SEEK_CUR, SEEK_END
|
slouken@0
|
44 |
Returns the final offset in the data source.
|
slouken@0
|
45 |
*/
|
slouken@930
|
46 |
int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence);
|
slouken@0
|
47 |
|
slouken@0
|
48 |
/* Read up to 'num' objects each of size 'objsize' from the data
|
slouken@0
|
49 |
source to the area pointed at by 'ptr'.
|
slouken@0
|
50 |
Returns the number of objects read, or -1 if the read failed.
|
slouken@0
|
51 |
*/
|
slouken@930
|
52 |
int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
|
slouken@0
|
53 |
|
slouken@0
|
54 |
/* Write exactly 'num' objects each of size 'objsize' from the area
|
slouken@0
|
55 |
pointed at by 'ptr' to data source.
|
slouken@0
|
56 |
Returns 'num', or -1 if the write failed.
|
slouken@0
|
57 |
*/
|
slouken@930
|
58 |
int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num);
|
slouken@0
|
59 |
|
slouken@0
|
60 |
/* Close and free an allocated SDL_FSops structure */
|
slouken@930
|
61 |
int (SDLCALL *close)(struct SDL_RWops *context);
|
slouken@0
|
62 |
|
slouken@0
|
63 |
Uint32 type;
|
slouken@0
|
64 |
union {
|
slouken@1330
|
65 |
#ifdef HAVE_STDIO_H
|
slouken@0
|
66 |
struct {
|
slouken@0
|
67 |
int autoclose;
|
slouken@0
|
68 |
FILE *fp;
|
slouken@0
|
69 |
} stdio;
|
slouken@1330
|
70 |
#endif
|
slouken@0
|
71 |
struct {
|
slouken@0
|
72 |
Uint8 *base;
|
slouken@0
|
73 |
Uint8 *here;
|
slouken@0
|
74 |
Uint8 *stop;
|
slouken@0
|
75 |
} mem;
|
slouken@0
|
76 |
struct {
|
slouken@0
|
77 |
void *data1;
|
slouken@0
|
78 |
} unknown;
|
slouken@0
|
79 |
} hidden;
|
slouken@0
|
80 |
|
slouken@0
|
81 |
} SDL_RWops;
|
slouken@0
|
82 |
|
slouken@0
|
83 |
|
slouken@0
|
84 |
/* Functions to create SDL_RWops structures from various data sources */
|
slouken@0
|
85 |
|
slouken@337
|
86 |
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode);
|
slouken@0
|
87 |
|
slouken@1330
|
88 |
#ifdef HAVE_STDIO_H
|
slouken@337
|
89 |
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose);
|
slouken@1330
|
90 |
#endif
|
slouken@0
|
91 |
|
slouken@337
|
92 |
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size);
|
slouken@764
|
93 |
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size);
|
slouken@0
|
94 |
|
slouken@337
|
95 |
extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void);
|
slouken@337
|
96 |
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
|
slouken@0
|
97 |
|
slouken@1330
|
98 |
#define RW_SEEK_SET 0 /* Seek from the beginning of data */
|
slouken@1330
|
99 |
#define RW_SEEK_CUR 1 /* Seek relative to current read point */
|
slouken@1330
|
100 |
#define RW_SEEK_END 2 /* Seek relative to the end of data */
|
slouken@1330
|
101 |
|
slouken@0
|
102 |
/* Macros to easily read and write from an SDL_RWops structure */
|
slouken@0
|
103 |
#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
|
slouken@1330
|
104 |
#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
|
slouken@0
|
105 |
#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
|
slouken@0
|
106 |
#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
|
slouken@0
|
107 |
#define SDL_RWclose(ctx) (ctx)->close(ctx)
|
slouken@0
|
108 |
|
slouken@0
|
109 |
|
slouken@1354
|
110 |
/* Read an item of the specified endianness and return in native format */
|
slouken@1354
|
111 |
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src);
|
slouken@1354
|
112 |
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops *src);
|
slouken@1354
|
113 |
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src);
|
slouken@1354
|
114 |
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src);
|
slouken@1354
|
115 |
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops *src);
|
slouken@1354
|
116 |
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops *src);
|
slouken@1354
|
117 |
|
slouken@1354
|
118 |
/* Write an item of native format to the specified endianness */
|
slouken@1354
|
119 |
extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops *dst, Uint16 value);
|
slouken@1354
|
120 |
extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops *dst, Uint16 value);
|
slouken@1354
|
121 |
extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops *dst, Uint32 value);
|
slouken@1354
|
122 |
extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops *dst, Uint32 value);
|
slouken@1354
|
123 |
extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops *dst, Uint64 value);
|
slouken@1354
|
124 |
extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops *dst, Uint64 value);
|
slouken@1354
|
125 |
|
slouken@1354
|
126 |
|
slouken@0
|
127 |
/* Ends C function definitions when using C++ */
|
slouken@0
|
128 |
#ifdef __cplusplus
|
slouken@0
|
129 |
}
|
slouken@0
|
130 |
#endif
|
slouken@0
|
131 |
#include "close_code.h"
|
slouken@0
|
132 |
|
slouken@1402
|
133 |
#endif /* _SDL_rwops_h */
|