зеркало из https://github.com/github/ruby.git
io.c: fix buffered output
* io.c (io_binwritev): append to buffered data, not overwriting. [Feature #9323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
92023a8f60
Коммит
71a7ef31d7
4
io.c
4
io.c
|
@ -1518,8 +1518,8 @@ io_binwritev(struct iovec *iov, int iovcnt, rb_io_t *fptr)
|
|||
}
|
||||
|
||||
if (fptr->wbuf.ptr && fptr->wbuf.len) {
|
||||
if (fptr->wbuf.off + fptr->wbuf.len + total <= fptr->wbuf.capa) {
|
||||
long offset = fptr->wbuf.off;
|
||||
long offset = fptr->wbuf.off + fptr->wbuf.len;
|
||||
if (offset + total <= fptr->wbuf.capa) {
|
||||
for (i = 1; i < iovcnt; i++) {
|
||||
memcpy(fptr->wbuf.ptr+offset, iov[i].iov_base, iov[i].iov_len);
|
||||
offset += iov[i].iov_len;
|
||||
|
|
|
@ -1225,6 +1225,20 @@ class TestIO < Test::Unit::TestCase
|
|||
end)
|
||||
end
|
||||
|
||||
def test_write_with_multiple_arguments_and_buffer
|
||||
mkcdtmpdir do
|
||||
line = "x"*9+"\n"
|
||||
file = "test.out"
|
||||
open(file, "wb") do |w|
|
||||
w.write(line)
|
||||
assert_equal(11, w.write(line, "\n"))
|
||||
end
|
||||
open(file, "rb") do |r|
|
||||
assert_equal([line, line, "\n"], r.readlines)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_write_with_many_arguments
|
||||
[1023, 1024].each do |n|
|
||||
pipe(proc do |w|
|
||||
|
|
Загрузка…
Ссылка в новой задаче