From f9b1a2bbc24f846e19b65167de76ef9ec30a87ff Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 20 Feb 2019 06:54:51 +0000 Subject: [PATCH] New Windows utility function: is_console_handle(). Rather like isatty() on Unix, this tells you if a raw Windows HANDLE points at a console or not. Useful to know if your standard output or standard error is going to be shown to a user, or redirected to something that will make automated use of it. --- windows/winmiscs.c | 8 ++++++++ windows/winstuff.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/windows/winmiscs.c b/windows/winmiscs.c index 1fc14d71..d1662330 100644 --- a/windows/winmiscs.c +++ b/windows/winmiscs.c @@ -267,3 +267,11 @@ bool platform_sha1_hw_available(void) } #endif + +bool is_console_handle(HANDLE handle) +{ + DWORD ignored_output; + if (GetConsoleMode(handle, &ignored_output)) + return true; + return false; +} diff --git a/windows/winstuff.h b/windows/winstuff.h index ee6a055a..3334674b 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -569,6 +569,8 @@ GLOBAL bool restricted_acl; void escape_registry_key(const char *in, strbuf *out); void unescape_registry_key(const char *in, strbuf *out); +bool is_console_handle(HANDLE); + /* A few pieces of up-to-date Windows API definition needed for older * compilers. */ #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32