Skip to content

Commit

Permalink
Redirect stdout to NUL if the log file can't be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Apr 17, 2022
1 parent c4291ff commit 48c0136
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion GSv6Fwd/GSv6Fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,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
Expand Down

0 comments on commit 48c0136

Please sign in to comment.