IO#sysread Check for readable

This commit is contained in:
ksss
2017-05-27 13:29:38 +09:00
parent 0c0b34136e
commit a3a4f4d061
2 changed files with 8 additions and 0 deletions
+3
View File
@@ -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 */
+5
View File
@@ -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