[PATCH 0/2] Return appropriate handle by _get_osfhandle() and GetStdHandle().
Takashi Yano
takashi.yano@nifty.ne.jp
Sun Mar 21 23:07:38 GMT 2021
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);
}
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Cygwin-patches
mailing list