summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-15 07:35:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-15 07:35:11 +0000
commit878bbd1199167d6beb0faa85a6d8fe5e8122ee49 (patch)
tree4c17ba423dc21f960b21106194619700839396f7 /io.c
parent12b1578cabdf06cc76f6debaf8a953a922b47154 (diff)
* io.c (open_key_args): allow specifying both :mode and :encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/io.c b/io.c
index 79995c7dd1..d8e518fa87 100644
--- a/io.c
+++ b/io.c
@@ -5820,6 +5820,7 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
static VALUE encoding, mode, open_args;
FilePathValue(argv[0]);
+ arg->io = 0;
arg->argc = argc > 1 ? 1 : 0;
arg->argv = argv + 1;
if (argc == 1) {
@@ -5861,16 +5862,16 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
args[0] = argv[0];
args[1] = v;
arg->io = rb_f_open(2, args);
- return;
}
v = rb_hash_aref(opt, encoding);
if (!NIL_P(v)) {
rb_io_t *fptr;
- arg->io = rb_io_open(RSTRING_PTR(argv[0]), "r");
+ if (!arg->io) {
+ arg->io = rb_io_open(RSTRING_PTR(argv[0]), "r");
+ }
GetOpenFile(arg->io, fptr);
mode_enc(fptr, StringValueCStr(v));
- return;
}
}
@@ -5971,8 +5972,9 @@ io_s_read(struct foreach_arg *arg)
* <code>read</code> ensures the file is closed before returning.
*
* If the last argument is a hash, it specifies option for internal
- * open(). The key would be the following. They are all exclusive,
- *
+ * open(). The key would be the following. open_args: is exclusive
+ * to others.
+ *
* encoding: string or encoding
*
* specifies encoding of the read string. encoding will be ignored