summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 04:26:38 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 04:26:38 +0000
commit1b27cfcd6ca0bcf7b75be27de4746cd030b7c1d4 (patch)
treeb921c8618fbacd59c47fba4d80935edc41659c12 /io.c
parent65a953c7c9527e32aa3024322bde24864a3a66cb (diff)
downloadruby-1b27cfcd6ca0bcf7b75be27de4746cd030b7c1d4.tar.gz
* io.c (rb_io_external_encoding): new method.
* encoding.c (rb_enc_from_encoding): returns Qnil for NULL encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/io.c b/io.c
index 89d15cac8d..6947987ee8 100644
--- a/io.c
+++ b/io.c
@@ -5657,6 +5657,24 @@ rb_io_s_read(int argc, VALUE *argv, VALUE io)
return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
}
+
+/*
+ * call-seq:
+ * io.externalencoding => encoding
+ *
+ * Returns the Encoding object that represents the encoding of the file.
+ */
+
+static VALUE
+rb_io_external_encoding(VALUE io)
+{
+ rb_io_t *fptr;
+
+ GetOpenFile(io, fptr);
+ return rb_enc_from_encoding(fptr->enc);
+}
+
+
static VALUE
argf_tell(void)
{
@@ -6232,6 +6250,8 @@ Init_IO(void)
rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0);
+ rb_define_method(rb_cIO, "external_encoding", rb_io_external_encoding, 0);
+
rb_define_variable("$stdin", &rb_stdin);
rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);