summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-18 03:38:20 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-18 03:38:20 (GMT)
commit7d24c27d2123c509c546c1563c01c1a01eb34f0f (patch)
tree6c60f603e589a46fcdce704d0550bb980ffd890a /io.c
parent2e24a66b883b7f14d9dd0aeffa749d68dd5d6939 (diff)
io.c: open_key_args by rb_io_open
* io.c (open_key_args): open by rb_io_open always also when open_args: option is given. From: Nobuyoshi Nakada <nobu@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/io.c b/io.c
index f988c1b..4c0fc43 100644
--- a/io.c
+++ b/io.c
@@ -7098,16 +7098,6 @@ rb_io_open_generic(VALUE filename, int oflags, int fmode,
}
static VALUE
-rb_io_open_with_args(int argc, const VALUE *argv)
-{
- VALUE io;
-
- io = io_alloc(rb_cFile);
- rb_open_file(argc, argv, io);
- return io;
-}
-
-static VALUE
io_reopen(VALUE io, VALUE nfile)
{
rb_io_t *fptr, *orig;
@@ -10168,6 +10158,7 @@ static void
open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg)
{
VALUE path, v;
+ VALUE vmode = Qnil, vperm = Qnil;
path = *argv++;
argc--;
@@ -10176,29 +10167,18 @@ open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg)
arg->argc = argc;
arg->argv = argv;
if (NIL_P(opt)) {
- arg->io = rb_io_open(path, INT2NUM(O_RDONLY), INT2FIX(0666), Qnil);
- return;
+ vmode = INT2NUM(O_RDONLY);
+ vperm = INT2FIX(0666);
}
- v = rb_hash_aref(opt, sym_open_args);
- if (!NIL_P(v)) {
- VALUE args;
- long n;
+ else if (!NIL_P(v = rb_hash_aref(opt, sym_open_args))) {
+ int n;
v = rb_to_array_type(v);
- n = RARRAY_LEN(v) + 1;
-#if SIZEOF_LONG > SIZEOF_INT
- if (n > INT_MAX) {
- rb_raise(rb_eArgError, "too many arguments");
- }
-#endif
- args = rb_ary_tmp_new(n);
- rb_ary_push(args, path);
- rb_ary_concat(args, v);
- arg->io = rb_io_open_with_args((int)n, RARRAY_CONST_PTR(args));
- rb_ary_clear(args); /* prevent from GC */
- return;
+ n = RARRAY_LENINT(v);
+ rb_check_arity(n, 0, 3); /* rb_io_open */
+ rb_scan_args(n, RARRAY_CONST_PTR(v), "02:", &vmode, &vperm, &opt);
}
- arg->io = rb_io_open(path, Qnil, Qnil, opt);
+ arg->io = rb_io_open(path, vmode, vperm, opt);
}
static VALUE