src/file/SDL_rwops.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 10 Jul 2007 04:31:31 +0000
branchSDL-1.2
changeset 4027 407ecf3ad3b3
parent 4026 255b0469ca83
child 4035 3ccd06fc22e5
permissions -rw-r--r--
Fixed signed/unsigned mismatch ... hmm, limited to 2 GB reads? Fix in SDL 1.3
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     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
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* This file provides a general interface for SDL to read and write
    25    data sources.  It can easily be extended to files, memory, etc.
    26 */
    27 
    28 #include "SDL_endian.h"
    29 #include "SDL_rwops.h"
    30 
    31 
    32 #if defined(__WIN32__) && !defined(__SYMBIAN32__)
    33 
    34 /* Functions to read/write Win32 API file pointers */
    35 /* Will not use it on WinCE because stdio is buffered, it means
    36    faster, and all stdio functions anyway are embedded in coredll.dll - 
    37    the main wince dll*/
    38 
    39 #define WINDOWS_LEAN_AND_MEAN
    40 #include <windows.h>
    41 
    42 #ifndef INVALID_SET_FILE_POINTER
    43 #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
    44 #endif
    45 
    46 #define READAHEAD_BUFFER_SIZE	1024
    47 
    48 static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
    49 {
    50 #ifndef _WIN32_WCE
    51 	UINT	old_error_mode;
    52 #endif
    53 	HANDLE	h;
    54 	DWORD	r_right, w_right;
    55 	DWORD	must_exist, truncate;
    56 	int		a_mode;
    57 
    58 	if (!context)
    59 		return -1;
    60 		
    61 	context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
    62 
    63 	context->hidden.win32io.buffer.data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE);
    64 	if (!context->hidden.win32io.buffer.data) {
    65 		SDL_OutOfMemory();
    66 		return -1;
    67 	}
    68 	context->hidden.win32io.buffer.size = 0;
    69 	context->hidden.win32io.buffer.left = 0;
    70 
    71 	/* "r" = reading, file must exist */
    72 	/* "w" = writing, truncate existing, file may not exist */
    73 	/* "r+"= reading or writing, file must exist            */
    74 	/* "a" = writing, append file may not exist             */
    75 	/* "a+"= append + read, file may not exist              */
    76 	/* "w+" = read, write, truncate. file may not exist    */
    77 	
    78 	must_exist = ( SDL_strchr(mode,'r') != NULL ) ? OPEN_EXISTING : 0;
    79 	truncate   = ( SDL_strchr(mode,'w') != NULL ) ? CREATE_ALWAYS : 0;
    80 	r_right    = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0;
    81 	a_mode     = ( SDL_strchr(mode,'a') != NULL ) ? OPEN_ALWAYS : 0;
    82 	w_right    = ( a_mode || SDL_strchr(mode,'+') || truncate ) ? GENERIC_WRITE : 0;
    83 
    84 	if (!r_right && !w_right) /* inconsistent mode */
    85 		return -1; /* failed (invalid call)*/
    86 
    87 #ifdef _WIN32_WCE
    88 	{
    89 		size_t size = SDL_strlen(filename)+1;
    90 		wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);
    91 
    92 		if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
    93 			SDL_SetError("Unable to convert filename to Unicode");
    94 			SDL_stack_free(filenameW);
    95 			return -1;
    96 		}
    97 		h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
    98 					   NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
    99 		SDL_stack_free(filenameW);
   100 	}
   101 #else
   102 	/* Do not open a dialog box if failure */
   103 	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
   104 
   105 	h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
   106 		           NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
   107 
   108 	/* restore old behaviour */
   109 	SetErrorMode(old_error_mode);
   110 #endif /* _WIN32_WCE */
   111 
   112 	if (h==INVALID_HANDLE_VALUE) {
   113 		SDL_SetError("Couldn't open %s",filename);
   114 		return -2; /* failed (CreateFile) */
   115 	}
   116 	context->hidden.win32io.h = h;
   117 	context->hidden.win32io.append = a_mode;
   118 	
   119 	return 0; /* ok */
   120 }
   121 static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence)
   122 {
   123 	DWORD win32whence;
   124 	int   file_pos;
   125 	
   126 	if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) {
   127 		SDL_SetError("win32_file_seek: invalid context/file not opened");
   128 		return -1;
   129 	}
   130 
   131 	/* FIXME: We may be able to satisfy the seek within buffered data */
   132 	if (whence == RW_SEEK_CUR && context->hidden.win32io.buffer.left) {
   133 		offset -= context->hidden.win32io.buffer.left;
   134     }
   135     context->hidden.win32io.buffer.left = 0;
   136 
   137 	switch (whence) {
   138 		case RW_SEEK_SET:		
   139 			win32whence = FILE_BEGIN; break;
   140 		case RW_SEEK_CUR:
   141 			win32whence = FILE_CURRENT; break;
   142 		case RW_SEEK_END:
   143 			win32whence = FILE_END; break;
   144 		default:
   145 			SDL_SetError("win32_file_seek: Unknown value for 'whence'");			
   146 			return -1;
   147 	}
   148 
   149 	file_pos = SetFilePointer(context->hidden.win32io.h,offset,NULL,win32whence);
   150 
   151 	if ( file_pos != INVALID_SET_FILE_POINTER )
   152 		return file_pos; /* success */
   153 	
   154 	SDL_Error(SDL_EFSEEK);
   155 	return -1; /* error */
   156 }
   157 static int SDLCALL win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   158 {
   159 	int		total_need; 
   160 	int		total_read = 0; 
   161     int     read_ahead;
   162 	DWORD	byte_read;
   163 	
   164 	total_need = size*maxnum;
   165 	
   166 	if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE || total_need<=0 || !size) 	
   167 		return 0;
   168 
   169     if (context->hidden.win32io.buffer.left > 0) {
   170         void *data = (char *)context->hidden.win32io.buffer.data +
   171                              context->hidden.win32io.buffer.size -
   172                              context->hidden.win32io.buffer.left;
   173         read_ahead = SDL_min(total_need, context->hidden.win32io.buffer.left); 
   174         SDL_memcpy(ptr, data, read_ahead);
   175         context->hidden.win32io.buffer.left -= read_ahead;
   176 
   177         if (read_ahead == total_need) {
   178             return maxnum;
   179         }
   180         ptr = (char *)ptr + read_ahead;
   181         total_need -= read_ahead;       
   182 		total_read += read_ahead;
   183     }
   184 
   185     if (total_need < READAHEAD_BUFFER_SIZE) {
   186         if (!ReadFile(context->hidden.win32io.h,context->hidden.win32io.buffer.data,READAHEAD_BUFFER_SIZE,&byte_read,NULL)) {
   187             SDL_Error(SDL_EFREAD);
   188             return 0;
   189         }
   190         read_ahead = SDL_min(total_need, (int)byte_read);
   191         SDL_memcpy(ptr, context->hidden.win32io.buffer.data, read_ahead);
   192         context->hidden.win32io.buffer.size = byte_read;
   193         context->hidden.win32io.buffer.left = byte_read-read_ahead;
   194         total_read += read_ahead;
   195     } else {
   196         if (!ReadFile(context->hidden.win32io.h,ptr,total_need,&byte_read,NULL)) {
   197             SDL_Error(SDL_EFREAD);
   198             return 0;
   199         }
   200         total_read += byte_read;
   201     }
   202 	return (total_read/size);
   203 }
   204 static int SDLCALL win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
   205 {
   206 	
   207 	int		total_bytes; 
   208 	DWORD	byte_written,nwritten;
   209 	
   210 	total_bytes = size*num;
   211 
   212 	if (!context || context->hidden.win32io.h==INVALID_HANDLE_VALUE || total_bytes<=0 || !size) 	
   213 		return 0;
   214 
   215 	if (context->hidden.win32io.buffer.left) {
   216 		SetFilePointer(context->hidden.win32io.h,-context->hidden.win32io.buffer.left,NULL,FILE_CURRENT);
   217 		context->hidden.win32io.buffer.left = 0;
   218 	}
   219 
   220 	/* if in append mode, we must go to the EOF before write */
   221 	if (context->hidden.win32io.append) {
   222 		if ( SetFilePointer(context->hidden.win32io.h,0L,NULL,FILE_END) == INVALID_SET_FILE_POINTER ) {
   223 			SDL_Error(SDL_EFWRITE);
   224 			return 0;
   225 		}
   226 	}
   227 	
   228 	if (!WriteFile(context->hidden.win32io.h,ptr,total_bytes,&byte_written,NULL)) {
   229 		SDL_Error(SDL_EFWRITE);
   230 		return 0;
   231 	}
   232 	
   233 	nwritten = byte_written/size;
   234 	return nwritten;
   235 }
   236 static int SDLCALL win32_file_close(SDL_RWops *context)
   237 {
   238 	
   239 	if ( context ) {								
   240 		if (context->hidden.win32io.h != INVALID_HANDLE_VALUE) {
   241 			CloseHandle(context->hidden.win32io.h);
   242 			context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* to be sure */
   243 		}
   244 		if (context->hidden.win32io.buffer.data) {
   245 			SDL_free(context->hidden.win32io.buffer.data);
   246 			context->hidden.win32io.buffer.data = NULL;
   247 		}
   248 		SDL_FreeRW(context);
   249 	}
   250 	return(0);
   251 }
   252 #endif /* __WIN32__ */
   253 
   254 #ifdef HAVE_STDIO_H
   255 
   256 /* Functions to read/write stdio file pointers */
   257 
   258 static int SDLCALL stdio_seek(SDL_RWops *context, int offset, int whence)
   259 {
   260 	if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) {
   261 		return(ftell(context->hidden.stdio.fp));
   262 	} else {
   263 		SDL_Error(SDL_EFSEEK);
   264 		return(-1);
   265 	}
   266 }
   267 static int SDLCALL stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   268 {
   269 	size_t nread;
   270 
   271 	nread = fread(ptr, size, maxnum, context->hidden.stdio.fp); 
   272 	if ( nread == 0 && ferror(context->hidden.stdio.fp) ) {
   273 		SDL_Error(SDL_EFREAD);
   274 	}
   275 	return(nread);
   276 }
   277 static int SDLCALL stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
   278 {
   279 	size_t nwrote;
   280 
   281 	nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
   282 	if ( nwrote == 0 && ferror(context->hidden.stdio.fp) ) {
   283 		SDL_Error(SDL_EFWRITE);
   284 	}
   285 	return(nwrote);
   286 }
   287 static int SDLCALL stdio_close(SDL_RWops *context)
   288 {
   289 	if ( context ) {
   290 		if ( context->hidden.stdio.autoclose ) {
   291 			/* WARNING:  Check the return value here! */
   292 			fclose(context->hidden.stdio.fp);
   293 		}
   294 		SDL_FreeRW(context);
   295 	}
   296 	return(0);
   297 }
   298 #endif /* !HAVE_STDIO_H */
   299 
   300 /* Functions to read/write memory pointers */
   301 
   302 static int SDLCALL mem_seek(SDL_RWops *context, int offset, int whence)
   303 {
   304 	Uint8 *newpos;
   305 
   306 	switch (whence) {
   307 		case RW_SEEK_SET:
   308 			newpos = context->hidden.mem.base+offset;
   309 			break;
   310 		case RW_SEEK_CUR:
   311 			newpos = context->hidden.mem.here+offset;
   312 			break;
   313 		case RW_SEEK_END:
   314 			newpos = context->hidden.mem.stop+offset;
   315 			break;
   316 		default:
   317 			SDL_SetError("Unknown value for 'whence'");
   318 			return(-1);
   319 	}
   320 	if ( newpos < context->hidden.mem.base ) {
   321 		newpos = context->hidden.mem.base;
   322 	}
   323 	if ( newpos > context->hidden.mem.stop ) {
   324 		newpos = context->hidden.mem.stop;
   325 	}
   326 	context->hidden.mem.here = newpos;
   327 	return(context->hidden.mem.here-context->hidden.mem.base);
   328 }
   329 static int SDLCALL mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   330 {
   331 	size_t total_bytes;
   332 	size_t mem_available;
   333 
   334 	total_bytes = (maxnum * size);
   335 	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != (size_t) size) ) {
   336 		return 0;
   337 	}
   338 
   339 	mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
   340 	if (total_bytes > mem_available) {
   341 		total_bytes = mem_available;
   342 	}
   343 
   344 	SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
   345 	context->hidden.mem.here += total_bytes;
   346 
   347 	return (total_bytes / size);
   348 }
   349 static int SDLCALL mem_write(SDL_RWops *context, const void *ptr, int size, int num)
   350 {
   351 	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
   352 		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
   353 	}
   354 	SDL_memcpy(context->hidden.mem.here, ptr, num*size);
   355 	context->hidden.mem.here += num*size;
   356 	return(num);
   357 }
   358 static int SDLCALL mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
   359 {
   360 	SDL_SetError("Can't write to read-only memory");
   361 	return(-1);
   362 }
   363 static int SDLCALL mem_close(SDL_RWops *context)
   364 {
   365 	if ( context ) {
   366 		SDL_FreeRW(context);
   367 	}
   368 	return(0);
   369 }
   370 
   371 
   372 /* Functions to create SDL_RWops structures from various data sources */
   373 
   374 #ifdef __MACOS__
   375 /*
   376  * translate unix-style slash-separated filename to mac-style colon-separated
   377  * name; return malloced string
   378  */
   379 static char *unix_to_mac(const char *file)
   380 {
   381 	int flen = SDL_strlen(file);
   382 	char *path = SDL_malloc(flen + 2);
   383 	const char *src = file;
   384 	char *dst = path;
   385 	if(*src == '/') {
   386 		/* really depends on filesystem layout, hope for the best */
   387 		src++;
   388 	} else {
   389 		/* Check if this is a MacOS path to begin with */
   390 		if(*src != ':')
   391 			*dst++ = ':';   /* relative paths begin with ':' */
   392 	}
   393 	while(src < file + flen) {
   394 		const char *end = SDL_strchr(src, '/');
   395 		int len;
   396 		if(!end)
   397 			end = file + flen; /* last component */
   398 		len = end - src;
   399 		if(len == 0 || (len == 1 && src[0] == '.')) {
   400 			/* remove repeated slashes and . */
   401 		} else {
   402 			if(len == 2 && src[0] == '.' && src[1] == '.') {
   403 				/* replace .. with the empty string */
   404 			} else {
   405 				SDL_memcpy(dst, src, len);
   406 				dst += len;
   407 			}
   408 			if(end < file + flen)
   409 				*dst++ = ':';
   410 		}
   411 		src = end + 1;
   412 	}
   413 	*dst++ = '\0';
   414 	return path;
   415 }
   416 #endif /* __MACOS__ */
   417 
   418 SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
   419 {
   420 	SDL_RWops *rwops = NULL;
   421 #ifdef HAVE_STDIO_H
   422 	FILE *fp = NULL;
   423 #endif
   424 	if ( !file || !*file || !mode || !*mode ) {
   425 		SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
   426 		return NULL;
   427 	}
   428 
   429 #if defined(__WIN32__) && !defined(__SYMBIAN32__)
   430 	rwops = SDL_AllocRW();
   431 	if (!rwops)
   432 		return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
   433 	rwops->hidden.win32io.h = INVALID_HANDLE_VALUE;
   434 	if (win32_file_open(rwops,file,mode)) {
   435 		SDL_FreeRW(rwops);
   436 		return NULL;
   437 	}	
   438 	rwops->seek  = win32_file_seek;
   439 	rwops->read  = win32_file_read;
   440 	rwops->write = win32_file_write;
   441 	rwops->close = win32_file_close;
   442 
   443 #elif HAVE_STDIO_H
   444 
   445 #ifdef __MACOS__
   446 	{
   447 		char *mpath = unix_to_mac(file);
   448 		fp = fopen(mpath, mode);
   449 		SDL_free(mpath);
   450 	}
   451 #else
   452 	fp = fopen(file, mode);
   453 #endif
   454 	if ( fp == NULL ) {
   455 		SDL_SetError("Couldn't open %s", file);
   456 	} else {
   457 		rwops = SDL_RWFromFP(fp, 1);
   458 	}
   459 #else
   460 	SDL_SetError("SDL not compiled with stdio support");
   461 #endif /* !HAVE_STDIO_H */
   462 
   463 	return(rwops);
   464 }
   465 
   466 #ifdef HAVE_STDIO_H
   467 SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
   468 {
   469 	SDL_RWops *rwops = NULL;
   470 
   471 	rwops = SDL_AllocRW();
   472 	if ( rwops != NULL ) {
   473 		rwops->seek = stdio_seek;
   474 		rwops->read = stdio_read;
   475 		rwops->write = stdio_write;
   476 		rwops->close = stdio_close;
   477 		rwops->hidden.stdio.fp = fp;
   478 		rwops->hidden.stdio.autoclose = autoclose;
   479 	}
   480 	return(rwops);
   481 }
   482 #endif /* HAVE_STDIO_H */
   483 
   484 SDL_RWops *SDL_RWFromMem(void *mem, int size)
   485 {
   486 	SDL_RWops *rwops;
   487 
   488 	rwops = SDL_AllocRW();
   489 	if ( rwops != NULL ) {
   490 		rwops->seek = mem_seek;
   491 		rwops->read = mem_read;
   492 		rwops->write = mem_write;
   493 		rwops->close = mem_close;
   494 		rwops->hidden.mem.base = (Uint8 *)mem;
   495 		rwops->hidden.mem.here = rwops->hidden.mem.base;
   496 		rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
   497 	}
   498 	return(rwops);
   499 }
   500 
   501 SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
   502 {
   503 	SDL_RWops *rwops;
   504 
   505 	rwops = SDL_AllocRW();
   506 	if ( rwops != NULL ) {
   507 		rwops->seek = mem_seek;
   508 		rwops->read = mem_read;
   509 		rwops->write = mem_writeconst;
   510 		rwops->close = mem_close;
   511 		rwops->hidden.mem.base = (Uint8 *)mem;
   512 		rwops->hidden.mem.here = rwops->hidden.mem.base;
   513 		rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
   514 	}
   515 	return(rwops);
   516 }
   517 
   518 SDL_RWops *SDL_AllocRW(void)
   519 {
   520 	SDL_RWops *area;
   521 
   522 	area = (SDL_RWops *)SDL_malloc(sizeof *area);
   523 	if ( area == NULL ) {
   524 		SDL_OutOfMemory();
   525 	}
   526 	return(area);
   527 }
   528 
   529 void SDL_FreeRW(SDL_RWops *area)
   530 {
   531 	SDL_free(area);
   532 }
   533 
   534 /* Functions for dynamically reading and writing endian-specific values */
   535 
   536 Uint16 SDL_ReadLE16 (SDL_RWops *src)
   537 {
   538 	Uint16 value;
   539 
   540 	SDL_RWread(src, &value, (sizeof value), 1);
   541 	return(SDL_SwapLE16(value));
   542 }
   543 Uint16 SDL_ReadBE16 (SDL_RWops *src)
   544 {
   545 	Uint16 value;
   546 
   547 	SDL_RWread(src, &value, (sizeof value), 1);
   548 	return(SDL_SwapBE16(value));
   549 }
   550 Uint32 SDL_ReadLE32 (SDL_RWops *src)
   551 {
   552 	Uint32 value;
   553 
   554 	SDL_RWread(src, &value, (sizeof value), 1);
   555 	return(SDL_SwapLE32(value));
   556 }
   557 Uint32 SDL_ReadBE32 (SDL_RWops *src)
   558 {
   559 	Uint32 value;
   560 
   561 	SDL_RWread(src, &value, (sizeof value), 1);
   562 	return(SDL_SwapBE32(value));
   563 }
   564 Uint64 SDL_ReadLE64 (SDL_RWops *src)
   565 {
   566 	Uint64 value;
   567 
   568 	SDL_RWread(src, &value, (sizeof value), 1);
   569 	return(SDL_SwapLE64(value));
   570 }
   571 Uint64 SDL_ReadBE64 (SDL_RWops *src)
   572 {
   573 	Uint64 value;
   574 
   575 	SDL_RWread(src, &value, (sizeof value), 1);
   576 	return(SDL_SwapBE64(value));
   577 }
   578 
   579 int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value)
   580 {
   581 	value = SDL_SwapLE16(value);
   582 	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   583 }
   584 int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value)
   585 {
   586 	value = SDL_SwapBE16(value);
   587 	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   588 }
   589 int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value)
   590 {
   591 	value = SDL_SwapLE32(value);
   592 	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   593 }
   594 int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value)
   595 {
   596 	value = SDL_SwapBE32(value);
   597 	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   598 }
   599 int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value)
   600 {
   601 	value = SDL_SwapLE64(value);
   602 	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   603 }
   604 int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value)
   605 {
   606 	value = SDL_SwapBE64(value);
   607 	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   608 }