From 059982949e7f33bf1dfbeb04f0d02ae5161d84bd Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 19 Feb 2021 18:12:37 +0100 Subject: [PATCH] Cygwin: default to O_BINARY in fhandler_base::reset_to_open_binmode() This only affects the very seldom bordercase of apps calling setmode(fd, 0) on fhandlers not calling fhandler_base::set_open_status(). All fhandlers not calling set_open_status() are binary mode only, but the way reset_to_open_binmode worked, calling setmode(fd, 0) would have "reset" their open flags to O_TEXT accidentally. Signed-off-by: Corinna Vinschen --- winsup/cygwin/fhandler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 8c2cc8c1d..a080c481e 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -275,7 +275,8 @@ class fhandler_base void reset_to_open_binmode () { set_flags ((get_flags () & ~(O_TEXT | O_BINARY)) - | ((open_status.wbinary || open_status.rbinary) + | (((open_status.wbinset ? open_status.wbinary : 1) + || (open_status.rbinset ? open_status.rbinary : 1)) ? O_BINARY : O_TEXT)); }