23 #include <stdio.h> /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */ |
23 #include <stdio.h> /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */ |
24 #include "physfsrwops.h" |
24 #include "physfsrwops.h" |
25 |
25 |
26 static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) |
26 static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) |
27 { |
27 { |
28 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1; |
28 PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
29 int pos = 0; |
29 int pos = 0; |
30 |
30 |
31 if (whence == SEEK_SET) |
31 if (whence == SEEK_SET) |
32 { |
32 { |
33 pos = offset; |
33 pos = offset; |
97 } /* physfsrwops_seek */ |
97 } /* physfsrwops_seek */ |
98 |
98 |
99 |
99 |
100 static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) |
100 static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) |
101 { |
101 { |
102 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1; |
102 PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
103 PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum); |
103 PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum); |
104 if (rc != maxnum) |
104 if (rc != maxnum) |
105 { |
105 { |
106 if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */ |
106 if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */ |
107 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
107 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
111 } /* physfsrwops_read */ |
111 } /* physfsrwops_read */ |
112 |
112 |
113 |
113 |
114 static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) |
114 static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) |
115 { |
115 { |
116 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1; |
116 PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
117 PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num); |
117 PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num); |
118 if (rc != num) |
118 if (rc != num) |
119 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
119 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
120 |
120 |
121 return((int) rc); |
121 return((int) rc); |
122 } /* physfsrwops_write */ |
122 } /* physfsrwops_write */ |
123 |
123 |
124 |
124 |
125 static int physfsrwops_close(SDL_RWops *rw) |
125 static int physfsrwops_close(SDL_RWops *rw) |
126 { |
126 { |
127 PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1; |
127 PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; |
128 if (!PHYSFS_close(handle)) |
128 if (!PHYSFS_close(handle)) |
129 { |
129 { |
130 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
130 SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); |
131 return(-1); |
131 return(-1); |
132 } /* if */ |
132 } /* if */ |