Save the full pathname for stdout.txt and stderr.txt
authorSam Lantinga <slouken@libsdl.org>
Sun, 17 Nov 2002 19:30:44 +0000
changeset 5458406511f850e
parent 544 2d7373ffd131
child 546 0009aadb3d01
Save the full pathname for stdout.txt and stderr.txt
src/main/win32/SDL_main.c
     1.1 --- a/src/main/win32/SDL_main.c	Sun Nov 17 19:03:05 2002 +0000
     1.2 +++ b/src/main/win32/SDL_main.c	Sun Nov 17 19:30:44 2002 +0000
     1.3 @@ -11,6 +11,7 @@
     1.4  
     1.5  #include <windows.h>
     1.6  #include <malloc.h>		/* For _alloca() */
     1.7 +#include <io.h>			/* For _getcwd() */
     1.8  
     1.9  /* Include the SDL main definition header */
    1.10  #include "SDL.h"
    1.11 @@ -30,6 +31,11 @@
    1.12  #define STDOUT_FILE	TEXT("stdout.txt")
    1.13  #define STDERR_FILE	TEXT("stderr.txt")
    1.14  
    1.15 +#ifndef NO_STDIO_REDIRECT
    1.16 +static char stdoutPath[MAX_PATH];
    1.17 +static char stderrPath[MAX_PATH];
    1.18 +#endif
    1.19 +
    1.20  #if defined(_WIN32_WCE) && _WIN32_WCE < 300
    1.21  /* seems to be undefined in Win CE although in online help */
    1.22  #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
    1.23 @@ -138,20 +144,20 @@
    1.24  
    1.25  #ifndef NO_STDIO_REDIRECT
    1.26  	/* See if the files have any output in them */
    1.27 -	file = fopen(STDOUT_FILE, "rb");
    1.28 +	file = fopen(stdoutPath, "rb");
    1.29  	if ( file ) {
    1.30  		empty = (fgetc(file) == EOF) ? 1 : 0;
    1.31  		fclose(file);
    1.32  		if ( empty ) {
    1.33 -			remove(STDOUT_FILE);
    1.34 +			remove(stdoutPath);
    1.35  		}
    1.36  	}
    1.37 -	file = fopen(STDERR_FILE, "rb");
    1.38 +	file = fopen(stderrPath, "rb");
    1.39  	if ( file ) {
    1.40  		empty = (fgetc(file) == EOF) ? 1 : 0;
    1.41  		fclose(file);
    1.42  		if ( empty ) {
    1.43 -			remove(STDERR_FILE);
    1.44 +			remove(stderrPath);
    1.45  		}
    1.46  	}
    1.47  #endif
    1.48 @@ -261,24 +267,31 @@
    1.49  	}
    1.50  
    1.51  #ifndef NO_STDIO_REDIRECT
    1.52 +	_getcwd( stdoutPath, sizeof( stdoutPath ) );
    1.53 +	strcat( stdoutPath, "/" STDOUT_FILE );
    1.54 +    
    1.55  	/* Redirect standard input and standard output */
    1.56 -	newfp = freopen(STDOUT_FILE, "w", stdout);
    1.57 +	newfp = freopen(stdoutPath, "w", stdout);
    1.58  	if ( newfp == NULL ) {	/* This happens on NT */
    1.59  #if !defined(stdout)
    1.60 -		stdout = fopen(STDOUT_FILE, "w");
    1.61 +		stdout = fopen(stdoutPath, "w");
    1.62  #else
    1.63 -		newfp = fopen(STDOUT_FILE, "w");
    1.64 +		newfp = fopen(stdoutPath, "w");
    1.65  		if ( newfp ) {
    1.66  			*stdout = *newfp;
    1.67  		}
    1.68  #endif
    1.69  	}
    1.70 -	newfp = freopen(STDERR_FILE, "w", stderr);
    1.71 +
    1.72 +	_getcwd( stderrPath, sizeof( stderrPath ) );
    1.73 +	strcat( stderrPath, "/" STDERR_FILE );
    1.74 +
    1.75 +	newfp = freopen(stderrPath, "w", stderr);
    1.76  	if ( newfp == NULL ) {	/* This happens on NT */
    1.77  #if !defined(stderr)
    1.78 -		stderr = fopen(STDERR_FILE, "w");
    1.79 +		stderr = fopen(stderrPath, "w");
    1.80  #else
    1.81 -		newfp = fopen(STDERR_FILE, "w");
    1.82 +		newfp = fopen(stderrPath, "w");
    1.83  		if ( newfp ) {
    1.84  			*stderr = *newfp;
    1.85  		}