MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / RedirectHandle

Function RedirectHandle

launcher/WindowsConsole.cpp:28–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include <iostream>
27
28void RedirectHandle(DWORD handle, FILE* stream, const char* mode)
29{
30 HANDLE stdHandle = GetStdHandle(handle);
31 if (stdHandle != INVALID_HANDLE_VALUE) {
32 int fileDescriptor = _open_osfhandle((intptr_t)stdHandle, _O_TEXT);
33 if (fileDescriptor != -1) {
34 FILE* file = _fdopen(fileDescriptor, mode);
35 if (file != NULL) {
36 int dup2Result = _dup2(_fileno(file), _fileno(stream));
37 if (dup2Result == 0) {
38 setvbuf(stream, NULL, _IONBF, 0);
39 }
40 }
41 }
42 }
43}
44
45// taken from https://stackoverflow.com/a/25927081
46// 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