- Improve console detection.
Prior to this change WriteConsole could be called to write to a handle
that may not be a console, which would cause an error. This issue is
limited to character devices that are not also consoles such as the null
device NUL.
Bug: https://github.com/curl/curl/issues/3175#issuecomment-
439068724
Reported-by: Gisle Vanem
struct OperationConfig *config = outs->config;
size_t bytes = sz * nmemb;
bool is_tty = config->global->isatty;
+#ifdef WIN32
+ CONSOLE_SCREEN_BUFFER_INFO console_info;
+#endif
/*
* Once that libcurl has called back tool_write_cb() the returned value
}
#ifdef _WIN32
- if(isatty(fileno(outs->stream))) {
+ if(isatty(fileno(outs->stream)) &&
+ GetConsoleScreenBufferInfo(
+ (HANDLE)_get_osfhandle(fileno(outs->stream)), &console_info)) {
DWORD in_len = (DWORD)(sz * nmemb);
wchar_t* wc_buf;
DWORD wc_len;