MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / RedirectHandle

Function RedirectHandle

launcher/console/WindowsConsole.cpp:37–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35namespace console {
36
37void RedirectHandle(DWORD handle, FILE* stream, const char* mode)
38{
39 HANDLE stdHandle = GetStdHandle(handle);
40 if (stdHandle != INVALID_HANDLE_VALUE) {
41 int fileDescriptor = _open_osfhandle((intptr_t)stdHandle, _O_TEXT);
42 if (fileDescriptor != -1) {
43 FILE* file = _fdopen(fileDescriptor, mode);
44 if (file != NULL) {
45 int dup2Result = _dup2(_fileno(file), _fileno(stream));
46 if (dup2Result == 0) {
47 setvbuf(stream, NULL, _IONBF, 0);
48 }
49 }
50 }
51 }
52}
53
54// taken from https://stackoverflow.com/a/25927081
55// getting a proper output to console with redirection support on windows is apparently hell

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected