On Mon, 15 Dec 2025 17:06:34 +0000
"Johannes Schindelin wrote:
> From: Johannes Schindelin <[email protected]>
> 
> This function contains special handling of these file extensions,
> treating them as console applications always, even if the first 1024
> bytes do not contain a PE header with the console bits set.
> 
> However, Batch and Command files are never expected to have such a
> header, therefore opening them and reading their first bytes is a waste
> of time.
> 
> Let's honor the best practice to deal with easy conditions that allow
> early returns first.
> 
> Fixed: bb4285206207 (Cygwin: pty: Implement new pseudo console suppot., 
> 2020-08-19)
  ~~~~~
Fixes:

> Signed-off-by: Johannes Schindelin <[email protected]>
> ---
>  winsup/cygwin/fhandler/termios.cc | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler/termios.cc 
> b/winsup/cygwin/fhandler/termios.cc
> index 808d0d435..5505bf416 100644
> --- a/winsup/cygwin/fhandler/termios.cc
> +++ b/winsup/cygwin/fhandler/termios.cc
> @@ -704,6 +704,9 @@ fhandler_termios::fstat (struct stat *buf)
>  static bool
>  is_console_app (const WCHAR *filename)
>  {
> +  wchar_t *e = wcsrchr (filename, L'.');
> +  if (e && (wcscasecmp (e, L".bat") == 0 || wcscasecmp (e, L".cmd") == 0))
> +    return true;
>    HANDLE h;
>    h = CreateFileW (filename, GENERIC_READ, FILE_SHARE_READ,
>                  NULL, OPEN_EXISTING, 0, NULL);
> @@ -720,9 +723,6 @@ is_console_app (const WCHAR *filename)
>    IMAGE_NT_HEADERS32 *p = (IMAGE_NT_HEADERS32 *) memmem (buf, n, "PE\0\0", 
> 4);
>    if (p && (char *) &p->OptionalHeader.DllCharacteristics <= buf + n)
>      return p->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI;
> -  wchar_t *e = wcsrchr (filename, L'.');
> -  if (e && (wcscasecmp (e, L".bat") == 0 || wcscasecmp (e, L".cmd") == 0))
> -    return true;
>    return false;
>  }
>  
> -- 
> cygwingitgadget
> 

Ohter than above, LGTM. Thanks.

-- 
Takashi Yano <[email protected]>

Reply via email to