1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2008-02-15 07:35:11 +00:00
parent 12b1578cab
commit 878bbd1199
2 changed files with 11 additions and 5 deletions

View file

@ -1,3 +1,7 @@
Fri Feb 15 16:22:49 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (open_key_args): allow specifying both :mode and :encoding.
Fri Feb 15 15:34:47 2008 Tanaka Akira <akr@fsij.org> Fri Feb 15 15:34:47 2008 Tanaka Akira <akr@fsij.org>
* string.c (rb_str_getbyte): new method. * string.c (rb_str_getbyte): new method.

12
io.c
View file

@ -5820,6 +5820,7 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
static VALUE encoding, mode, open_args; static VALUE encoding, mode, open_args;
FilePathValue(argv[0]); FilePathValue(argv[0]);
arg->io = 0;
arg->argc = argc > 1 ? 1 : 0; arg->argc = argc > 1 ? 1 : 0;
arg->argv = argv + 1; arg->argv = argv + 1;
if (argc == 1) { if (argc == 1) {
@ -5861,16 +5862,16 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
args[0] = argv[0]; args[0] = argv[0];
args[1] = v; args[1] = v;
arg->io = rb_f_open(2, args); arg->io = rb_f_open(2, args);
return;
} }
v = rb_hash_aref(opt, encoding); v = rb_hash_aref(opt, encoding);
if (!NIL_P(v)) { if (!NIL_P(v)) {
rb_io_t *fptr; 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); GetOpenFile(arg->io, fptr);
mode_enc(fptr, StringValueCStr(v)); 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. * <code>read</code> ensures the file is closed before returning.
* *
* If the last argument is a hash, it specifies option for internal * 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 * encoding: string or encoding
* *
* specifies encoding of the read string. encoding will be ignored * specifies encoding of the read string. encoding will be ignored