On 01/03/2012 09:36 AM, Eli Zaretskii wrote:
From: Bruno Haible<br...@clisp.org>
Cc: bastien ROUCARIES<roucaries.bast...@gmail.com>, Eli Zaretskii<e...@gnu.org>, Eric 
Blake<ebl...@redhat.com>, bonz...@gnu.org, bug-g...@gnu.org
Date: Tue, 03 Jan 2012 03:56:56 +0100

I'm adding this new module. Feel free to use it in 'grep'.

Thanks

#define IsConsoleHandle(h) (((long) (h)&  3) == 3)

Where does this magic come from, and can we be sure it will always
hold?  If there's some documentation about this, I would suggest to
mention it here.

http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00065.html

It's documented in Wine's source code and in http://www.winehq.org/docs/winedev-guide/x3500:

Console handles, on the other hand, are not multiple of four, but have the two lower bit set (being a multiple of four means having the two lower bits reset). When KERNEL32 sees a handle with the two lower bits set, it then knows it's a console handle and takes appropriate decisions. For example, in the various kernel32!WaitFor*() functions, it transforms any console handle (input and output - strangely enough handles to console's screen buffers are waitable) into a dedicated wait event for the targetted console. There's an (undocumented) KERNEL32 function GetConsoleInputWaitHandle() which returns the handle to this event in case you need it. Another interesting handling of those console's handles is in ReadFile() (resp. WriteFile()), which behavior, for console's handles, is transferred to ReadConsole() (resp. WriteConsole()). Note that's always the ANSI version of ReadConsole() / WriteConsole() which is called, hence using the default console's code page. There are some other spots affected, but you can look in dlls/kernel to find them all. All of this is implemented in Wine.

Paolo

Reply via email to