src/file/SDL_rwops.c
changeset 1465 8dfa9a6d69a5
parent 1456 84de7511f79f
child 1659 14717b52abc0
     1.1 --- a/src/file/SDL_rwops.c	Sat Mar 04 05:13:03 2006 +0000
     1.2 +++ b/src/file/SDL_rwops.c	Sat Mar 04 08:24:35 2006 +0000
     1.3 @@ -29,16 +29,25 @@
     1.4  #include "SDL_rwops.h"
     1.5  
     1.6  
     1.7 -#ifdef __WIN32__
     1.8 +#if defined(__WIN32__)
     1.9  
    1.10  /* Functions to read/write Win32 API file pointers */
    1.11 +/* Will not use it on WinCE because stdio is buffered, it means
    1.12 +   faster, and all stdio functions anyway are embedded in coredll.dll - 
    1.13 +   the main wince dll*/
    1.14  
    1.15  #define WINDOWS_LEAN_AND_MEAN
    1.16  #include <windows.h>
    1.17  
    1.18 -static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode) {
    1.19 -	
    1.20 +#ifndef INVALID_SET_FILE_POINTER
    1.21 +#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
    1.22 +#endif
    1.23 +
    1.24 +static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
    1.25 +{
    1.26 +#ifndef _WIN32_WCE
    1.27  	UINT	old_error_mode;
    1.28 +#endif
    1.29  	HANDLE	h;
    1.30  	DWORD	r_right, w_right;
    1.31  	DWORD	must_exist, truncate;
    1.32 @@ -64,15 +73,31 @@
    1.33  
    1.34  	if (!r_right && !w_right) /* inconsistent mode */
    1.35  		return -1; /* failed (invalid call)*/
    1.36 -	
    1.37 +
    1.38 +#ifdef _WIN32_WCE
    1.39 +	{
    1.40 +		size_t size = SDL_strlen(filename)+1;
    1.41 +		wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);
    1.42 +
    1.43 +		if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
    1.44 +			SDL_SetError("Unable to convert filename to Unicode");
    1.45 +			SDL_stack_free(filenameW);
    1.46 +			return -1;
    1.47 +		}
    1.48 +		h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
    1.49 +					   NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
    1.50 +		SDL_stack_free(filenameW);
    1.51 +	}
    1.52 +#else
    1.53  	/* Do not open a dialog box if failure */
    1.54 -	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);	
    1.55 -	
    1.56 +	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
    1.57 +
    1.58  	h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
    1.59  		           NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
    1.60 -	
    1.61 +
    1.62  	/* restore old behaviour */
    1.63  	SetErrorMode(old_error_mode);
    1.64 +#endif /* _WIN32_WCE */
    1.65  
    1.66  	if (h==INVALID_HANDLE_VALUE) {
    1.67  		SDL_SetError("Couldn't open %s",filename);
    1.68 @@ -83,7 +108,8 @@
    1.69  	
    1.70  	return 0; /* ok */
    1.71  }
    1.72 -static int win32_file_seek(SDL_RWops *context, int offset, int whence) {
    1.73 +static int win32_file_seek(SDL_RWops *context, int offset, int whence)
    1.74 +{
    1.75  	DWORD win32whence;
    1.76  	int   file_pos;
    1.77  	
    1.78 @@ -112,7 +138,8 @@
    1.79  	SDL_Error(SDL_EFSEEK);
    1.80  	return -1; /* error */
    1.81  }
    1.82 -static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum) {
    1.83 +static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
    1.84 +{
    1.85  	
    1.86  	int		total_bytes; 
    1.87  	DWORD	byte_read,nread;
    1.88 @@ -129,7 +156,8 @@
    1.89  	nread = byte_read/size;
    1.90  	return nread;
    1.91  }
    1.92 -static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num) {
    1.93 +static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
    1.94 +{
    1.95  	
    1.96  	int		total_bytes; 
    1.97  	DWORD	byte_written,nwritten;
    1.98 @@ -155,7 +183,8 @@
    1.99  	nwritten = byte_written/size;
   1.100  	return nwritten;
   1.101  }
   1.102 -static int win32_file_close(SDL_RWops *context) {
   1.103 +static int win32_file_close(SDL_RWops *context)
   1.104 +{
   1.105  	
   1.106  	if ( context ) {								
   1.107  		if (context->hidden.win32io.h != INVALID_HANDLE_VALUE) {
   1.108 @@ -249,7 +278,7 @@
   1.109  	size_t mem_available;
   1.110  
   1.111  	total_bytes = (maxnum * size);
   1.112 -	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) {
   1.113 +	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != (size_t) size) ) {
   1.114  		return 0;
   1.115  	}
   1.116  
   1.117 @@ -335,13 +364,15 @@
   1.118  SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
   1.119  {
   1.120  	SDL_RWops *rwops = NULL;
   1.121 -
   1.122 +#ifdef HAVE_STDIO_H
   1.123 +	FILE *fp = NULL;
   1.124 +#endif
   1.125  	if ( !file || !*file || !mode || !*mode ) {
   1.126  		SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
   1.127  		return NULL;
   1.128  	}
   1.129  
   1.130 -#ifdef __WIN32__
   1.131 +#if defined(__WIN32__)
   1.132  	rwops = SDL_AllocRW();
   1.133  	if (!rwops)
   1.134  		return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
   1.135 @@ -356,7 +387,6 @@
   1.136  	rwops->close = win32_file_close;
   1.137  
   1.138  #elif HAVE_STDIO_H
   1.139 -	FILE *fp;
   1.140  
   1.141  #ifdef __MACOS__
   1.142  	{