Commit 83cb8c4a authored by Sam Lantinga's avatar Sam Lantinga

Save the full pathname for stdout.txt and stderr.txt

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40546
parent 9f15e5f2
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <windows.h> #include <windows.h>
#include <malloc.h> /* For _alloca() */ #include <malloc.h> /* For _alloca() */
#include <io.h> /* For _getcwd() */
/* Include the SDL main definition header */ /* Include the SDL main definition header */
#include "SDL.h" #include "SDL.h"
...@@ -30,6 +31,11 @@ ...@@ -30,6 +31,11 @@
#define STDOUT_FILE TEXT("stdout.txt") #define STDOUT_FILE TEXT("stdout.txt")
#define STDERR_FILE TEXT("stderr.txt") #define STDERR_FILE TEXT("stderr.txt")
#ifndef NO_STDIO_REDIRECT
static char stdoutPath[MAX_PATH];
static char stderrPath[MAX_PATH];
#endif
#if defined(_WIN32_WCE) && _WIN32_WCE < 300 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
/* seems to be undefined in Win CE although in online help */ /* seems to be undefined in Win CE although in online help */
#define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
...@@ -138,20 +144,20 @@ static void __cdecl cleanup_output(void) ...@@ -138,20 +144,20 @@ static void __cdecl cleanup_output(void)
#ifndef NO_STDIO_REDIRECT #ifndef NO_STDIO_REDIRECT
/* See if the files have any output in them */ /* See if the files have any output in them */
file = fopen(STDOUT_FILE, "rb"); file = fopen(stdoutPath, "rb");
if ( file ) { if ( file ) {
empty = (fgetc(file) == EOF) ? 1 : 0; empty = (fgetc(file) == EOF) ? 1 : 0;
fclose(file); fclose(file);
if ( empty ) { if ( empty ) {
remove(STDOUT_FILE); remove(stdoutPath);
} }
} }
file = fopen(STDERR_FILE, "rb"); file = fopen(stderrPath, "rb");
if ( file ) { if ( file ) {
empty = (fgetc(file) == EOF) ? 1 : 0; empty = (fgetc(file) == EOF) ? 1 : 0;
fclose(file); fclose(file);
if ( empty ) { if ( empty ) {
remove(STDERR_FILE); remove(stderrPath);
} }
} }
#endif #endif
...@@ -261,24 +267,31 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) ...@@ -261,24 +267,31 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
} }
#ifndef NO_STDIO_REDIRECT #ifndef NO_STDIO_REDIRECT
_getcwd( stdoutPath, sizeof( stdoutPath ) );
strcat( stdoutPath, "/" STDOUT_FILE );
/* Redirect standard input and standard output */ /* Redirect standard input and standard output */
newfp = freopen(STDOUT_FILE, "w", stdout); newfp = freopen(stdoutPath, "w", stdout);
if ( newfp == NULL ) { /* This happens on NT */ if ( newfp == NULL ) { /* This happens on NT */
#if !defined(stdout) #if !defined(stdout)
stdout = fopen(STDOUT_FILE, "w"); stdout = fopen(stdoutPath, "w");
#else #else
newfp = fopen(STDOUT_FILE, "w"); newfp = fopen(stdoutPath, "w");
if ( newfp ) { if ( newfp ) {
*stdout = *newfp; *stdout = *newfp;
} }
#endif #endif
} }
newfp = freopen(STDERR_FILE, "w", stderr);
_getcwd( stderrPath, sizeof( stderrPath ) );
strcat( stderrPath, "/" STDERR_FILE );
newfp = freopen(stderrPath, "w", stderr);
if ( newfp == NULL ) { /* This happens on NT */ if ( newfp == NULL ) { /* This happens on NT */
#if !defined(stderr) #if !defined(stderr)
stderr = fopen(STDERR_FILE, "w"); stderr = fopen(stderrPath, "w");
#else #else
newfp = fopen(STDERR_FILE, "w"); newfp = fopen(stderrPath, "w");
if ( newfp ) { if ( newfp ) {
*stderr = *newfp; *stderr = *newfp;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment