summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-29 05:46:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-29 05:46:23 +0000
commit8354b6d2cd0b83ad801d038a034e78e397ca32db (patch)
tree2b9f676fed49aaef4d5e0a9851a8919cc2eea413 /io.c
parent85195203f4eca03e163e5c9c2fbe503b0d40bd95 (diff)
io.c: honor buffered mode
* io.c (io_writev): honor buffered mode to get rid of broken pipe error when stdout is redirected to a pipeline. [ruby-core:83578] [Feature #14042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/io.c b/io.c
index a4afeafc60..8a5d6ab246 100644
--- a/io.c
+++ b/io.c
@@ -1637,12 +1637,16 @@ io_writev(int argc, VALUE *argv, VALUE io)
for (i = 0; i < argc; i += cnt) {
#ifdef HAVE_WRITEV
- if ((cnt = argc - i) >= IOV_MAX) cnt = IOV_MAX-1;
- n = io_fwritev(cnt, &argv[i], fptr);
-#else
- /* sync at last item */
- n = io_fwrite(argv[i], fptr, (i < argc-1));
+ if ((fptr->mode & (FMODE_SYNC|FMODE_TTY)) && ((cnt = argc - i) < IOV_MAX)) {
+ n = io_fwritev(cnt, &argv[i], fptr);
+ }
+ else
#endif
+ {
+ cnt = 1;
+ /* sync at last item */
+ n = io_fwrite(rb_obj_as_string(argv[i]), fptr, (i < argc-1));
+ }
if (n == -1L) rb_sys_fail_path(fptr->pathv);
total = rb_fix_plus(LONG2FIX(n), total);
}