diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-24 10:18:32 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-24 10:18:32 +0000 |
commit | 7918141932ee5c440f556f272a01befd1de5a52d (patch) | |
tree | 3107ed958bfb9d5190601728127166ea1e0a8110 | |
parent | 6f8c2ea9c425fc4e263c0327bef273595cdfb9ae (diff) | |
download | ruby-7918141932ee5c440f556f272a01befd1de5a52d.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | io.c | 21 |
2 files changed, 20 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Sun Aug 24 19:17:31 2008 Tanaka Akira <akr@fsij.org> + + * io.c (rb_io_open): add an argument: vperm. + (open_key_args): call rb_io_open with perm. + Sun Aug 24 19:11:07 2008 Tanaka Akira <akr@fsij.org> * io.c (sym_invalid): removed. @@ -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 |