[PATCH] Cygwin: select: Set errno when peek() returns -1

Takashi Yano takashi.yano@nifty.ne.jp
Fri Apr 17 19:45:22 GMT 2026


Currently, poll() sometimes returns -1 with errno == 0 if the fd is
not opened. This is due to lack of setting errno when peek() fails.
This patch ensure to set errno to thread_errno if peek() returns
NULL.

Addresses: https://cygwin.com/pipermail/cygwin/2026-April/259602.html
Fixes: 8382778cdb57 ("Cygwin: console: fix select() behaviour")
Reported-by: Nahor <nahor.j+cygwin@gmail.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by:
---
 winsup/cygwin/select.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 8a94ac076..523c46ee6 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -561,7 +561,10 @@ select_stuff::poll (fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
     {
       int ret = s->peek ? s->peek (s, true) : 1;
       if (ret < 0)
-	return -1;
+	{
+	  set_errno (s->thread_errno);
+	  return -1;
+	}
       n += (ret > 0) ?  set_bits (s, readfds, writefds, exceptfds) : 0;
     }
   return n;
-- 
2.51.0



More information about the Cygwin-patches mailing list