summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-31 03:11:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-31 03:11:14 +0000
commit610e39e9495e0a89ae36b3ae750ed45c06e6c4a3 (patch)
tree390636f02397fa1d3c3b6f6e84ea4ce4058657d7 /io.c
parentc949aab59acad037f90a30578845b03474e6e5d3 (diff)
io.c: rb_io_open_generic
* io.c (rb_io_open_generic): split from rb_io_open without argument conversions. * io.c (rb_io_s_binread): get rid of unnecessary object creation and conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/io.c b/io.c
index 365a0ba5f7..9e782a9aaf 100644
--- a/io.c
+++ b/io.c
@@ -6578,23 +6578,31 @@ rb_f_open(int argc, VALUE *argv)
return rb_io_s_open(argc, argv, rb_cFile);
}
+static VALUE rb_io_open_generic(VALUE, int, int, const convconfig_t *, mode_t);
+
static VALUE
rb_io_open(VALUE filename, VALUE vmode, VALUE vperm, VALUE opt)
{
- VALUE cmd;
int oflags, fmode;
convconfig_t convconfig;
mode_t perm;
rb_io_extract_modeenc(&vmode, &vperm, opt, &oflags, &fmode, &convconfig);
perm = NIL_P(vperm) ? 0666 : NUM2MODET(vperm);
+ return rb_io_open_generic(filename, oflags, fmode, &convconfig, perm);
+}
+static VALUE
+rb_io_open_generic(VALUE filename, int oflags, int fmode,
+ const convconfig_t *convconfig, mode_t perm)
+{
+ VALUE cmd;
if (!NIL_P(cmd = check_pipe_command(filename))) {
- return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, &convconfig);
+ return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, convconfig);
}
else {
return rb_file_open_generic(io_alloc(rb_cFile), filename,
- oflags, fmode, &convconfig, perm);
+ oflags, fmode, convconfig, perm);
}
}
@@ -9899,10 +9907,19 @@ rb_io_s_binread(int argc, VALUE *argv, VALUE io)
{
VALUE offset;
struct foreach_arg arg;
+ enum {
+ fmode = FMODE_READABLE|FMODE_BINMODE,
+ oflags = O_RDONLY
+#ifdef O_BINARY
+ |O_BINARY
+#endif
+ };
+ convconfig_t convconfig = {NULL, NULL, 0, Qnil};
rb_scan_args(argc, argv, "12", NULL, NULL, &offset);
FilePathValue(argv[0]);
- arg.io = rb_io_open(argv[0], rb_str_new_cstr("rb:ASCII-8BIT"), Qnil, Qnil);
+ convconfig.enc = rb_ascii8bit_encoding();
+ arg.io = rb_io_open_generic(argv[0], oflags, fmode, &convconfig, 0);
if (NIL_P(arg.io)) return Qnil;
arg.argv = argv+1;
arg.argc = (argc > 1) ? 1 : 0;