IO#sysread Check for readable
MODIFY
src/io.c
src/io.c
@@ -637,6 +637,9 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
}
fptr = (struct mrb_io *)io_get_open_fptr(mrb, io);
+ if (!fptr->readable) {
+ mrb_raise(mrb, E_IO_ERROR, "not opened for reading");
+ }
ret = read(fptr->fd, RSTRING_PTR(buf), maxlen);
switch (ret) {
case 0: /* EOF */

MODIFY
test/io.rb
test/io.rb
@@ -238,6 +238,11 @@ assert('IO.sysopen, IO#sysread') do
assert_raise(IOError) { io.sysread(1) }
assert_raise(ArgumentError) { io.sysread(-1) }
io.closed?
+
+ fd = IO.sysopen $mrbtest_io_wfname, "w"
+ io = IO.new fd, "w"
+ assert_raise(IOError) { io.sysread(1) }
+ io.close
end
assert('IO.sysopen, IO#syswrite') do

IO#sysread Check for readable