[PATCH 0/2] Return appropriate handle by _get_osfhandle() and GetStdHandle().

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Mar 22 11:43:36 GMT 2021


[CC Marco]

On Mar 22 08:07, Takashi Yano via Cygwin-patches wrote:
> On Sun, 21 Mar 2021 17:44:27 +0900
> Takashi Yano wrote:
> > On Sun, 21 Mar 2021 13:01:24 +0900
> > Takashi Yano wrote:
> > > Takashi Yano (2):
> > >   Cygwin: syscalls.cc: Make _get_osfhandle() return appropriate handle.
> > >   Cygwin: pty: Add hook for GetStdHandle() to return appropriate handle.
> > > 
> > >  winsup/cygwin/fhandler_tty.cc | 19 +++++++++++++++++++
> > >  winsup/cygwin/syscalls.cc     | 13 ++++++++++++-
> > >  2 files changed, 31 insertions(+), 1 deletion(-)
> > 
> > I submitted these patches, however, I still wonder if we really
> > need these patches. I cannot imagine the situation where handle
> > itself is needed rather than file descriptor.
> > 
> > However, following cygwin apps/dlls call _get_osfhandle():
> > ccmake.exe
> > cmake.exe
> > cpack.exe
> > ctest.exe
> > ddrescue.exe
> > 
> > And also, following cygwin apps/dlls call GetStdHandle():
> > ccmake.exe
> > cmake.exe
> > cpack.exe
> > ctest.exe
> > run.exe
> > cygusb0.dll
> > tk86.dll
> > 
> > in my installation.
> > 
> > Therefore, some of these apps/dlls may need these patches...
> 
> I looked into cmake source and found the patch exactly for
> this issue. Therefore, it seems better to fix this. 
> 
> /* Get the Windows handle for a FILE stream.  */
> static HANDLE kwsysTerminalGetStreamHandle(FILE* stream)
> {
>   /* Get the C-library file descriptor from the stream.  */
>   int fd = fileno(stream);
> 
> #  if defined(__CYGWIN__)
>   /* Cygwin seems to have an extra pipe level.  If the file descriptor
>      corresponds to stdout or stderr then obtain the matching windows
>      handle directly.  */
>   if (fd == fileno(stdout)) {
>     return GetStdHandle(STD_OUTPUT_HANDLE);
>   } else if (fd == fileno(stderr)) {
>     return GetStdHandle(STD_ERROR_HANDLE);
>   }
> #  endif
> 
>   /* Get the underlying Windows handle for the descriptor.  */
>   return (HANDLE)_get_osfhandle(fd);
> }

Why on earth is cmake using Windows functions on Cygwin at all???
It's not as if it actually requires Windows functionality on our
platform.

Marco, any input?  Any chance to drop this Windows stuff from the Cygwin
code path in cmake?


Thanks,
Corinna


More information about the Cygwin-patches mailing list