| 35 | namespace console { |
| 36 | |
| 37 | void 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 |
no outgoing calls
no test coverage detected