Subversion Repositories Kolibri OS

Rev

Rev 8209 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8209 Rev 9561
1
/*
1
/*
2
    SDL - Simple DirectMedia Layer
2
    SDL - Simple DirectMedia Layer
3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
4
 
4
 
5
    This library is free software; you can redistribute it and/or
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
8
    version 2 of the License, or (at your option) any later version.
9
 
9
 
10
    This library is distributed in the hope that it will be useful,
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
13
    Library General Public License for more details.
14
 
14
 
15
    You should have received a copy of the GNU Library General Public
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
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
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
18
 
19
    Sam Lantinga
19
    Sam Lantinga
20
    slouken@devolution.com
20
    slouken@devolution.com
21
*/
21
*/
22
 
22
 
23
#ifdef SAVE_RCSID
23
#ifdef SAVE_RCSID
24
static char rcsid =
24
static char rcsid =
25
 "@(#) $Id: SDL_rwops.h,v 1.2 2001/04/26 16:50:17 hercules Exp $";
25
 "@(#) $Id: SDL_rwops.h,v 1.2 2001/04/26 16:50:17 hercules Exp $";
26
#endif
26
#endif
27
 
27
 
28
/* This file provides a general interface for SDL to read and write
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.
29
   data sources.  It can easily be extended to files, memory, etc.
30
*/
30
*/
31
 
31
 
32
#ifndef _SDL_RWops_h
32
#ifndef _SDL_RWops_h
33
#define _SDL_RWops_h
33
#define _SDL_RWops_h
34
 
34
 
35
#include 
35
#include 
36
 
36
 
37
#include "SDL_types.h"
37
#include "SDL_types.h"
38
 
38
 
39
#include "begin_code.h"
39
#include "begin_code.h"
40
/* Set up for C function definitions, even when using C++ */
40
/* Set up for C function definitions, even when using C++ */
41
#ifdef __cplusplus
41
#ifdef __cplusplus
42
extern "C" {
42
extern "C" {
43
#endif
43
#endif
44
 
44
 
45
/* This is the read/write operation structure -- very basic */
45
/* This is the read/write operation structure -- very basic */
46
 
46
 
47
typedef struct SDL_RWops {
47
typedef struct SDL_RWops {
48
	/* Seek to 'offset' relative to whence, one of stdio's whence values:
48
	/* Seek to 'offset' relative to whence, one of stdio's whence values:
49
		SEEK_SET, SEEK_CUR, SEEK_END
49
		SEEK_SET, SEEK_CUR, SEEK_END
50
	   Returns the final offset in the data source.
50
	   Returns the final offset in the data source.
51
	 */
51
	 */
52
	int (*seek)(struct SDL_RWops *context, int offset, int whence);
52
	int (*seek)(struct SDL_RWops *context, int offset, int whence);
53
 
53
 
54
	/* Read up to 'num' objects each of size 'objsize' from the data
54
	/* Read up to 'num' objects each of size 'objsize' from the data
55
	   source to the area pointed at by 'ptr'.
55
	   source to the area pointed at by 'ptr'.
56
	   Returns the number of objects read, or -1 if the read failed.
56
	   Returns the number of objects read, or -1 if the read failed.
57
	 */
57
	 */
58
	int (*read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
58
	int (*read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
59
 
59
 
60
	/* Write exactly 'num' objects each of size 'objsize' from the area
60
	/* Write exactly 'num' objects each of size 'objsize' from the area
61
	   pointed at by 'ptr' to data source.
61
	   pointed at by 'ptr' to data source.
62
	   Returns 'num', or -1 if the write failed.
62
	   Returns 'num', or -1 if the write failed.
63
	 */
63
	 */
64
	int (*write)(struct SDL_RWops *context, const void *ptr, int size, int num);
64
	int (*write)(struct SDL_RWops *context, const void *ptr, int size, int num);
65
 
65
 
66
	/* Close and free an allocated SDL_FSops structure */
66
	/* Close and free an allocated SDL_FSops structure */
67
	int (*close)(struct SDL_RWops *context);
67
	int (*close)(struct SDL_RWops *context);
68
 
68
 
69
	Uint32 type;
69
	Uint32 type;
70
	union {
70
	union {
71
	    struct {
71
	    struct {
72
		int autoclose;
72
		int autoclose;
73
	 	FILE *fp;
73
	 	FILE *fp;
74
	    } stdio;
74
	    } stdio;
75
	    struct {
75
	    struct {
76
		Uint8 *base;
76
		Uint8 *base;
77
	 	Uint8 *here;
77
	 	Uint8 *here;
78
		Uint8 *stop;
78
		Uint8 *stop;
79
	    } mem;
79
	    } mem;
80
	    struct {
80
	    struct {
81
		void *data1;
81
		void *data1;
82
	    } unknown;
82
	    } unknown;
83
	} hidden;
83
	} hidden;
84
 
84
 
85
} SDL_RWops;
85
} SDL_RWops;
86
 
86
 
87
 
87
 
88
/* Functions to create SDL_RWops structures from various data sources */
88
/* Functions to create SDL_RWops structures from various data sources */
89
 
89
 
90
extern DECLSPEC SDL_RWops * SDL_RWFromFile(const char *file, const char *mode);
90
extern DECLSPEC SDL_RWops * SDL_RWFromFile(const char *file, const char *mode);
91
 
91
 
92
extern DECLSPEC SDL_RWops * SDL_RWFromFP(FILE *fp, int autoclose);
92
extern DECLSPEC SDL_RWops * SDL_RWFromFP(FILE *fp, int autoclose);
93
 
93
 
94
extern DECLSPEC SDL_RWops * SDL_RWFromMem(void *mem, int size);
94
extern DECLSPEC SDL_RWops * SDL_RWFromMem(void *mem, int size);
95
 
95
 
96
extern DECLSPEC SDL_RWops * SDL_AllocRW(void);
96
extern DECLSPEC SDL_RWops * SDL_AllocRW(void);
97
extern DECLSPEC void SDL_FreeRW(SDL_RWops *area);
97
extern DECLSPEC void SDL_FreeRW(SDL_RWops *area);
-
 
98
 
-
 
99
#define RW_SEEK_SET	SEEK_SET	/**< Seek from the beginning of data */
-
 
100
#define RW_SEEK_CUR	SEEK_CUR	/**< Seek relative to current read point */
-
 
101
#define RW_SEEK_END	SEEK_END	/**< Seek relative to the end of data */
98
 
102
 
99
/* Macros to easily read and write from an SDL_RWops structure */
103
/* Macros to easily read and write from an SDL_RWops structure */
100
#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
104
#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
101
#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, SEEK_CUR)
105
#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, SEEK_CUR)
102
#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
106
#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)
107
#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
104
#define SDL_RWclose(ctx)		(ctx)->close(ctx)
108
#define SDL_RWclose(ctx)		(ctx)->close(ctx)
105
 
109
 
106
 
110
 
107
/* Ends C function definitions when using C++ */
111
/* Ends C function definitions when using C++ */
108
#ifdef __cplusplus
112
#ifdef __cplusplus
109
}
113
}
110
#endif
114
#endif
111
#include "close_code.h"
115
#include "close_code.h"
112
 
116
 
113
#endif /* _SDL_RWops_h */
117
#endif /* _SDL_RWops_h */