summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-24 10:18:32 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-24 10:18:32 +0000
commit7918141932ee5c440f556f272a01befd1de5a52d (patch)
tree3107ed958bfb9d5190601728127166ea1e0a8110 /io.c
parent6f8c2ea9c425fc4e263c0327bef273595cdfb9ae (diff)
* io.c (rb_io_open): add an argument: vperm.
(open_key_args): call rb_io_open with perm. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/io.c b/io.c
index 4f37000ef7..9681d466ab 100644
--- a/io.c
+++ b/io.c
@@ -4860,19 +4860,22 @@ rb_f_open(int argc, VALUE *argv)
}
static VALUE
-rb_io_open(VALUE filename, VALUE mode, VALUE opt)
+rb_io_open(VALUE filename, VALUE mode, VALUE vperm, VALUE opt)
{
VALUE cmd;
int modenum, flags;
convconfig_t convconfig;
+ mode_t perm;
+
rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
+ perm = NIL_P(vperm) ? 0666 : NUM2UINT(vperm);
if (!NIL_P(cmd = check_pipe_command(filename))) {
return pipe_open_s(cmd, rb_io_modenum_mode(modenum), flags, &convconfig);
}
else {
return rb_file_open_generic(io_alloc(rb_cFile), filename,
- modenum, flags, &convconfig, 0666);
+ modenum, flags, &convconfig, perm);
}
}
@@ -6760,6 +6763,7 @@ static void
open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
{
VALUE opt, v;
+ VALUE mode, perm;
FilePathValue(argv[0]);
arg->io = 0;
@@ -6767,7 +6771,7 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
arg->argv = argv + 1;
if (argc == 1) {
no_key:
- arg->io = rb_io_open(argv[0], INT2NUM(O_RDONLY), Qnil);
+ arg->io = rb_io_open(argv[0], INT2NUM(O_RDONLY), INT2FIX(0666), Qnil);
return;
}
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
@@ -6786,10 +6790,15 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
arg->io = rb_io_open_with_args(RARRAY_LEN(args), RARRAY_PTR(args));
return;
}
+ mode = Qnil;
+ perm = INT2NUM(O_RDONLY);
v = rb_hash_aref(opt, sym_mode);
- if (NIL_P(v))
- v = INT2NUM(O_RDONLY);
- arg->io = rb_io_open(argv[0], v, opt);
+ if (!NIL_P(v))
+ mode = v;
+ v = rb_hash_aref(opt, sym_perm);
+ if (!NIL_P(v))
+ perm = v;
+ arg->io = rb_io_open(argv[0], mode, perm, opt);
}
static VALUE