aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-04 08:08:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-04 08:08:46 +0000
commit8259e4aa9a140b9584dec2be4e542dfbd71a40ad (patch)
treefb073722738e236e19c9f71290ffd167012dc96b /io.c
parent7f8eb55d6c3f6132d84ce46ee468d5e660253471 (diff)
downloadruby-8259e4aa9a140b9584dec2be4e542dfbd71a40ad.tar.gz
* io.c (pipe_open): refined the message of NotImplementedError.
[ruby-dev:30685] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/io.c b/io.c
index 60bee39968..37c96b9233 100644
--- a/io.c
+++ b/io.c
@@ -3056,7 +3056,7 @@ pipe_open(int argc, VALUE *argv, const char *mode)
int pid = 0;
rb_io_t *fptr;
VALUE port, prog;
-#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
+#if defined(HAVE_FORK)
int status;
struct popen_arg arg;
#elif defined(_WIN32)
@@ -3077,7 +3077,14 @@ pipe_open(int argc, VALUE *argv, const char *mode)
cmd = StringValueCStr(prog);
doexec = (strcmp("-", cmd) != 0);
-#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
+#if !defined(HAVE_FORK)
+ if (!doexec) {
+ rb_raise(rb_eNotImpError,
+ "The fork(2) function is unimplemented on this machine");
+ }
+#endif
+
+#if defined(HAVE_FORK)
if (!doexec) {
fflush(stdin); /* is it really needed? */
rb_io_flush(rb_stdout);
@@ -3085,19 +3092,22 @@ pipe_open(int argc, VALUE *argv, const char *mode)
}
arg.modef = modef;
arg.pair[0] = arg.pair[1] = -1;
- if ((modef & FMODE_READABLE) && (modef & FMODE_WRITABLE)) {
+ switch (modef & (FMODE_READABLE|FMODE_WRITABLE)) {
+#if defined(HAVE_SOCKETPAIR)
+ case FMODE_READABLE|FMODE_WRITABLE:
if (socketpair(AF_UNIX, SOCK_STREAM, 0, arg.pair) < 0)
rb_sys_fail(cmd);
- }
- else if (modef & FMODE_READABLE) {
+ break;
+#endif
+ case FMODE_READABLE:
if (pipe(arg.pair) < 0)
rb_sys_fail(cmd);
- }
- else if (modef & FMODE_WRITABLE) {
+ break;
+ case FMODE_WRITABLE:
if (pipe(arg.pair) < 0)
rb_sys_fail(cmd);
- }
- else {
+ break;
+ default:
rb_sys_fail(cmd);
}
if (doexec) {
@@ -3137,7 +3147,6 @@ pipe_open(int argc, VALUE *argv, const char *mode)
fd = arg.pair[1];
}
#elif defined(_WIN32)
- if (!doexec) rb_notimplement();
if (argc) {
char **args = ALLOCA_N(char *, argc+1);
int i;
@@ -3165,7 +3174,6 @@ pipe_open(int argc, VALUE *argv, const char *mode)
}
}
#else
- if (!doexec) rb_notimplement();
if (argc) {
prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
cmd = StringValueCStr(prog);