comparison src/file/SDL_rwops.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents 450721ad5436
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
118 mem_available = (context->hidden.mem.stop - context->hidden.mem.here); 118 mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
119 if (total_bytes > mem_available) { 119 if (total_bytes > mem_available) {
120 total_bytes = mem_available; 120 total_bytes = mem_available;
121 } 121 }
122 122
123 memcpy(ptr, context->hidden.mem.here, total_bytes); 123 SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
124 context->hidden.mem.here += total_bytes; 124 context->hidden.mem.here += total_bytes;
125 125
126 return (total_bytes / size); 126 return (total_bytes / size);
127 } 127 }
128 static int mem_write(SDL_RWops *context, const void *ptr, int size, int num) 128 static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
129 { 129 {
130 if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) { 130 if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
131 num = (context->hidden.mem.stop-context->hidden.mem.here)/size; 131 num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
132 } 132 }
133 memcpy(context->hidden.mem.here, ptr, num*size); 133 SDL_memcpy(context->hidden.mem.here, ptr, num*size);
134 context->hidden.mem.here += num*size; 134 context->hidden.mem.here += num*size;
135 return(num); 135 return(num);
136 } 136 }
137 static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num) 137 static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
138 { 138 {
160 * translate unix-style slash-separated filename to mac-style colon-separated 160 * translate unix-style slash-separated filename to mac-style colon-separated
161 * name; return malloced string 161 * name; return malloced string
162 */ 162 */
163 static char *unix_to_mac(const char *file) 163 static char *unix_to_mac(const char *file)
164 { 164 {
165 int flen = strlen(file); 165 int flen = SDL_strlen(file);
166 char *path = malloc(flen + 2); 166 char *path = SDL_malloc(flen + 2);
167 const char *src = file; 167 const char *src = file;
168 char *dst = path; 168 char *dst = path;
169 if(*src == '/') { 169 if(*src == '/') {
170 /* really depends on filesystem layout, hope for the best */ 170 /* really depends on filesystem layout, hope for the best */
171 src++; 171 src++;
173 /* Check if this is a MacOS path to begin with */ 173 /* Check if this is a MacOS path to begin with */
174 if(*src != ':') 174 if(*src != ':')
175 *dst++ = ':'; /* relative paths begin with ':' */ 175 *dst++ = ':'; /* relative paths begin with ':' */
176 } 176 }
177 while(src < file + flen) { 177 while(src < file + flen) {
178 const char *end = strchr(src, '/'); 178 const char *end = SDL_strchr(src, '/');
179 int len; 179 int len;
180 if(!end) 180 if(!end)
181 end = file + flen; /* last component */ 181 end = file + flen; /* last component */
182 len = end - src; 182 len = end - src;
183 if(len == 0 || (len == 1 && src[0] == '.')) { 183 if(len == 0 || (len == 1 && src[0] == '.')) {
184 /* remove repeated slashes and . */ 184 /* remove repeated slashes and . */
185 } else { 185 } else {
186 if(len == 2 && src[0] == '.' && src[1] == '.') { 186 if(len == 2 && src[0] == '.' && src[1] == '.') {
187 /* replace .. with the empty string */ 187 /* replace .. with the empty string */
188 } else { 188 } else {
189 memcpy(dst, src, len); 189 SDL_memcpy(dst, src, len);
190 dst += len; 190 dst += len;
191 } 191 }
192 if(end < file + flen) 192 if(end < file + flen)
193 *dst++ = ':'; 193 *dst++ = ':';
194 } 194 }
207 207
208 #ifdef macintosh 208 #ifdef macintosh
209 { 209 {
210 char *mpath = unix_to_mac(file); 210 char *mpath = unix_to_mac(file);
211 fp = fopen(mpath, mode); 211 fp = fopen(mpath, mode);
212 free(mpath); 212 SDL_free(mpath);
213 } 213 }
214 #else 214 #else
215 fp = fopen(file, mode); 215 fp = fopen(file, mode);
216 #endif 216 #endif
217 if ( fp == NULL ) { 217 if ( fp == NULL ) {
290 290
291 SDL_RWops *SDL_AllocRW(void) 291 SDL_RWops *SDL_AllocRW(void)
292 { 292 {
293 SDL_RWops *area; 293 SDL_RWops *area;
294 294
295 area = (SDL_RWops *)malloc(sizeof *area); 295 area = (SDL_RWops *)SDL_malloc(sizeof *area);
296 if ( area == NULL ) { 296 if ( area == NULL ) {
297 SDL_OutOfMemory(); 297 SDL_OutOfMemory();
298 } 298 }
299 return(area); 299 return(area);
300 } 300 }
301 301
302 void SDL_FreeRW(SDL_RWops *area) 302 void SDL_FreeRW(SDL_RWops *area)
303 { 303 {
304 free(area); 304 SDL_free(area);
305 } 305 }