Applied Corona688's patch for output redirection on Windows CE
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 Jan 2003 04:15:21 +0000
changeset 5751f6438c8df2c
parent 574 64fe373be3dc
child 576 cd41dca47fff
Applied Corona688's patch for output redirection on Windows CE
src/main/win32/SDL_main.c
     1.1 --- a/src/main/win32/SDL_main.c	Mon Jan 20 16:01:20 2003 +0000
     1.2 +++ b/src/main/win32/SDL_main.c	Tue Jan 21 04:15:21 2003 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  /*
     1.5      SDL_main.c, placed in the public domain by Sam Lantinga  4/13/98
     1.6  
     1.7 -    The WinMain function -- calls your program's main() function 
     1.8 +    The WinMain function -- calls your program's main() function
     1.9  */
    1.10  
    1.11  #include <stdio.h>
    1.12 @@ -10,30 +10,44 @@
    1.13  #include <stdlib.h>
    1.14  
    1.15  #include <windows.h>
    1.16 -#include <malloc.h>		/* For _alloca() */
    1.17 -#include <io.h>			/* For _getcwd() */
    1.18 +#include <malloc.h>			/* For _alloca() */
    1.19 +
    1.20 +#ifdef _WIN32_WCE
    1.21 +# define DIR_SEPERATOR TEXT("\\")
    1.22 +# define _getcwd(str,len)	wcscpy(str,DIR_SEPERATOR);
    1.23 +# define setbuf(x)
    1.24 +# define setvbuf(x)
    1.25 +# define fopen		_wfopen
    1.26 +# define freopen	_wfreopen
    1.27 +# define remove(x)	DeleteFile(x)
    1.28 +# define strcat		wcscat
    1.29 +#else
    1.30 +# define DIR_SEPERATOR TEXT("/")
    1.31 +# include <direct.h>
    1.32 +#endif
    1.33  
    1.34  /* Include the SDL main definition header */
    1.35  #include "SDL.h"
    1.36  #include "SDL_main.h"
    1.37 +
    1.38  #ifdef main
    1.39 -#ifndef _WIN32_WCE_EMULATION
    1.40 -#undef main
    1.41 -#endif
    1.42 -#endif
    1.43 -
    1.44 -/* Do we really not want stdio redirection with Windows CE? */
    1.45 -#ifdef _WIN32_WCE
    1.46 -#define NO_STDIO_REDIRECT
    1.47 -#endif
    1.48 +# ifndef _WIN32_WCE_EMULATION
    1.49 +#  undef main
    1.50 +# endif /* _WIN32_WCE_EMULATION */
    1.51 +#endif /* main */
    1.52  
    1.53  /* The standard output files */
    1.54  #define STDOUT_FILE	TEXT("stdout.txt")
    1.55  #define STDERR_FILE	TEXT("stderr.txt")
    1.56  
    1.57  #ifndef NO_STDIO_REDIRECT
    1.58 -static char stdoutPath[MAX_PATH];
    1.59 -static char stderrPath[MAX_PATH];
    1.60 +# ifdef _WIN32_WCE
    1.61 +  static wchar_t stdoutPath[MAX_PATH];
    1.62 +  static wchar_t stderrPath[MAX_PATH];
    1.63 +# else
    1.64 +  static char stdoutPath[MAX_PATH];
    1.65 +  static char stderrPath[MAX_PATH];
    1.66 +# endif
    1.67  #endif
    1.68  
    1.69  #if defined(_WIN32_WCE) && _WIN32_WCE < 300
    1.70 @@ -145,7 +159,7 @@
    1.71  #ifndef NO_STDIO_REDIRECT
    1.72  	/* See if the files have any output in them */
    1.73  	if ( stdoutPath[0] ) {
    1.74 -		file = fopen(stdoutPath, "rb");
    1.75 +		file = fopen(stdoutPath, TEXT("rb"));
    1.76  		if ( file ) {
    1.77  			empty = (fgetc(file) == EOF) ? 1 : 0;
    1.78  			fclose(file);
    1.79 @@ -155,7 +169,7 @@
    1.80  		}
    1.81  	}
    1.82  	if ( stderrPath[0] ) {
    1.83 -		file = fopen(stderrPath, "rb");
    1.84 +		file = fopen(stderrPath, TEXT("rb"));
    1.85  		if ( file ) {
    1.86  			empty = (fgetc(file) == EOF) ? 1 : 0;
    1.87  			fclose(file);
    1.88 @@ -272,35 +286,41 @@
    1.89  
    1.90  #ifndef NO_STDIO_REDIRECT
    1.91  	_getcwd( stdoutPath, sizeof( stdoutPath ) );
    1.92 -	strcat( stdoutPath, "/" STDOUT_FILE );
    1.93 +	strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE );
    1.94      
    1.95  	/* Redirect standard input and standard output */
    1.96 -	newfp = freopen(stdoutPath, "w", stdout);
    1.97 +	newfp = freopen(stdoutPath, TEXT("w"), stdout);
    1.98 +
    1.99 +#ifndef _WIN32_WCE
   1.100  	if ( newfp == NULL ) {	/* This happens on NT */
   1.101  #if !defined(stdout)
   1.102 -		stdout = fopen(stdoutPath, "w");
   1.103 +		stdout = fopen(stdoutPath, TEXT("w"));
   1.104  #else
   1.105 -		newfp = fopen(stdoutPath, "w");
   1.106 +		newfp = fopen(stdoutPath, TEXT("w"));
   1.107  		if ( newfp ) {
   1.108  			*stdout = *newfp;
   1.109  		}
   1.110  #endif
   1.111  	}
   1.112 +#endif /* _WIN32_WCE */
   1.113  
   1.114  	_getcwd( stderrPath, sizeof( stderrPath ) );
   1.115 -	strcat( stderrPath, "/" STDERR_FILE );
   1.116 +	strcat( stderrPath, DIR_SEPERATOR STDERR_FILE );
   1.117  
   1.118 -	newfp = freopen(stderrPath, "w", stderr);
   1.119 +	newfp = freopen(stderrPath, TEXT("w"), stderr);
   1.120 +#ifndef _WIN32_WCE
   1.121  	if ( newfp == NULL ) {	/* This happens on NT */
   1.122  #if !defined(stderr)
   1.123 -		stderr = fopen(stderrPath, "w");
   1.124 +		stderr = fopen(stderrPath, TEXT("w"));
   1.125  #else
   1.126 -		newfp = fopen(stderrPath, "w");
   1.127 +		newfp = fopen(stderrPath, TEXT("w"));
   1.128  		if ( newfp ) {
   1.129  			*stderr = *newfp;
   1.130  		}
   1.131  #endif
   1.132  	}
   1.133 +#endif /* _WIN32_WCE */
   1.134 +
   1.135  	setvbuf(stdout, NULL, _IOLBF, BUFSIZ);	/* Line buffered */
   1.136  	setbuf(stderr, NULL);			/* No buffering */
   1.137  #endif /* !NO_STDIO_REDIRECT */