Redirect stdout to NUL if the log file can't be opened

This commit is contained in:
Cameron Gutman
2022-04-16 21:28:28 -05:00
parent 771e34f199
commit 8f011440b4
2 changed files with 6 additions and 2 deletions

View File

@@ -842,7 +842,11 @@ void ResetLogFile(bool standaloneExe)
MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING);
// Redirect stdout to this new file
freopen(currentLogFilePath, "w", stdout);
if (freopen(currentLogFilePath, "w", stdout) == NULL) {
// If we couldn't create a log file, just redirect stdout to NUL.
// We have to open _something_ or printf() will crash.
freopen("NUL", "w", stdout);
}
}
// Print a log header