Mercurial > sdl-ios-xcode
annotate src/file/SDL_rwops.c @ 1354:22f39393668a
Fixed build problem with SDL_string.c
Officially deprecated SDL_byteorder.h, SDL_getenv.h and SDL_types.h
Moved endian-related SDL_rwops code into SDL_rwops.c
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 09 Feb 2006 09:38:05 +0000 |
parents | 604d73db6802 |
children | c71e05b4dc2e |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1269
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1269
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1269
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1269
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1269
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1269
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1269
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
36
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* This file provides a general interface for SDL to read and write | |
24 data sources. It can easily be extended to files, memory, etc. | |
25 */ | |
26 | |
27 #include "SDL_error.h" | |
1354
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
28 #include "SDL_endian.h" |
0 | 29 #include "SDL_rwops.h" |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
30 |
1354
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
31 |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
32 #ifdef HAVE_STDIO_H |
0 | 33 |
34 /* Functions to read/write stdio file pointers */ | |
35 | |
36 static int stdio_seek(SDL_RWops *context, int offset, int whence) | |
37 { | |
38 if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) { | |
39 return(ftell(context->hidden.stdio.fp)); | |
40 } else { | |
41 SDL_Error(SDL_EFSEEK); | |
42 return(-1); | |
43 } | |
44 } | |
45 static int stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum) | |
46 { | |
47 size_t nread; | |
48 | |
49 nread = fread(ptr, size, maxnum, context->hidden.stdio.fp); | |
50 if ( nread == 0 && ferror(context->hidden.stdio.fp) ) { | |
51 SDL_Error(SDL_EFREAD); | |
52 } | |
53 return(nread); | |
54 } | |
55 static int stdio_write(SDL_RWops *context, const void *ptr, int size, int num) | |
56 { | |
57 size_t nwrote; | |
58 | |
59 nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp); | |
60 if ( nwrote == 0 && ferror(context->hidden.stdio.fp) ) { | |
61 SDL_Error(SDL_EFWRITE); | |
62 } | |
63 return(nwrote); | |
64 } | |
65 static int stdio_close(SDL_RWops *context) | |
66 { | |
67 if ( context ) { | |
68 if ( context->hidden.stdio.autoclose ) { | |
69 /* WARNING: Check the return value here! */ | |
70 fclose(context->hidden.stdio.fp); | |
71 } | |
1202
0748fbb272e7
Matched SDL_AllowRW and SDL_FreeRW calls in SDL_rwops.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1078
diff
changeset
|
72 SDL_FreeRW(context); |
0 | 73 } |
74 return(0); | |
75 } | |
76 | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
77 #endif /* HAVE_STDIO_H */ |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
78 |
0 | 79 /* Functions to read/write memory pointers */ |
80 | |
81 static int mem_seek(SDL_RWops *context, int offset, int whence) | |
82 { | |
83 Uint8 *newpos; | |
84 | |
85 switch (whence) { | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
86 case RW_SEEK_SET: |
0 | 87 newpos = context->hidden.mem.base+offset; |
88 break; | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
89 case RW_SEEK_CUR: |
0 | 90 newpos = context->hidden.mem.here+offset; |
91 break; | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
92 case RW_SEEK_END: |
0 | 93 newpos = context->hidden.mem.stop+offset; |
94 break; | |
95 default: | |
96 SDL_SetError("Unknown value for 'whence'"); | |
97 return(-1); | |
98 } | |
99 if ( newpos < context->hidden.mem.base ) { | |
100 newpos = context->hidden.mem.base; | |
101 } | |
102 if ( newpos > context->hidden.mem.stop ) { | |
103 newpos = context->hidden.mem.stop; | |
104 } | |
105 context->hidden.mem.here = newpos; | |
106 return(context->hidden.mem.here-context->hidden.mem.base); | |
107 } | |
108 static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum) | |
109 { | |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
110 int total_bytes; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
111 int mem_available; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
112 |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
113 total_bytes = (maxnum * size); |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
114 if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) { |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
115 return 0; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
116 } |
0 | 117 |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
118 mem_available = (context->hidden.mem.stop - context->hidden.mem.here); |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
119 if (total_bytes > mem_available) { |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
120 total_bytes = mem_available; |
0 | 121 } |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
122 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
123 SDL_memcpy(ptr, context->hidden.mem.here, total_bytes); |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
124 context->hidden.mem.here += total_bytes; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
125 |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
126 return (total_bytes / size); |
0 | 127 } |
128 static int mem_write(SDL_RWops *context, const void *ptr, int size, int num) | |
129 { | |
130 if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) { | |
131 num = (context->hidden.mem.stop-context->hidden.mem.here)/size; | |
132 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
133 SDL_memcpy(context->hidden.mem.here, ptr, num*size); |
0 | 134 context->hidden.mem.here += num*size; |
135 return(num); | |
136 } | |
764
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
137 static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num) |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
138 { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
139 SDL_SetError("Can't write to read-only memory"); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
140 return(-1); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
141 } |
0 | 142 static int mem_close(SDL_RWops *context) |
143 { | |
144 if ( context ) { | |
1202
0748fbb272e7
Matched SDL_AllowRW and SDL_FreeRW calls in SDL_rwops.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1078
diff
changeset
|
145 SDL_FreeRW(context); |
0 | 146 } |
147 return(0); | |
148 } | |
149 | |
150 /* Functions to create SDL_RWops structures from various data sources */ | |
151 #ifdef WIN32 | |
152 /* Aggh. You can't (apparently) open a file in an application and | |
153 read from it in a DLL. | |
154 */ | |
155 static int in_sdl = 0; | |
156 #endif | |
157 | |
158 #ifdef macintosh | |
159 /* | |
160 * translate unix-style slash-separated filename to mac-style colon-separated | |
161 * name; return malloced string | |
162 */ | |
163 static char *unix_to_mac(const char *file) | |
164 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
165 int flen = SDL_strlen(file); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
166 char *path = SDL_malloc(flen + 2); |
0 | 167 const char *src = file; |
168 char *dst = path; | |
169 if(*src == '/') { | |
170 /* really depends on filesystem layout, hope for the best */ | |
171 src++; | |
172 } else { | |
173 /* Check if this is a MacOS path to begin with */ | |
174 if(*src != ':') | |
175 *dst++ = ':'; /* relative paths begin with ':' */ | |
176 } | |
177 while(src < file + flen) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
178 const char *end = SDL_strchr(src, '/'); |
0 | 179 int len; |
180 if(!end) | |
181 end = file + flen; /* last component */ | |
182 len = end - src; | |
183 if(len == 0 || (len == 1 && src[0] == '.')) { | |
184 /* remove repeated slashes and . */ | |
185 } else { | |
186 if(len == 2 && src[0] == '.' && src[1] == '.') { | |
187 /* replace .. with the empty string */ | |
188 } else { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
189 SDL_memcpy(dst, src, len); |
0 | 190 dst += len; |
191 } | |
192 if(end < file + flen) | |
193 *dst++ = ':'; | |
194 } | |
195 src = end + 1; | |
196 } | |
197 *dst++ = '\0'; | |
198 return path; | |
199 } | |
200 #endif /* macintosh */ | |
201 | |
202 SDL_RWops *SDL_RWFromFile(const char *file, const char *mode) | |
203 { | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
204 SDL_RWops *rwops = NULL; |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
205 #ifdef HAVE_STDIO_H |
0 | 206 FILE *fp; |
207 | |
208 #ifdef macintosh | |
209 { | |
210 char *mpath = unix_to_mac(file); | |
211 fp = fopen(mpath, mode); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
212 SDL_free(mpath); |
0 | 213 } |
214 #else | |
215 fp = fopen(file, mode); | |
216 #endif | |
217 if ( fp == NULL ) { | |
218 SDL_SetError("Couldn't open %s", file); | |
219 } else { | |
220 #ifdef WIN32 | |
221 in_sdl = 1; | |
222 rwops = SDL_RWFromFP(fp, 1); | |
223 in_sdl = 0; | |
224 #else | |
225 rwops = SDL_RWFromFP(fp, 1); | |
226 #endif | |
227 } | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
228 #endif /* HAVE_STDIO_H */ |
0 | 229 return(rwops); |
230 } | |
231 | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
232 #ifdef HAVE_STDIO_H |
0 | 233 SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose) |
234 { | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
235 SDL_RWops *rwops = NULL; |
0 | 236 |
237 #ifdef WIN32 | |
238 if ( ! in_sdl ) { | |
1269
905d5b482f2a
Some explanation on why SDL_RWFromFP doesn't always work on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1202
diff
changeset
|
239 /* It's when SDL and the app are compiled with different C runtimes */ |
543
522e5202014d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
240 SDL_SetError("You can't pass a FILE pointer to a DLL (?)"); |
0 | 241 /*return(NULL);*/ |
242 } | |
243 #endif | |
244 rwops = SDL_AllocRW(); | |
245 if ( rwops != NULL ) { | |
246 rwops->seek = stdio_seek; | |
247 rwops->read = stdio_read; | |
248 rwops->write = stdio_write; | |
249 rwops->close = stdio_close; | |
250 rwops->hidden.stdio.fp = fp; | |
251 rwops->hidden.stdio.autoclose = autoclose; | |
252 } | |
253 return(rwops); | |
254 } | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
255 #endif /* HAVE_STDIO_H */ |
0 | 256 |
257 SDL_RWops *SDL_RWFromMem(void *mem, int size) | |
258 { | |
259 SDL_RWops *rwops; | |
260 | |
261 rwops = SDL_AllocRW(); | |
262 if ( rwops != NULL ) { | |
263 rwops->seek = mem_seek; | |
264 rwops->read = mem_read; | |
265 rwops->write = mem_write; | |
266 rwops->close = mem_close; | |
267 rwops->hidden.mem.base = (Uint8 *)mem; | |
268 rwops->hidden.mem.here = rwops->hidden.mem.base; | |
269 rwops->hidden.mem.stop = rwops->hidden.mem.base+size; | |
270 } | |
271 return(rwops); | |
272 } | |
273 | |
764
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
274 SDL_RWops *SDL_RWFromConstMem(const void *mem, int size) |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
275 { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
276 SDL_RWops *rwops; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
277 |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
278 rwops = SDL_AllocRW(); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
279 if ( rwops != NULL ) { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
280 rwops->seek = mem_seek; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
281 rwops->read = mem_read; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
282 rwops->write = mem_writeconst; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
283 rwops->close = mem_close; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
284 rwops->hidden.mem.base = (Uint8 *)mem; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
285 rwops->hidden.mem.here = rwops->hidden.mem.base; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
286 rwops->hidden.mem.stop = rwops->hidden.mem.base+size; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
287 } |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
288 return(rwops); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
289 } |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
290 |
0 | 291 SDL_RWops *SDL_AllocRW(void) |
292 { | |
293 SDL_RWops *area; | |
294 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
295 area = (SDL_RWops *)SDL_malloc(sizeof *area); |
0 | 296 if ( area == NULL ) { |
297 SDL_OutOfMemory(); | |
298 } | |
299 return(area); | |
300 } | |
301 | |
302 void SDL_FreeRW(SDL_RWops *area) | |
303 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
304 SDL_free(area); |
0 | 305 } |
1354
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
306 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
307 /* Functions for dynamically reading and writing endian-specific values */ |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
308 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
309 Uint16 SDL_ReadLE16 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
310 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
311 Uint16 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
312 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
313 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
314 return(SDL_SwapLE16(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
315 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
316 Uint16 SDL_ReadBE16 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
317 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
318 Uint16 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
319 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
320 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
321 return(SDL_SwapBE16(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
322 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
323 Uint32 SDL_ReadLE32 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
324 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
325 Uint32 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
326 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
327 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
328 return(SDL_SwapLE32(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
329 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
330 Uint32 SDL_ReadBE32 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
331 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
332 Uint32 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
333 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
334 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
335 return(SDL_SwapBE32(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
336 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
337 Uint64 SDL_ReadLE64 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
338 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
339 Uint64 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
340 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
341 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
342 return(SDL_SwapLE64(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
343 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
344 Uint64 SDL_ReadBE64 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
345 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
346 Uint64 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
347 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
348 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
349 return(SDL_SwapBE64(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
350 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
351 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
352 int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
353 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
354 value = SDL_SwapLE16(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
355 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
356 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
357 int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
358 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
359 value = SDL_SwapBE16(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
360 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
361 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
362 int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
363 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
364 value = SDL_SwapLE32(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
365 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
366 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
367 int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
368 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
369 value = SDL_SwapBE32(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
370 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
371 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
372 int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
373 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
374 value = SDL_SwapLE64(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
375 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
376 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
377 int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
378 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
379 value = SDL_SwapBE64(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
380 return(SDL_RWwrite(dst, &value, (sizeof value), 1)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
381 } |