aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-04 11:28:20 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-12 14:58:13 +0900
commite6551d835febe00fce6c6a3b12c4e394d2a05bd6 (patch)
tree52face52cd84ec7406e993d5bd227c0d902c9946 /io.c
parentf22c4ff359498ab342e4b6d6feb21af6004ee270 (diff)
downloadruby-e6551d835febe00fce6c6a3b12c4e394d2a05bd6.tar.gz
PAGER without fork&exec too [Feature #16754]
Diffstat (limited to 'io.c')
-rw-r--r--io.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/io.c b/io.c
index 2cdfd80610..4be5f05d2f 100644
--- a/io.c
+++ b/io.c
@@ -6868,6 +6868,8 @@ pipe_close(VALUE io)
return Qnil;
}
+static VALUE popen_finish(VALUE port, VALUE klass);
+
/*
* call-seq:
* IO.popen([env,] cmd, mode="r" [, opt]) -> io
@@ -6957,10 +6959,7 @@ pipe_close(VALUE io)
static VALUE
rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
{
- const char *modestr;
- VALUE pname, pmode = Qnil, port, tmp, opt = Qnil, env = Qnil, execarg_obj = Qnil;
- int oflags, fmode;
- convconfig_t convconfig;
+ VALUE pname, pmode = Qnil, opt = Qnil, env = Qnil;
if (argc > 1 && !NIL_P(opt = rb_check_hash_type(argv[argc-1]))) --argc;
if (argc > 1 && !NIL_P(env = rb_check_hash_type(argv[0]))) --argc, ++argv;
@@ -6976,6 +6975,16 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
rb_error_arity(argc + ex, 1 + ex, 2 + ex);
}
}
+ return popen_finish(rb_io_popen(pname, pmode, env, opt), klass);
+}
+
+VALUE
+rb_io_popen(VALUE pname, VALUE pmode, VALUE env, VALUE opt)
+{
+ const char *modestr;
+ VALUE tmp, execarg_obj = Qnil;
+ int oflags, fmode;
+ convconfig_t convconfig;
tmp = rb_check_array_type(pname);
if (!NIL_P(tmp)) {
@@ -7003,7 +7012,12 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
rb_io_extract_modeenc(&pmode, 0, opt, &oflags, &fmode, &convconfig);
modestr = rb_io_oflags_modestr(oflags);
- port = pipe_open(execarg_obj, modestr, fmode, &convconfig);
+ return pipe_open(execarg_obj, modestr, fmode, &convconfig);
+}
+
+static VALUE
+popen_finish(VALUE port, VALUE klass)
+{
if (NIL_P(port)) {
/* child */
if (rb_block_given_p()) {