From 72bf77fb30fbc97e9dcbfe50d0f62f2f40c93ae3 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 25 Dec 2007 06:44:58 +0000 Subject: * io.c (rb_io_external_encoding): should return nil for pass-through write IO. [ruby-dev:32740] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'io.c') diff --git a/io.c b/io.c index 9556b98ff6..41449beb33 100644 --- a/io.c +++ b/io.c @@ -5921,6 +5921,7 @@ rb_io_s_read(int argc, VALUE *argv, VALUE io) * io.external_encoding => encoding * * Returns the Encoding object that represents the encoding of the file. + * If io is write mode and no encoding is specified, returns nil. */ static VALUE @@ -5935,6 +5936,11 @@ rb_io_external_encoding(VALUE io) if (!fptr->enc && fptr->fd == 0) { fptr->enc = rb_default_external_encoding(); } + if (fptr->mode & FMODE_WRITABLE) { + if (fptr->enc) + return rb_enc_from_encoding(fptr->enc); + return Qnil; + } return rb_enc_from_encoding(io_read_encoding(fptr)); } -- cgit v1.2.3