delorie.com/archives/browse.cgi | search |
DMARC-Filter: | OpenDMARC Filter v1.4.2 delorie.com 504JEXMI1912538 |
Authentication-Results: | delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com |
Authentication-Results: | delorie.com; spf=pass smtp.mailfrom=cygwin.com |
DKIM-Filter: | OpenDKIM Filter v2.11.0 delorie.com 504JEXMI1912538 |
Authentication-Results: | delorie.com; |
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=qVjFig9V | |
X-Recipient: | archive-cygwin AT delorie DOT com |
DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org EBD3D3858D35 |
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
s=default; t=1736018072; | |
bh=p/x9vudf+36OhUUCN+5OHT494UxMl1P1I/QPDi2XYo4=; | |
h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: | |
List-Help:List-Subscribe:From:Reply-To:From; | |
b=qVjFig9VcfvgN+8cbfWzJBcHcrFBe+m6l5ittHQ5HuzN6ONrI0GrtjpThes6RSpra | |
VsvP7lzJqvU79WziScKlSuSOdSvmWuSz4ibvvhzoxovau/BxulBd7/15zI0i1W8++X | |
oOMhaYPIX6tjyeUcxXbxfQwMJwr57LTULKPtWBOM= | |
X-Original-To: | cygwin AT cygwin DOT com |
Delivered-To: | cygwin AT cygwin DOT com |
DMARC-Filter: | OpenDMARC Filter v1.4.2 sourceware.org 983983858D20 |
ARC-Filter: | OpenARC Filter v1.0.0 sourceware.org 983983858D20 |
ARC-Seal: | i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736018046; cv=none; |
b=Udcrz1UaisNedc/3UiyaZ726Ex1CS9cuFUWtQi1B+hUo2BJ53jnz5k3A+N07szLfokwCagtleaIKRjeygxrUco3Sw36IRu5hz16dPZPelx+zZiszmB7ZS8r56S0CeKKzrBMm4Hf9E9oQ3XFaGI1jDr3WutXHi5cZIITrCZSwZlE= | |
ARC-Message-Signature: | i=1; a=rsa-sha256; d=sourceware.org; s=key; |
t=1736018046; c=relaxed/simple; | |
bh=iFk4RKmHPZ/EfU45ufFn3WAhWq80Lo+v8L+Z7x/b9DM=; | |
h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; | |
b=SRJfvOdRiZ/Zb677F227cn/H0WTJmbcJtNgPY1sSQI7z13+f+2HAyTiDbdrYfjAUpJaerGkcK2QwvV0nnrv8FceiLtIEUzLkKBZoZEWNKdpqOfePzSY03Qn3hxnGEEpcTvtCym+HK+TBQY+lqX2GEPK5m8OF/0nBgu+vGtS3Uvk= | |
ARC-Authentication-Results: | i=1; server2.sourceware.org |
DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 983983858D20 |
Date: | Sat, 04 Jan 2025 19:13:57 +0000 |
To: | "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com> |
Subject: | Alt Key Parsing on Cygwin |
Message-ID: | <lv7zEWDxF6f8zQHcatNWzbBav2LpG6oqkMAWCtv6WSMqx1ffXkeBMdA2ypp3gx5RJnkqppCjICXj7HM1_ab7w7d_ckLjXutejqcygM2Aazg=@proton.me> |
Feedback-ID: | 51238035:user:proton |
X-Pm-Message-ID: | 695c934db054d33155c52e34e93fd87ec93a90a0 |
MIME-Version: | 1.0 |
X-BeenThere: | cygwin AT cygwin DOT com |
X-Mailman-Version: | 2.1.30 |
List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
From: | William Hu via Cygwin <cygwin AT cygwin DOT com> |
Reply-To: | William Hu <purplearmadillo77 AT proton DOT me> |
Sender: | "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com> |
Hi all, I've noticed that the Alt key parsing of the following program has different behavior across the different compiler chains/shells on Windows. Consider the following program that reads 4 characters from standard input. ``` #include <cstdio> int main() { char x[4] {}; fgets(reinterpret_cast<char*>(&x), 4, stdin); for (int i {0}; i < 4; ++i) { printf("%x ", x[i]); } return 0; } ``` Perform these steps: 1. compile (g++ test.cc under cygwin, cl test.cc under MSVC) 2. execute 3. hit "Alt" and "1" at the same time and then hit enter Here is a table of the output of this program when compiled with different toolchains and executed in various terminals. +-------------------------------+----------------+--------------+------------+ | COMPILER | Cygwin Mintty | MSYS2 Mintty | CMD | +-------------------------------+----------------+--------------+------------+ | Cygwin g++ | 1b 31 a 0 | 1b 31 0 0* | 1b 31 0 0* | | Cygwin x86_64-w64-mingw32-g++ | 31 a 0 0 | 31 a 0 0 | 31 a 0 0 | | MSYS2 UCRT g++ | 31 a 0 0 | 31 a 0 0 | 31 a 0 0 | | Visual Studio 2022 | 31 a 0 0 | 31 a 0 0 | 31 a 0 0 | +-------------------------------+----------------+--------------+------------+ ----------------------------------------------------------------------------- * cygwin1.dll was copied into the current directory in order to run the program within these terminals. I didn't get a chance to hit enter - the application just quits. I thought different C libraries might be the problem, so I tried a pure-winapi version: ``` #include <cstdio> #include <windows.h> int main() { // On Cygwin, apparently these are distinct - stdin points to a pipe rather than a console buffer HANDLE hstdin {GetStdHandle(STD_INPUT_HANDLE)}; HANDLE hconin {CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)}; printf("STDIN Handle: %p\n", hstdin); printf("CONIN Handle: %p\n", hconin); DWORD stdtype {GetFileType(hstdin)}; DWORD contype {GetFileType(hconin)}; printf("STDIN Filetype: %x\n", stdtype); printf("CONIN Filetype: %x\n", contype); char x[4] {}; DWORD nread {0}; // You might ask: Why not read from hconin? The test program will hang ReadFile(hstdin, &x, 4, &nread, NULL); for (int i {0}; i < 4; ++i) { printf("%x ", x[i]); } printf("\n"); return 0; } ``` New matrix: +-------------------------------+----------------+--------------+------------+ | COMPILER | Cygwin Mintty | MSYS2 Mintty | CMD | +-------------------------------+----------------+--------------+------------+ | Cygwin g++ | 1b 31 a 0 | 1b 31 0 0* | 1b 31 0 0* | | Cygwin x86_64-w64-mingw32-g++ | 31 d a 0 | 31 d a 0 | 31 d a 0 | | MSYS2 UCRT g++ | 31 d a 0 | 31 d a 0 | 31 d a 0 | | Visual Studio 2022 | 31 d a 0 | 31 d a 0 | 31 d a 0 | +-------------------------------+----------------+--------------+------------+ What does Cygwin do differently that allows it to capture Alt key presses? The above tables suggest the presence of cygwin1.dll in the program is relevant. I'm guessing that the backend magic (e.g. pipes for standard input, invisible consoles) that Cygwin performs plays some role, but thought people on this list would be much more familiar with the inner workings and would be able to provide a fuller explanation. Thanks, William -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |