1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/io-nonblock] Revert tab expansion

This commit is contained in:
Nobuyoshi Nakada 2022-07-30 17:24:43 +09:00
parent 1bebf21570
commit f28287d34c
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -42,7 +42,7 @@ rb_io_nonblock_p(VALUE io)
rb_io_t *fptr; rb_io_t *fptr;
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
if (get_fcntl_flags(fptr->fd) & O_NONBLOCK) if (get_fcntl_flags(fptr->fd) & O_NONBLOCK)
return Qtrue; return Qtrue;
return Qfalse; return Qfalse;
} }
#else #else
@ -54,21 +54,21 @@ static void
set_fcntl_flags(int fd, int f) set_fcntl_flags(int fd, int f)
{ {
if (fcntl(fd, F_SETFL, f) == -1) if (fcntl(fd, F_SETFL, f) == -1)
rb_sys_fail(0); rb_sys_fail(0);
} }
static int static int
io_nonblock_set(int fd, int f, int nb) io_nonblock_set(int fd, int f, int nb)
{ {
if (nb) { if (nb) {
if ((f & O_NONBLOCK) != 0) if ((f & O_NONBLOCK) != 0)
return 0; return 0;
f |= O_NONBLOCK; f |= O_NONBLOCK;
} }
else { else {
if ((f & O_NONBLOCK) == 0) if ((f & O_NONBLOCK) == 0)
return 0; return 0;
f &= ~O_NONBLOCK; f &= ~O_NONBLOCK;
} }
set_fcntl_flags(fd, f); set_fcntl_flags(fd, f);
return 1; return 1;
@ -127,9 +127,9 @@ rb_io_nonblock_set(VALUE io, VALUE nb)
rb_io_t *fptr; rb_io_t *fptr;
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
if (RTEST(nb)) if (RTEST(nb))
rb_io_set_nonblock(fptr); rb_io_set_nonblock(fptr);
else else
io_nonblock_set(fptr->fd, get_fcntl_flags(fptr->fd), RTEST(nb)); io_nonblock_set(fptr->fd, get_fcntl_flags(fptr->fd), RTEST(nb));
return io; return io;
} }
@ -160,15 +160,15 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
if (argc > 0) { if (argc > 0) {
VALUE v; VALUE v;
rb_scan_args(argc, argv, "01", &v); rb_scan_args(argc, argv, "01", &v);
nb = RTEST(v); nb = RTEST(v);
} }
f = get_fcntl_flags(fptr->fd); f = get_fcntl_flags(fptr->fd);
restore[0] = fptr->fd; restore[0] = fptr->fd;
restore[1] = f; restore[1] = f;
if (!io_nonblock_set(fptr->fd, f, nb)) if (!io_nonblock_set(fptr->fd, f, nb))
return rb_yield(io); return rb_yield(io);
return rb_ensure(rb_yield, io, io_nonblock_restore, (VALUE)restore); return rb_ensure(rb_yield, io, io_nonblock_restore, (VALUE)restore);
} }
#else #else