Mercurial > sdl-ios-xcode
comparison src/main/win32/SDL_main.c @ 545:8406511f850e
Save the full pathname for stdout.txt and stderr.txt
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 17 Nov 2002 19:30:44 +0000 |
parents | 6b34c9dcf74c |
children | 0ac20b67c2c7 |
comparison
equal
deleted
inserted
replaced
544:2d7373ffd131 | 545:8406511f850e |
---|---|
9 #include <ctype.h> | 9 #include <ctype.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 | 11 |
12 #include <windows.h> | 12 #include <windows.h> |
13 #include <malloc.h> /* For _alloca() */ | 13 #include <malloc.h> /* For _alloca() */ |
14 #include <io.h> /* For _getcwd() */ | |
14 | 15 |
15 /* Include the SDL main definition header */ | 16 /* Include the SDL main definition header */ |
16 #include "SDL.h" | 17 #include "SDL.h" |
17 #include "SDL_main.h" | 18 #include "SDL_main.h" |
18 #ifdef main | 19 #ifdef main |
27 #endif | 28 #endif |
28 | 29 |
29 /* The standard output files */ | 30 /* The standard output files */ |
30 #define STDOUT_FILE TEXT("stdout.txt") | 31 #define STDOUT_FILE TEXT("stdout.txt") |
31 #define STDERR_FILE TEXT("stderr.txt") | 32 #define STDERR_FILE TEXT("stderr.txt") |
33 | |
34 #ifndef NO_STDIO_REDIRECT | |
35 static char stdoutPath[MAX_PATH]; | |
36 static char stderrPath[MAX_PATH]; | |
37 #endif | |
32 | 38 |
33 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 | 39 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 |
34 /* seems to be undefined in Win CE although in online help */ | 40 /* seems to be undefined in Win CE although in online help */ |
35 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) | 41 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) |
36 | 42 |
136 fclose(stdout); | 142 fclose(stdout); |
137 fclose(stderr); | 143 fclose(stderr); |
138 | 144 |
139 #ifndef NO_STDIO_REDIRECT | 145 #ifndef NO_STDIO_REDIRECT |
140 /* See if the files have any output in them */ | 146 /* See if the files have any output in them */ |
141 file = fopen(STDOUT_FILE, "rb"); | 147 file = fopen(stdoutPath, "rb"); |
142 if ( file ) { | 148 if ( file ) { |
143 empty = (fgetc(file) == EOF) ? 1 : 0; | 149 empty = (fgetc(file) == EOF) ? 1 : 0; |
144 fclose(file); | 150 fclose(file); |
145 if ( empty ) { | 151 if ( empty ) { |
146 remove(STDOUT_FILE); | 152 remove(stdoutPath); |
147 } | 153 } |
148 } | 154 } |
149 file = fopen(STDERR_FILE, "rb"); | 155 file = fopen(stderrPath, "rb"); |
150 if ( file ) { | 156 if ( file ) { |
151 empty = (fgetc(file) == EOF) ? 1 : 0; | 157 empty = (fgetc(file) == EOF) ? 1 : 0; |
152 fclose(file); | 158 fclose(file); |
153 if ( empty ) { | 159 if ( empty ) { |
154 remove(STDERR_FILE); | 160 remove(stderrPath); |
155 } | 161 } |
156 } | 162 } |
157 #endif | 163 #endif |
158 } | 164 } |
159 | 165 |
259 if ( handle != NULL ) { | 265 if ( handle != NULL ) { |
260 FreeLibrary(handle); | 266 FreeLibrary(handle); |
261 } | 267 } |
262 | 268 |
263 #ifndef NO_STDIO_REDIRECT | 269 #ifndef NO_STDIO_REDIRECT |
270 _getcwd( stdoutPath, sizeof( stdoutPath ) ); | |
271 strcat( stdoutPath, "/" STDOUT_FILE ); | |
272 | |
264 /* Redirect standard input and standard output */ | 273 /* Redirect standard input and standard output */ |
265 newfp = freopen(STDOUT_FILE, "w", stdout); | 274 newfp = freopen(stdoutPath, "w", stdout); |
266 if ( newfp == NULL ) { /* This happens on NT */ | 275 if ( newfp == NULL ) { /* This happens on NT */ |
267 #if !defined(stdout) | 276 #if !defined(stdout) |
268 stdout = fopen(STDOUT_FILE, "w"); | 277 stdout = fopen(stdoutPath, "w"); |
269 #else | 278 #else |
270 newfp = fopen(STDOUT_FILE, "w"); | 279 newfp = fopen(stdoutPath, "w"); |
271 if ( newfp ) { | 280 if ( newfp ) { |
272 *stdout = *newfp; | 281 *stdout = *newfp; |
273 } | 282 } |
274 #endif | 283 #endif |
275 } | 284 } |
276 newfp = freopen(STDERR_FILE, "w", stderr); | 285 |
286 _getcwd( stderrPath, sizeof( stderrPath ) ); | |
287 strcat( stderrPath, "/" STDERR_FILE ); | |
288 | |
289 newfp = freopen(stderrPath, "w", stderr); | |
277 if ( newfp == NULL ) { /* This happens on NT */ | 290 if ( newfp == NULL ) { /* This happens on NT */ |
278 #if !defined(stderr) | 291 #if !defined(stderr) |
279 stderr = fopen(STDERR_FILE, "w"); | 292 stderr = fopen(stderrPath, "w"); |
280 #else | 293 #else |
281 newfp = fopen(STDERR_FILE, "w"); | 294 newfp = fopen(stderrPath, "w"); |
282 if ( newfp ) { | 295 if ( newfp ) { |
283 *stderr = *newfp; | 296 *stderr = *newfp; |
284 } | 297 } |
285 #endif | 298 #endif |
286 } | 299 } |