From b60b9f0ebd88b9c1e20641ca20e7482396b6a3c7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 29 Jan 2006 08:39:35 +0000 Subject: [PATCH] Use the executable directory, not the current directory, for stdio output files --- src/main/win32/SDL_win32_main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/win32/SDL_win32_main.c b/src/main/win32/SDL_win32_main.c index 64866a793..5249377b8 100644 --- a/src/main/win32/SDL_win32_main.c +++ b/src/main/win32/SDL_win32_main.c @@ -266,6 +266,12 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) char **argv; int argc; char *cmdline; + DWORD pathlen; +#ifdef _WIN32_WCE + wchar_t path[MAX_PATH]; +#else + char path[MAX_PATH]; +#endif #ifdef _WIN32_WCE wchar_t *bufp; int nLen; @@ -286,7 +292,13 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) } #ifndef NO_STDIO_REDIRECT - _getcwd( stdoutPath, sizeof( stdoutPath ) ); + pathlen = GetModuleFileName(NULL, path, SDL_TABLESIZE(path)); + while ( pathlen > 0 && path[pathlen] != '\\' ) { + --pathlen; + } + path[pathlen] = '\0'; + + strcpy( stdoutPath, path ); strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE ); /* Redirect standard input and standard output */ @@ -305,7 +317,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) } #endif /* _WIN32_WCE */ - _getcwd( stderrPath, sizeof( stderrPath ) ); + strcpy( stderrPath, path ); strcat( stderrPath, DIR_SEPERATOR STDERR_FILE ); newfp = freopen(stderrPath, TEXT("w"), stderr);