This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_rwops.h
205 lines (175 loc) · 6.08 KB
1
/*
2
3
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4
5
6
7
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
8
9
10
11
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
12
13
14
15
16
17
18
19
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
20
21
*/
22
/**
23
24
25
* \file SDL_rwops.h
*
* This file provides a general interface for SDL to read and write
26
* data streams. It can easily be extended to files, memory, etc.
27
*/
28
29
30
#ifndef _SDL_rwops_h
#define _SDL_rwops_h
31
32
#include "SDL_stdinc.h"
33
#include "SDL_error.h"
34
35
36
37
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
38
/* *INDENT-OFF* */
39
extern "C" {
40
/* *INDENT-ON* */
41
42
#endif
43
44
45
/**
* This is the read/write operation structure -- very basic.
*/
46
47
typedef struct SDL_RWops
{
48
49
50
51
/**
* Seek to \c offset relative to \c whence, one of stdio's whence values:
* RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
*
52
* \return the final offset in the data stream.
53
*/
54
55
long (SDLCALL * seek) (struct SDL_RWops * context, long offset,
int whence);
56
57
/**
58
* Read up to \c maxnum objects each of size \c size from the data
59
* stream to the area pointed at by \c ptr.
60
61
*
* \return the number of objects read, or 0 at error or end of file.
62
*/
63
64
65
66
size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
size_t size, size_t maxnum);
/**
67
* Write exactly \c num objects each of size \c size from the area
68
* pointed at by \c ptr to data stream.
69
70
*
* \return the number of objects written, or 0 at error or end of file.
71
*/
72
73
size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
size_t size, size_t num);
74
75
76
77
78
/**
* Close and free an allocated SDL_RWops structure.
*
* \return 0 if successful or -1 on write error when flushing data.
79
*/
80
81
82
83
84
int (SDLCALL * close) (struct SDL_RWops * context);
Uint32 type;
union
{
85
#ifdef __WIN32__
86
87
struct
{
88
SDL_bool append;
89
void *h;
90
91
92
struct
{
void *data;
93
94
size_t size;
size_t left;
95
} buffer;
96
} windowsio;
97
#endif
98
99
100
#ifdef HAVE_STDIO_H
struct
{
101
SDL_bool autoclose;
102
103
FILE *fp;
} stdio;
104
#endif
105
106
107
108
109
110
111
112
113
114
115
struct
{
Uint8 *base;
Uint8 *here;
Uint8 *stop;
} mem;
struct
{
void *data1;
} unknown;
} hidden;
116
117
118
119
} SDL_RWops;
120
121
122
/**
* \name RWFrom functions
*
123
* Functions to create SDL_RWops structures from various data streams.
124
125
*/
/*@{*/
126
127
128
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
const char *mode);
129
130
#ifdef HAVE_STDIO_H
131
132
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
SDL_bool autoclose);
133
134
135
#else
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
SDL_bool autoclose);
136
#endif
137
138
139
140
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
int size);
141
142
143
144
/*@}*//*RWFrom functions*/
145
146
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
147
148
149
150
#define RW_SEEK_SET 0 /**< Seek from the beginning of data */
#define RW_SEEK_CUR 1 /**< Seek relative to current read point */
#define RW_SEEK_END 2 /**< Seek relative to the end of data */
151
152
153
154
155
156
157
/**
* \name Read/write macros
*
* Macros to easily read and write from an SDL_RWops structure.
*/
/*@{*/
158
#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
159
#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
160
161
162
#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
#define SDL_RWclose(ctx) (ctx)->close(ctx)
163
/*@}*//*Read/write macros*/
164
165
166
167
168
169
170
171
/**
* \name Read endian functions
*
* Read an item of the specified endianness and return in native format.
*/
/*@{*/
172
173
174
175
176
177
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
178
/*@}*//*Read endian functions*/
179
180
181
182
183
184
185
/**
* \name Write endian functions
*
* Write an item of native format to the specified endianness.
*/
/*@{*/
186
187
188
189
190
191
extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
192
/*@}*//*Write endian functions*/
193
194
195
196
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
197
/* *INDENT-OFF* */
198
}
199
/* *INDENT-ON* */
200
201
202
#endif
#include "close_code.h"
203
#endif /* _SDL_rwops_h */
204
205
/* vi: set ts=4 sw=4 expandtab: */