Merge pull request #78 from ksss/syswrite

Should raise SyscallError on IO#syswrite
This commit is contained in:
Tomoyuki Sahara
2017-05-23 15:09:04 +09:00
committed by GitHub
2 changed files with 5 additions and 7 deletions
+2 -7
View File
@@ -123,14 +123,9 @@ class IO
def write(string)
str = string.is_a?(String) ? string : string.to_s
return str.size unless str.size > 0
len = syswrite(str)
if len != -1
@pos += len
return len
end
raise IOError
@pos += len
len
end
def <<(str)
+3
View File
@@ -708,6 +708,9 @@ mrb_io_syswrite(mrb_state *mrb, mrb_value io)
fd = fptr->fd2;
}
length = write(fd, RSTRING_PTR(buf), RSTRING_LEN(buf));
if (length == -1) {
mrb_sys_fail(mrb, 0);
}
return mrb_fixnum_value(length);
}