Cygwin: drop macro and code for CYGWIN_VERSION_CHECK_FOR_OLD_O_NONBLOCK

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2022-08-03 15:48:56 +02:00
parent 7de1be0472
commit c2743614bf
5 changed files with 9 additions and 33 deletions

View File

@ -1360,17 +1360,12 @@ int fhandler_base::fcntl (int cmd, intptr_t arg)
break; break;
case F_SETFL: case F_SETFL:
{ {
/* Only O_APPEND, O_ASYNC and O_NONBLOCK/O_NDELAY are allowed. /* Only O_APPEND, O_ASYNC and O_NONBLOCK are allowed.
Each other flag will be ignored. Each other flag will be ignored.
Since O_ASYNC isn't defined in fcntl.h it's currently Since O_ASYNC isn't defined in fcntl.h it's currently
ignored as well. */ ignored as well. */
const int allowed_flags = O_APPEND | O_NONBLOCK_MASK; const int allowed_flags = O_APPEND | O_NONBLOCK;
int new_flags = arg & allowed_flags; int new_flags = arg & allowed_flags;
/* Carefully test for the O_NONBLOCK or deprecated OLD_O_NDELAY flag.
Set only the flag that has been passed in. If both are set, just
record O_NONBLOCK. */
if ((new_flags & OLD_O_NDELAY) && (new_flags & O_NONBLOCK))
new_flags &= ~OLD_O_NDELAY;
set_flags ((get_flags () & ~allowed_flags) | new_flags); set_flags ((get_flags () & ~allowed_flags) | new_flags);
} }
res = 0; res = 0;
@ -1573,15 +1568,15 @@ fhandler_base::fixup_after_exec ()
bool bool
fhandler_base::is_nonblocking () fhandler_base::is_nonblocking ()
{ {
return (openflags & O_NONBLOCK_MASK) != 0; return (openflags & O_NONBLOCK) != 0;
} }
void void
fhandler_base::set_nonblocking (int yes) fhandler_base::set_nonblocking (int yes)
{ {
int current = openflags & O_NONBLOCK_MASK; int current = openflags & O_NONBLOCK;
int new_flags = yes ? (!current ? O_NONBLOCK : current) : 0; int new_flags = yes ? (!current ? O_NONBLOCK : current) : 0;
openflags = (openflags & ~O_NONBLOCK_MASK) | new_flags; openflags = (openflags & ~O_NONBLOCK) | new_flags;
} }
int int

View File

@ -15,15 +15,6 @@ details. */
#include <cygwin/_ucred.h> #include <cygwin/_ucred.h>
#include <sys/un.h> #include <sys/un.h>
/* newlib used to define O_NDELAY differently from O_NONBLOCK. Now it
properly defines both to be the same. Unfortunately, we have to
behave properly the old version, too, to accommodate older executables. */
#define OLD_O_NDELAY (CYGWIN_VERSION_CHECK_FOR_OLD_O_NONBLOCK ? 4 : 0)
/* Care for the old O_NDELAY flag. If one of the flags is set,
both flags are set. */
#define O_NONBLOCK_MASK (O_NONBLOCK | OLD_O_NDELAY)
/* It appears that 64K is the block size used for buffered I/O on NT. /* It appears that 64K is the block size used for buffered I/O on NT.
Using this blocksize in read/write calls in the application results Using this blocksize in read/write calls in the application results
in a much better performance than using smaller values. */ in a much better performance than using smaller values. */

View File

@ -246,17 +246,12 @@ fhandler_socket::fcntl (int cmd, intptr_t arg)
{ {
case F_SETFL: case F_SETFL:
{ {
/* Carefully test for the O_NONBLOCK or deprecated OLD_O_NDELAY flag. int new_flags = arg & O_NONBLOCK;
Set only the flag that has been passed in. If both are set, just current = get_flags () & O_NONBLOCK;
record O_NONBLOCK. */
int new_flags = arg & O_NONBLOCK_MASK;
if ((new_flags & OLD_O_NDELAY) && (new_flags & O_NONBLOCK))
new_flags = O_NONBLOCK;
current = get_flags () & O_NONBLOCK_MASK;
request = new_flags ? 1 : 0; request = new_flags ? 1 : 0;
if (!!current != !!new_flags && (res = ioctl (FIONBIO, &request))) if (!!current != !!new_flags && (res = ioctl (FIONBIO, &request)))
break; break;
set_flags ((get_flags () & ~O_NONBLOCK_MASK) | new_flags); set_flags ((get_flags () & ~O_NONBLOCK) | new_flags);
break; break;
} }
default: default:

View File

@ -2289,10 +2289,8 @@ fhandler_socket_unix::fcntl (int cmd, intptr_t arg)
case F_SETFL: case F_SETFL:
{ {
const bool was_nonblocking = is_nonblocking (); const bool was_nonblocking = is_nonblocking ();
const int allowed_flags = O_APPEND | O_NONBLOCK_MASK; const int allowed_flags = O_APPEND | O_NONBLOCK;
int new_flags = arg & allowed_flags; int new_flags = arg & allowed_flags;
if ((new_flags & OLD_O_NDELAY) && (new_flags & O_NONBLOCK))
new_flags &= ~OLD_O_NDELAY;
set_flags ((get_flags () & ~allowed_flags) | new_flags); set_flags ((get_flags () & ~allowed_flags) | new_flags);
const bool now_nonblocking = is_nonblocking (); const bool now_nonblocking = is_nonblocking ();
if (was_nonblocking != now_nonblocking) if (was_nonblocking != now_nonblocking)

View File

@ -34,9 +34,6 @@ details. */
#define CYGWIN_VERSION_USER_API_VERSION_COMBINED \ #define CYGWIN_VERSION_USER_API_VERSION_COMBINED \
CYGWIN_VERSION_PER_PROCESS_API_VERSION_COMBINED (user_data) CYGWIN_VERSION_PER_PROCESS_API_VERSION_COMBINED (user_data)
#define CYGWIN_VERSION_CHECK_FOR_OLD_O_NONBLOCK \
(CYGWIN_VERSION_USER_API_VERSION_COMBINED <= 28)
#define CYGWIN_VERSION_CHECK_FOR_USING_BIG_TYPES \ #define CYGWIN_VERSION_CHECK_FOR_USING_BIG_TYPES \
(CYGWIN_VERSION_USER_API_VERSION_COMBINED >= 79) (CYGWIN_VERSION_USER_API_VERSION_COMBINED >= 79)