aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-18 07:15:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-18 07:15:07 +0000
commitd8970de1bfd7956b676e56cac42c04da2b5656cc (patch)
treeeaca8d061b5d4860b7bc8be12d9d553bd3a4a07c /io.c
parent3b3ec02bb8d9af98d453415268244f468e62758d (diff)
downloadruby-d8970de1bfd7956b676e56cac42c04da2b5656cc.tar.gz
io.c: opening external command
* io.c (rb_io_open_generic): try to open the named file as usual, if klass is not IO nor File, so that Errno::ENOENT will be raised probably. calling on File will be same in the future. From: Nobuyoshi Nakada <nobu@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/io.c b/io.c
index a8ed4f0433..24f721e8fd 100644
--- a/io.c
+++ b/io.c
@@ -7088,17 +7088,11 @@ rb_io_open_generic(VALUE klass, VALUE filename, int oflags, int fmode,
const convconfig_t *convconfig, mode_t perm)
{
VALUE cmd;
- if (!NIL_P(cmd = check_pipe_command(filename))) {
- if (klass != rb_cIO) {
- ID func = rb_frame_this_func();
- VALUE fname = rb_id2str(func);
- static const char MSG[] = "IO.%"PRIsVALUE" called on %"PRIsVALUE" to invoke external command";
- if (klass == rb_cFile) {
- rb_warn(MSG, fname, klass);
- }
- else {
- rb_raise(rb_eArgError, MSG, fname, klass);
- }
+ const int warn = klass == rb_cFile;
+ if ((warn || klass == rb_cIO) && !NIL_P(cmd = check_pipe_command(filename))) {
+ if (warn) {
+ rb_warn("IO.%"PRIsVALUE" called on File to invoke external command",
+ rb_id2str(rb_frame_this_func()));
}
return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, convconfig);
}