author | David Yip <dwyip@peach-bun.com> |
Mon, 15 Aug 2016 00:50:58 -0500 | |
changeset 1375 | 20ee02ea086c |
parent 1373 | 527ef3c6a2d6 |
child 1629 | 540be489d50f |
permissions | -rw-r--r-- |
123 | 1 |
/* |
2 |
* This code provides a glue layer between PhysicsFS and Simple Directmedia |
|
3 |
* Layer's (SDL) RWops i/o abstraction. |
|
4 |
* |
|
5 |
* License: this code is public domain. I make no warranty that it is useful, |
|
6 |
* correct, harmless, or environmentally safe. |
|
7 |
* |
|
8 |
* This particular file may be used however you like, including copying it |
|
9 |
* verbatim into a closed-source project, exploiting it commercially, and |
|
10 |
* removing any trace of my name from the source (although I hope you won't |
|
11 |
* do that). I welcome enhancements and corrections to this file, but I do |
|
576
5da65f8e9a50
Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
12 |
* not require you to send me patches if you make changes. This code has |
5da65f8e9a50
Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
13 |
* NO WARRANTY. |
123 | 14 |
* |
576
5da65f8e9a50
Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
15 |
* Unless otherwise stated, the rest of PhysicsFS falls under the zlib license. |
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
16 |
* Please see LICENSE.txt in the root of the source tree. |
123 | 17 |
* |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
18 |
* SDL 1.2 falls under the LGPL license. SDL 1.3+ is zlib, like PhysicsFS. |
1373
527ef3c6a2d6
HTTPS all the things.
Ryan C. Gordon <icculus@icculus.org>
parents:
1364
diff
changeset
|
19 |
* You can get SDL at https://www.libsdl.org/ |
123 | 20 |
* |
767
db29bf06d171
Changed my email address.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
21 |
* This file was written by Ryan C. Gordon. (icculus@icculus.org). |
123 | 22 |
*/ |
23 |
||
24 |
#include <stdio.h> /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */ |
|
25 |
#include "physfsrwops.h" |
|
26 |
||
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
27 |
/* SDL's RWOPS interface changed a little in SDL 2.0... */ |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
28 |
#if defined(SDL_VERSION_ATLEAST) |
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
29 |
#if SDL_VERSION_ATLEAST(2, 0, 0) |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
30 |
#define TARGET_SDL2 1 |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
31 |
#endif |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
32 |
#endif |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
33 |
|
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
34 |
#if !TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
35 |
#define RW_SEEK_SET SEEK_SET |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
36 |
#define RW_SEEK_CUR SEEK_CUR |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
37 |
#define RW_SEEK_END SEEK_END |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
38 |
#endif |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
39 |
|
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
40 |
#if TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
41 |
static Sint64 SDLCALL physfsrwops_size(struct SDL_RWops *rw) |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
42 |
{ |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
43 |
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
44 |
return (Sint64) PHYSFS_fileLength(handle); |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
45 |
} /* physfsrwops_size */ |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
46 |
#endif |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
47 |
|
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
48 |
|
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
49 |
#if TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
50 |
static Sint64 SDLCALL physfsrwops_seek(struct SDL_RWops *rw, Sint64 offset, int whence) |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
51 |
#else |
123 | 52 |
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
53 |
#endif |
123 | 54 |
{ |
654
c0ae01de361d
Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
55 |
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
56 |
PHYSFS_sint64 pos = 0; |
123 | 57 |
|
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
58 |
if (whence == RW_SEEK_SET) |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
59 |
pos = (PHYSFS_sint64) offset; |
123 | 60 |
|
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
61 |
else if (whence == RW_SEEK_CUR) |
123 | 62 |
{ |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
63 |
const PHYSFS_sint64 current = PHYSFS_tell(handle); |
123 | 64 |
if (current == -1) |
65 |
{ |
|
66 |
SDL_SetError("Can't find position in file: %s", |
|
67 |
PHYSFS_getLastError()); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
68 |
return -1; |
123 | 69 |
} /* if */ |
70 |
||
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
71 |
if (offset == 0) /* this is a "tell" call. We're done. */ |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
72 |
{ |
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
73 |
#if TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
74 |
return (Sint64) current; |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
75 |
#else |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
76 |
return (int) current; |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
77 |
#endif |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
78 |
} /* if */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
79 |
|
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
80 |
pos = current + ((PHYSFS_sint64) offset); |
123 | 81 |
} /* else if */ |
82 |
||
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
83 |
else if (whence == RW_SEEK_END) |
123 | 84 |
{ |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
85 |
const PHYSFS_sint64 len = PHYSFS_fileLength(handle); |
123 | 86 |
if (len == -1) |
87 |
{ |
|
88 |
SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError()); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
89 |
return -1; |
123 | 90 |
} /* if */ |
91 |
||
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
92 |
pos = len + ((PHYSFS_sint64) offset); |
123 | 93 |
} /* else if */ |
94 |
||
95 |
else |
|
96 |
{ |
|
97 |
SDL_SetError("Invalid 'whence' parameter."); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
98 |
return -1; |
123 | 99 |
} /* else */ |
100 |
||
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
101 |
if ( pos < 0 ) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
102 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
103 |
SDL_SetError("Attempt to seek past start of file."); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
104 |
return -1; |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
105 |
} /* if */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
106 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
123
diff
changeset
|
107 |
if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos)) |
123 | 108 |
{ |
109 |
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
110 |
return -1; |
123 | 111 |
} /* if */ |
112 |
||
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
113 |
#if TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
114 |
return (Sint64) pos; |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
115 |
#else |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
116 |
return (int) pos; |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
117 |
#endif |
123 | 118 |
} /* physfsrwops_seek */ |
119 |
||
120 |
||
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
121 |
#if TARGET_SDL2 |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
122 |
static size_t SDLCALL physfsrwops_read(struct SDL_RWops *rw, void *ptr, |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
123 |
size_t size, size_t maxnum) |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
124 |
#else |
123 | 125 |
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
126 |
#endif |
123 | 127 |
{ |
654
c0ae01de361d
Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
128 |
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
129 |
const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size); |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
130 |
const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen); |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
131 |
if (rc != ((PHYSFS_sint64) readlen)) |
123 | 132 |
{ |
133 |
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */ |
|
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
134 |
{ |
123 | 135 |
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
136 |
|
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
137 |
#if TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
138 |
return 0; |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
139 |
#else |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
140 |
return -1; |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
141 |
#endif |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
142 |
} /* if */ |
123 | 143 |
} /* if */ |
144 |
||
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
145 |
#if TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
146 |
return (size_t) rc / size; |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
147 |
#else |
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
148 |
return (int) rc / size; |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
149 |
#endif |
123 | 150 |
} /* physfsrwops_read */ |
151 |
||
152 |
||
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
153 |
#if TARGET_SDL2 |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
154 |
static size_t SDLCALL physfsrwops_write(struct SDL_RWops *rw, const void *ptr, |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
155 |
size_t size, size_t num) |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
156 |
#else |
123 | 157 |
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
158 |
#endif |
123 | 159 |
{ |
654
c0ae01de361d
Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
160 |
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
161 |
const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size); |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
162 |
const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen); |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
163 |
if (rc != ((PHYSFS_sint64) writelen)) |
123 | 164 |
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
165 |
||
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
166 |
#if TARGET_SDL2 |
1193
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
167 |
return (size_t) rc; |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
168 |
#else |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
169 |
return (int) rc; |
e4cc35000826
Add support for SDL 1.3 to physfsrwops.
Ryan C. Gordon <icculus@icculus.org>
parents:
1192
diff
changeset
|
170 |
#endif |
123 | 171 |
} /* physfsrwops_write */ |
172 |
||
173 |
||
174 |
static int physfsrwops_close(SDL_RWops *rw) |
|
175 |
{ |
|
654
c0ae01de361d
Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
176 |
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
123 | 177 |
if (!PHYSFS_close(handle)) |
178 |
{ |
|
179 |
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
180 |
return -1; |
123 | 181 |
} /* if */ |
182 |
||
183 |
SDL_FreeRW(rw); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
184 |
return 0; |
123 | 185 |
} /* physfsrwops_close */ |
186 |
||
187 |
||
654
c0ae01de361d
Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
188 |
static SDL_RWops *create_rwops(PHYSFS_File *handle) |
123 | 189 |
{ |
190 |
SDL_RWops *retval = NULL; |
|
191 |
||
192 |
if (handle == NULL) |
|
193 |
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
|
194 |
else |
|
195 |
{ |
|
196 |
retval = SDL_AllocRW(); |
|
197 |
if (retval != NULL) |
|
198 |
{ |
|
1364
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
199 |
#if TARGET_SDL2 |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
200 |
retval->size = physfsrwops_size; |
61d312843192
Fixes to SDL_RWops bridge code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1193
diff
changeset
|
201 |
#endif |
123 | 202 |
retval->seek = physfsrwops_seek; |
203 |
retval->read = physfsrwops_read; |
|
204 |
retval->write = physfsrwops_write; |
|
205 |
retval->close = physfsrwops_close; |
|
206 |
retval->hidden.unknown.data1 = handle; |
|
207 |
} /* if */ |
|
208 |
} /* else */ |
|
209 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
210 |
return retval; |
123 | 211 |
} /* create_rwops */ |
212 |
||
213 |
||
654
c0ae01de361d
Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
214 |
SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle) |
123 | 215 |
{ |
216 |
SDL_RWops *retval = NULL; |
|
217 |
if (handle == NULL) |
|
218 |
SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops()."); |
|
219 |
else |
|
220 |
retval = create_rwops(handle); |
|
221 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
222 |
return retval; |
123 | 223 |
} /* PHYSFSRWOPS_makeRWops */ |
224 |
||
225 |
||
226 |
SDL_RWops *PHYSFSRWOPS_openRead(const char *fname) |
|
227 |
{ |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
228 |
return create_rwops(PHYSFS_openRead(fname)); |
123 | 229 |
} /* PHYSFSRWOPS_openRead */ |
230 |
||
231 |
||
232 |
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname) |
|
233 |
{ |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
234 |
return create_rwops(PHYSFS_openWrite(fname)); |
123 | 235 |
} /* PHYSFSRWOPS_openWrite */ |
236 |
||
237 |
||
238 |
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname) |
|
239 |
{ |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
240 |
return create_rwops(PHYSFS_openAppend(fname)); |
123 | 241 |
} /* PHYSFSRWOPS_openAppend */ |
242 |
||
243 |
||
244 |
/* end of physfsrwops.c ... */ |
|
245 |