From 6af67f541d104e1cce381b14da53e5b1f7fe58fc Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 3 Sep 2018 22:03:13 +0300 Subject: core/windows.c: write logs to the user path Writing logs to the path where the executable is located, might not be possible if the current user doesn't have permissions to write there. Obtain the user path and write the log files to the user path instead - e.g.: c:\users\myuser\appdata\roaming\subsurface\subsurface_*.log Signed-off-by: Lubomir I. Ivanov --- core/windows.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'core/windows.c') diff --git a/core/windows.c b/core/windows.c index f1c95fff1..77b7f5755 100644 --- a/core/windows.c +++ b/core/windows.c @@ -424,8 +424,14 @@ void subsurface_console_init(void) console_desc.err = freopen("CON", "w", stderr); } else { verbose = 1; /* set the verbose level to '1' */ - console_desc.out = freopen("subsurface_out.log", "w", stdout); - console_desc.err = freopen("subsurface_err.log", "w", stderr); + wchar_t *wpath_out = system_default_path_append(L"subsurface_out.log"); + wchar_t *wpath_err = system_default_path_append(L"subsurface_err.log"); + if (wpath_out && wpath_err) { + console_desc.out = _wfreopen(wpath_out, L"w", stdout); + console_desc.err = _wfreopen(wpath_err, L"w", stderr); + } + free((void *)wpath_out); + free((void *)wpath_err); } puts(""); /* add an empty line */ -- cgit v1.2.3-70-g09d2