summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-23 01:45:49 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-23 01:45:49 +0000
commitd2cb86c532c5123d93351d4953af1f4a351a7ce5 (patch)
tree6e712b46110516b0705f609a30d000ff94f1c189
parent341abd3f881ce77458f62c46e6421fd6c4444984 (diff)
* io.c (check_pipe_command): extracted from rb_f_open and rb_io_open.
(rb_f_open): use check_pipe_command. (rb_io_open): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--io.c28
2 files changed, 27 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index ad03b21d1e..1a640422f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Aug 23 10:42:52 2008 Tanaka Akira <akr@fsij.org>
+
+ * io.c (check_pipe_command): extracted from rb_f_open and rb_io_open.
+ (rb_f_open): use check_pipe_command.
+ (rb_io_open): ditto.
+
Sat Aug 23 10:13:00 2008 Tanaka Akira <akr@fsij.org>
* io.c (read_all): fptr->enc2 is 0 if no conversion.
diff --git a/io.c b/io.c
index 47b4505820..0cca5b07f5 100644
--- a/io.c
+++ b/io.c
@@ -4673,6 +4673,22 @@ rb_io_s_sysopen(int argc, VALUE *argv)
return INT2NUM(fd);
}
+static VALUE
+check_pipe_command(VALUE filename_or_command)
+{
+ char *s = RSTRING_PTR(filename_or_command);
+ long l = RSTRING_LEN(filename_or_command);
+ char *e = s + l;
+ int chlen;
+
+ if (rb_enc_ascget(s, e, &chlen, rb_enc_get(filename_or_command)) == '|') {
+ VALUE cmd = rb_str_new(s+chlen, l-chlen);
+ OBJ_INFECT(cmd, filename_or_command);
+ return cmd;
+ }
+ return Qnil;
+}
+
/*
* call-seq:
* open(path [, mode_enc [, perm]] ) => io or nil
@@ -4798,10 +4814,9 @@ rb_f_open(int argc, VALUE *argv)
redirect = Qtrue;
}
else {
- char *str = StringValuePtr(tmp);
- if (str && str[0] == '|') {
- argv[0] = rb_str_new(str+1, RSTRING_LEN(tmp)-1);
- OBJ_INFECT(argv[0], tmp);
+ VALUE cmd = check_pipe_command(tmp);
+ if (!NIL_P(cmd)) {
+ argv[0] = cmd;
return rb_io_s_popen(argc, argv, rb_cIO);
}
}
@@ -4821,13 +4836,12 @@ rb_f_open(int argc, VALUE *argv)
static VALUE
rb_io_open(VALUE filename, VALUE mode, VALUE opt)
{
- char *fname = RSTRING_PTR(filename);
+ VALUE cmd;
int modenum, flags;
convconfig_t convconfig;
rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
- if (fname[0] == '|') {
- VALUE cmd = rb_str_new2(fname+1);
+ if (!NIL_P(cmd = check_pipe_command(filename))) {
return pipe_open_s(cmd, rb_io_modenum_mode(modenum), flags, &convconfig);
}
else {