summaryrefslogtreecommitdiffstats
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
commitd8e8231c22e0c31e76a30ab86faf2723f9c6dd53 (patch)
treeb921c8618fbacd59c47fba4d80935edc41659c12 /io.c
parent43bc9c1ef979719fe47462e2ae9e370f65df602a (diff)
downloadruby-d8e8231c22e0c31e76a30ab86faf2723f9c6dd53.tar.gz
ruby-d8e8231c22e0c31e76a30ab86faf2723f9c6dd53.tar.xz
ruby-d8e8231c22e0c31e76a30ab86faf2723f9c6dd53.zip
* io.c (rb_io_external_encoding): new method.
* encoding.c (rb_enc_from_encoding): returns Qnil for NULL encoding. git-svn-id: http://svn.ruby-lang.org/repos/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 89d15cac8..6947987ee 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);