mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
IO#sysread Check for readable
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user