38
|
1 #ifndef ALMIXER_RWOPS
|
|
2 #define ALMIXER_RWOPS
|
|
3
|
|
4 #if defined(_WIN32)
|
|
5 #if defined(ALMIXER_RWOPS_BUILD_LIBRARY)
|
|
6 #define ALMIXER_RWOPS_DECLSPEC __declspec(dllexport)
|
|
7 #else
|
|
8 #define ALMIXER_RWOPS_DECLSPEC __declspec(dllimport)
|
|
9 #endif
|
|
10 #else
|
|
11 #if defined(ALMIXER_RWOPS_BUILD_LIBRARY)
|
|
12 #if defined (__GNUC__) && __GNUC__ >= 4
|
|
13 #define ALMIXER_RWOPS_DECLSPEC __attribute__((visibility("default")))
|
|
14 #else
|
|
15 #define ALMIXER_RWOPS_DECLSPEC
|
|
16 #endif
|
|
17 #else
|
|
18 #define ALMIXER_RWOPS_DECLSPEC
|
|
19 #endif
|
|
20 #endif
|
|
21
|
|
22 #if defined(_WIN32)
|
|
23 #define ALMIXER_RWOPS_CALL __cdecl
|
|
24 #else
|
|
25 #define ALMIXER_RWOPS_CALL
|
|
26 #endif
|
|
27
|
|
28 #ifdef __cplusplus
|
|
29 extern "C" {
|
|
30 #endif
|
|
31
|
|
32 /* Trying to keep compatibility with SDL_RWops,
|
|
33 * but I don't plan on reimplementing everything.
|
|
34 */
|
|
35 #include <stdio.h>
|
|
36 #include <stddef.h>
|
|
37 /* The 'type' parameter needs to be 32-bits to match SDL_RWops.
|
|
38 * <stdint.h> has been problematic for Visual Studio for years.
|
|
39 * It appears that Visual Studio 2010 finally includes this.
|
|
40 */
|
|
41 #include <stdint.h>
|
|
42 typedef struct ALmixer_RWops
|
|
43 {
|
|
44 /** Seek to 'offset' relative to whence, one of stdio's whence values:
|
|
45 * SEEK_SET, SEEK_CUR, SEEK_END
|
|
46 * Returns the final offset in the data source.
|
|
47 * (Note this is different than stdio's seek. This returns ftell.)
|
|
48 */
|
|
49 int (ALMIXER_RWOPS_CALL *seek)(struct ALmixer_RWops* the_context, long offset, int whence);
|
|
50
|
|
51 /** Read up to 'nitems' objects each of size 'size' from the data
|
|
52 * source to the area pointed at by 'ptr'.
|
|
53 * Returns the number of objects read, or -1 if the read failed.
|
|
54 */
|
|
55 size_t (ALMIXER_RWOPS_CALL *read)(struct ALmixer_RWops* the_context, void* ptr, size_t size, size_t nitems);
|
|
56
|
|
57 /** Write exactly 'nitems' objects each of size 'size' from the area
|
|
58 * pointed at by 'ptr' to data source.
|
|
59 * Returns 'num', or -1 if the write failed.
|
|
60 */
|
|
61 size_t (ALMIXER_RWOPS_CALL *write)(struct ALmixer_RWops* the_context, const void* ptr, size_t size, size_t nitems);
|
|
62
|
|
63 /** Close and free an allocated ALmixer_RWops structure */
|
|
64 int (ALMIXER_RWOPS_CALL *close)(struct ALmixer_RWops* the_context);
|
|
65
|
|
66 /* type Needs to be a 32-bit to be compatible with SDL */
|
|
67 uint32_t type;
|
|
68 union
|
|
69 {
|
|
70 #if defined(__WIN32__) && !defined(__SYMBIAN32__)
|
|
71 /* Chances are that I will not implement this path.
|
|
72 * But I want the padding to be the same as SDL.
|
|
73 */
|
|
74 struct
|
|
75 {
|
|
76 int append;
|
|
77 void *h;
|
|
78 struct
|
|
79 {
|
|
80 void *data;
|
|
81 int size;
|
|
82 int left;
|
|
83 } buffer;
|
|
84 } win32io;
|
|
85 #endif
|
|
86 struct
|
|
87 {
|
|
88 int autoclose;
|
|
89 FILE* fp;
|
|
90 } stdio;
|
|
91 struct
|
|
92 {
|
|
93 unsigned char* base;
|
|
94 unsigned char* here;
|
|
95 unsigned char* stop;
|
|
96 } mem;
|
|
97 struct
|
|
98 {
|
|
99 void* data1;
|
|
100 } unknown;
|
|
101 } hidden;
|
|
102 } ALmixer_RWops;
|
|
103
|
|
104 extern ALMIXER_RWOPS_DECLSPEC ALmixer_RWops* ALMIXER_RWOPS_CALL ALmixer_RWFromFile(const char* file_name, const char* file_mode);
|
|
105 extern ALMIXER_RWOPS_DECLSPEC ALmixer_RWops* ALMIXER_RWOPS_CALL ALmixer_RWFromFP(FILE* file_pointer, char autoclose_flag);
|
|
106
|
|
107 #define ALmixer_RWseek(rwops, offset, whence) (rwops)->seek(rwops, offset, whence)
|
|
108 #define ALmixer_RWtell(rwops) (rwops)->seek(rwops, 0, SEEK_CUR)
|
|
109 #define ALmixer_RWread(rwops, ptr, size, nitems) (rwops)->read(rwops, ptr, size, nitems)
|
|
110
|
|
111 /* Ends C function definitions when using C++ */
|
|
112 #ifdef __cplusplus
|
|
113 }
|
|
114 #endif
|
|
115
|
|
116 #endif
|
|
117
|