annotate playsound/physfsrwops.c @ 474:c66080364dff

Most decoders now report total sample play time, now. Technically, this breaks binary compatibility with the 1.0 branch, since it extends the Sound_Sample struct, but most (all?) programs are just passing pointers allocated by SDL_sound around, and might be okay. Source-level compatibility is not broken...yet! :) --ryan. -------- Original Message -------- Subject: SDL_sound patch: Finding total length of time of sound file. Date: Sun, 26 Jan 2003 09:31:17 -0800 (PST) Hi Ryan, I am working with Eric Wing and helping him modify SDL_sound. AS part of our efforts in improving and enhancing SDL_sound, we like to submit this patch. We modified the codecs to find the total time of a sound file. Below is the explanation of the patch. The patch is appended as an attachment to this email. * MOTIVATION: We needed the ability to get the total play time of a sample (And we noticed that we're not the only ones). Since SDL_sound blocks direct access to the specific decoders, there is no way for a user to know this information short of decoding the whole thing. Because of this, we believe this will be a useful addition, even though the accuracy may not be perfect (subject to each decoder) or the information may not always be available. * CONTRIBUTORS: Wesley Leong (modified the majority of the codecs and verified the results) Eric Wing (showed everyone how to do modify codec, modified mikmod) Wang Lam (modified a handful of codecs, researched into specs and int overflow) Ahilan Anantha (modified a few codecs and helped with integer math) * GENERAL ISSUES: We chose the value to be milliseconds as an Sint32. Milliseconds because that's what Sound_Seek takes as a parameter and -1 to allow for instances/codecs where the value could not be determined. We are not sure if this is the final convention you want, so we are willing to work with you on this. We also expect the total_time field to be set on open and never again modified by SDL_sound. Users may access it directly much like the sample buffer and buffer_size. We thought about recomputing the time on DecodeAll, but since users may seek or decode small chunks first, not all the data may be there. So this is better done by the user. This may be good information to document. Currently, all the main codecs are implemented except for QuickTime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 08 May 2004 08:19:50 +0000
parents d8c0315deba9
children 35dfa9d9782e
rev   line source
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * This code provides a glue layer between PhysicsFS and Simple Directmedia
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Layer's (SDL) RWops i/o abstraction.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * License: this code is public domain. I make no warranty that it is useful,
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * correct, harmless, or environmentally safe.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * This particular file may be used however you like, including copying it
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 * verbatim into a closed-source project, exploiting it commercially, and
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * removing any trace of my name from the source (although I hope you won't
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * do that). I welcome enhancements and corrections to this file, but I do
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * not require you to send me patches if you make changes.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 * Unless otherwise stated, the rest of PhysicsFS falls under the GNU Lesser
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * General Public License: http://www.gnu.org/licenses/lgpl.txt
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * SDL falls under the LGPL, too. You can get SDL at http://www.libsdl.org/
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 * This file was written by Ryan C. Gordon. (icculus@clutteredmind.org).
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 #include <stdio.h> /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 #include "physfsrwops.h"
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 int pos = 0;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 if (whence == SEEK_SET)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 pos = offset;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 } /* if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 else if (whence == SEEK_CUR)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 {
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
37 PHYSFS_sint64 current = PHYSFS_tell(handle);
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 if (current == -1)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 SDL_SetError("Can't find position in file: %s",
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 PHYSFS_getLastError());
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 return(-1);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 } /* if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
45 pos = (int) current;
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
46 if ( ((PHYSFS_sint64) pos) != current )
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
47 {
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
48 SDL_SetError("Can't fit current file position in an int!");
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
49 return(-1);
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
50 } /* if */
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
51
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 if (offset == 0) /* this is a "tell" call. We're done. */
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
53 return(pos);
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
55 pos += offset;
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 } /* else if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 else if (whence == SEEK_END)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 {
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
60 PHYSFS_sint64 len = PHYSFS_fileLength(handle);
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 if (len == -1)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 return(-1);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 } /* if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
67 pos = (int) len;
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
68 if ( ((PHYSFS_sint64) pos) != len )
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
69 {
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
70 SDL_SetError("Can't fit end-of-file position in an int!");
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
71 return(-1);
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
72 } /* if */
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
73
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
74 pos += offset;
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 } /* else if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 else
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 SDL_SetError("Invalid 'whence' parameter.");
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 return(-1);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 } /* else */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
83 if ( pos < 0 )
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
84 {
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
85 SDL_SetError("Attempt to seek past start of file.");
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
86 return(-1);
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
87 } /* if */
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
88
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
89 if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 return(-1);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 } /* if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 return(pos);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 } /* physfsrwops_seek */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
102 PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 if (rc != maxnum)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 } /* if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
109 return((int) rc);
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 } /* physfsrwops_read */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
116 PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 if (rc != num)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119
296
d8c0315deba9 Updated to fix bugs and deal with API breakage in PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents: 286
diff changeset
120 return((int) rc);
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 } /* physfsrwops_write */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 static int physfsrwops_close(SDL_RWops *rw)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 if (!PHYSFS_close(handle))
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 return(-1);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 } /* if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 SDL_FreeRW(rw);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 return(0);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 } /* physfsrwops_close */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 static SDL_RWops *create_rwops(PHYSFS_file *handle)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 SDL_RWops *retval = NULL;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 if (handle == NULL)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 else
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 retval = SDL_AllocRW();
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 if (retval != NULL)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 retval->seek = physfsrwops_seek;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 retval->read = physfsrwops_read;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 retval->write = physfsrwops_write;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 retval->close = physfsrwops_close;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 retval->hidden.unknown.data1 = handle;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 } /* if */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 } /* else */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 return(retval);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 } /* create_rwops */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 SDL_RWops *retval = NULL;
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 if (handle == NULL)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 else
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 retval = create_rwops(handle);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 return(retval);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 } /* PHYSFSRWOPS_makeRWops */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 return(create_rwops(PHYSFS_openRead(fname)));
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 } /* PHYSFSRWOPS_openRead */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 return(create_rwops(PHYSFS_openWrite(fname)));
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 } /* PHYSFSRWOPS_openWrite */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 return(create_rwops(PHYSFS_openAppend(fname)));
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 } /* PHYSFSRWOPS_openAppend */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 /* end of physfsrwops.c ... */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192