tool_cb_wrt: fix bad-function-cast warning

Commit f5bc578f4c reintroduced the
warning fixed in commit 2f5f31bb57.
Extend fhnd's scope and reuse that variable instead of calling
_get_osfhandle a second time to fix the warning again.

Closes https://github.com/curl/curl/pull/3718
This commit is contained in:
Marcel Raad 2019-04-01 18:40:01 +02:00
parent e102ba7a19
commit d110d96b98
No known key found for this signature in database
GPG Key ID: FE4D8BC5EE1701DD
1 changed files with 3 additions and 5 deletions

View File

@ -81,6 +81,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
bool is_tty = config->global->isatty; bool is_tty = config->global->isatty;
#ifdef WIN32 #ifdef WIN32
CONSOLE_SCREEN_BUFFER_INFO console_info; CONSOLE_SCREEN_BUFFER_INFO console_info;
intptr_t fhnd;
#endif #endif
/* /*
@ -159,13 +160,12 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
} }
#ifdef _WIN32 #ifdef _WIN32
fhnd = _get_osfhandle(fileno(outs->stream));
if(isatty(fileno(outs->stream)) && if(isatty(fileno(outs->stream)) &&
GetConsoleScreenBufferInfo( GetConsoleScreenBufferInfo((HANDLE)fhnd, &console_info)) {
(HANDLE)_get_osfhandle(fileno(outs->stream)), &console_info)) {
DWORD in_len = (DWORD)(sz * nmemb); DWORD in_len = (DWORD)(sz * nmemb);
wchar_t* wc_buf; wchar_t* wc_buf;
DWORD wc_len; DWORD wc_len;
intptr_t fhnd;
/* calculate buffer size for wide characters */ /* calculate buffer size for wide characters */
wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, NULL, 0); wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, NULL, 0);
@ -180,8 +180,6 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
return failure; return failure;
} }
fhnd = _get_osfhandle(fileno(outs->stream));
if(!WriteConsoleW( if(!WriteConsoleW(
(HANDLE) fhnd, (HANDLE) fhnd,
wc_buf, wc_buf,