Project

General

Profile

Backport #2559 ยป io-write-fix.diff

hongli (Hongli Lai), 01/06/2010 03:37 AM

View differences:

io.c
{
long len, n, r, l, offset = 0;
FILE *f = GetWriteFile(fptr);
#if BSD_STDIO
off_t cur_offset;
#endif
len = RSTRING(str)->len;
if ((n = len) <= 0) return n;
......
r = write(fileno(f), RSTRING(str)->ptr+offset, l);
TRAP_END;
#if BSD_STDIO
fseeko(f, lseek(fileno(f), (off_t)0, SEEK_CUR), SEEK_SET);
if (r > 0) {
cur_offset = lseek(fileno(f), (off_t)0, SEEK_CUR);
if (cur_offset != -1) {
if (fseeko(f, cur_offset, SEEK_SET) == -1)
/* Raise fseeko's error. */
r = -1;
}
else if (errno != ESPIPE) {
/* Raise lseek's error. */
r = -1;
}
/* else if (errno == ESPIPE) ignore error */
}
#endif
if (r == n) return len;
if (0 <= r) {
test/io/test_write.rb
require 'test/unit'
class TestIOWrite < Test::Unit::TestCase
def test_write
a, b = IO.pipe
begin
a.close
assert_raises(Errno::EPIPE) do
b.write("hi")
end
ensure
a.close if !a.closed?
b.close if !b.closed?
end
end
end
    (1-1/1)