I tested the following HANDLE hConRW = CreateFileA("CONIN$" , GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hConRW == INVALID_HANDLE_VALUE) hConRW = handle; ret = bare_console_fetch_input(hConRW, fd, timeout); if (hConRW!=handle) CloseHandle(hConRW);
It works a charm, although feels inefficient for the times handle was already r/w - (it feels slightly odd that the 'handle' we are working on is unrelated to the handle passed in (I was worried about stdin redirection, but that seems to work fine even after the change).
Was this what you meant or have I gone off on a tangent?
more or less. I was thinking to add a helper functions for the writeconsoleinput calls in bare_console_fetch_input. and this helper function would : - try to call writeconsoleinput with the current console input handle - if it fails with status_access_denied, then create the right handle as you did - from your code, please use CreateFileW instead of CreateFileA
A+