Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
205 lines (175 loc) · 6.08 KB

SDL_rwops.h

File metadata and controls

205 lines (175 loc) · 6.08 KB
 
Apr 26, 2001
Apr 26, 2001
1
/*
Apr 8, 2011
Apr 8, 2011
2
3
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
Apr 26, 2001
Apr 26, 2001
4
Apr 8, 2011
Apr 8, 2011
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.
Apr 26, 2001
Apr 26, 2001
8
Apr 8, 2011
Apr 8, 2011
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:
Apr 26, 2001
Apr 26, 2001
12
Apr 8, 2011
Apr 8, 2011
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.
Apr 26, 2001
Apr 26, 2001
20
21
*/
Jul 10, 2006
Jul 10, 2006
22
/**
Oct 19, 2009
Oct 19, 2009
23
24
25
* \file SDL_rwops.h
*
* This file provides a general interface for SDL to read and write
Jan 12, 2011
Jan 12, 2011
26
* data streams. It can easily be extended to files, memory, etc.
Jul 10, 2006
Jul 10, 2006
27
*/
Apr 26, 2001
Apr 26, 2001
28
Feb 21, 2006
Feb 21, 2006
29
30
#ifndef _SDL_rwops_h
#define _SDL_rwops_h
Apr 26, 2001
Apr 26, 2001
31
Feb 9, 2006
Feb 9, 2006
32
#include "SDL_stdinc.h"
Feb 10, 2006
Feb 10, 2006
33
#include "SDL_error.h"
Apr 26, 2001
Apr 26, 2001
34
35
36
37
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
Jul 10, 2006
Jul 10, 2006
38
/* *INDENT-OFF* */
Apr 26, 2001
Apr 26, 2001
39
extern "C" {
Jul 10, 2006
Jul 10, 2006
40
/* *INDENT-ON* */
Apr 26, 2001
Apr 26, 2001
41
42
#endif
Oct 19, 2009
Oct 19, 2009
43
44
45
/**
* This is the read/write operation structure -- very basic.
*/
Jul 10, 2006
Jul 10, 2006
46
47
typedef struct SDL_RWops
{
Oct 19, 2009
Oct 19, 2009
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
*
Jan 12, 2011
Jan 12, 2011
52
* \return the final offset in the data stream.
Jul 10, 2006
Jul 10, 2006
53
*/
Jul 10, 2007
Jul 10, 2007
54
55
long (SDLCALL * seek) (struct SDL_RWops * context, long offset,
int whence);
Jul 10, 2006
Jul 10, 2006
56
Oct 19, 2009
Oct 19, 2009
57
/**
Jan 6, 2010
Jan 6, 2010
58
* Read up to \c maxnum objects each of size \c size from the data
Jan 12, 2011
Jan 12, 2011
59
* stream to the area pointed at by \c ptr.
Oct 19, 2009
Oct 19, 2009
60
61
*
* \return the number of objects read, or 0 at error or end of file.
Jul 10, 2006
Jul 10, 2006
62
*/
Oct 19, 2009
Oct 19, 2009
63
64
65
66
size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
size_t size, size_t maxnum);
/**
Aug 23, 2010
Aug 23, 2010
67
* Write exactly \c num objects each of size \c size from the area
Jan 12, 2011
Jan 12, 2011
68
* pointed at by \c ptr to data stream.
Oct 19, 2009
Oct 19, 2009
69
70
*
* \return the number of objects written, or 0 at error or end of file.
Jul 10, 2006
Jul 10, 2006
71
*/
Oct 19, 2009
Oct 19, 2009
72
73
size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
size_t size, size_t num);
Jul 10, 2006
Jul 10, 2006
74
Oct 19, 2009
Oct 19, 2009
75
76
77
78
/**
* Close and free an allocated SDL_RWops structure.
*
* \return 0 if successful or -1 on write error when flushing data.
Jul 10, 2007
Jul 10, 2007
79
*/
Jul 10, 2006
Jul 10, 2006
80
81
82
83
84
int (SDLCALL * close) (struct SDL_RWops * context);
Uint32 type;
union
{
Jan 24, 2011
Jan 24, 2011
85
#ifdef __WIN32__
Jul 10, 2006
Jul 10, 2006
86
87
struct
{
Jul 10, 2007
Jul 10, 2007
88
SDL_bool append;
Jul 10, 2006
Jul 10, 2006
89
void *h;
Jul 10, 2007
Jul 10, 2007
90
91
92
struct
{
void *data;
Sep 5, 2009
Sep 5, 2009
93
94
size_t size;
size_t left;
Jul 10, 2007
Jul 10, 2007
95
} buffer;
Jan 21, 2011
Jan 21, 2011
96
} windowsio;
Feb 27, 2006
Feb 27, 2006
97
#endif
Jul 10, 2006
Jul 10, 2006
98
99
100
#ifdef HAVE_STDIO_H
struct
{
Jul 10, 2007
Jul 10, 2007
101
SDL_bool autoclose;
Jul 10, 2006
Jul 10, 2006
102
103
FILE *fp;
} stdio;
Feb 6, 2006
Feb 6, 2006
104
#endif
Jul 10, 2006
Jul 10, 2006
105
106
107
108
109
110
111
112
113
114
115
struct
{
Uint8 *base;
Uint8 *here;
Uint8 *stop;
} mem;
struct
{
void *data1;
} unknown;
} hidden;
Apr 26, 2001
Apr 26, 2001
116
117
118
119
} SDL_RWops;
Oct 19, 2009
Oct 19, 2009
120
121
122
/**
* \name RWFrom functions
*
Jan 12, 2011
Jan 12, 2011
123
* Functions to create SDL_RWops structures from various data streams.
Oct 19, 2009
Oct 19, 2009
124
125
*/
/*@{*/
Apr 26, 2001
Apr 26, 2001
126
Jul 10, 2006
Jul 10, 2006
127
128
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
const char *mode);
Apr 26, 2001
Apr 26, 2001
129
Feb 6, 2006
Feb 6, 2006
130
#ifdef HAVE_STDIO_H
Jul 10, 2007
Jul 10, 2007
131
132
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
SDL_bool autoclose);
Dec 15, 2009
Dec 15, 2009
133
134
135
#else
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
SDL_bool autoclose);
Feb 6, 2006
Feb 6, 2006
136
#endif
Apr 26, 2001
Apr 26, 2001
137
Jul 10, 2006
Jul 10, 2006
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);
Apr 26, 2001
Apr 26, 2001
141
Oct 19, 2009
Oct 19, 2009
142
143
144
/*@}*//*RWFrom functions*/
Jul 10, 2006
Jul 10, 2006
145
146
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
Apr 26, 2001
Apr 26, 2001
147
Oct 19, 2009
Oct 19, 2009
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 */
Feb 6, 2006
Feb 6, 2006
151
Oct 19, 2009
Oct 19, 2009
152
153
154
155
156
157
/**
* \name Read/write macros
*
* Macros to easily read and write from an SDL_RWops structure.
*/
/*@{*/
Apr 26, 2001
Apr 26, 2001
158
#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
Feb 6, 2006
Feb 6, 2006
159
#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
Apr 26, 2001
Apr 26, 2001
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)
Oct 19, 2009
Oct 19, 2009
163
/*@}*//*Read/write macros*/
Apr 26, 2001
Apr 26, 2001
164
165
Oct 19, 2009
Oct 19, 2009
166
167
168
169
170
171
/**
* \name Read endian functions
*
* Read an item of the specified endianness and return in native format.
*/
/*@{*/
Jul 10, 2006
Jul 10, 2006
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);
Oct 19, 2009
Oct 19, 2009
178
/*@}*//*Read endian functions*/
Feb 9, 2006
Feb 9, 2006
179
Oct 19, 2009
Oct 19, 2009
180
181
182
183
184
185
/**
* \name Write endian functions
*
* Write an item of native format to the specified endianness.
*/
/*@{*/
Sep 5, 2009
Sep 5, 2009
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);
Oct 19, 2009
Oct 19, 2009
192
/*@}*//*Write endian functions*/
Feb 9, 2006
Feb 9, 2006
193
194
Apr 26, 2001
Apr 26, 2001
195
196
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Jul 10, 2006
Jul 10, 2006
197
/* *INDENT-OFF* */
Apr 26, 2001
Apr 26, 2001
198
}
Jul 10, 2006
Jul 10, 2006
199
/* *INDENT-ON* */
Apr 26, 2001
Apr 26, 2001
200
201
202
#endif
#include "close_code.h"
Feb 21, 2006
Feb 21, 2006
203
#endif /* _SDL_rwops_h */
Jul 10, 2006
Jul 10, 2006
204
205
/* vi: set ts=4 sw=4 expandtab: */