summaryrefslogtreecommitdiff
path: root/ext/io/console/console.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-13 14:28:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-13 14:28:53 +0000
commita7b0b52f09b63e8ffe28b0040b54ae71a4a829e4 (patch)
tree4dc5ccf1790b9efe273b6a5195f2b253b5e2a9e2 /ext/io/console/console.c
parentbcfc22b10e30771e692f7716a1fec7577373963e (diff)
* ext/io/console/console.c (console_dev): take care of no-ctty
case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/io/console/console.c')
-rw-r--r--ext/io/console/console.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index cc4ab113809..c2660d2ac94 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -557,27 +557,36 @@ console_dev(VALUE klass)
VALUE out;
rb_io_t *ofptr;
#endif
+ int fd, mode;
- args[1] = INT2FIX(O_RDWR);
#ifdef CONSOLE_DEVICE_FOR_WRITING
- args[0] = rb_str_new2(CONSOLE_DEVICE_FOR_WRITING);
+ fd = open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY);
+ if (fd < 0) return Qnil;
+ args[1] = INT2FIX(O_WRONLY);
+ args[0] = INT2NUM(fd);
out = rb_class_new_instance(2, args, klass);
#endif
- args[0] = rb_str_new2(CONSOLE_DEVICE_FOR_READING);
- con = rb_class_new_instance(2, args, klass);
+ fd = open(CONSOLE_DEVICE_FOR_READING, O_RDWR);
+ if (fd < 0) {
#ifdef CONSOLE_DEVICE_FOR_WRITING
+ rb_io_close(out);
+#endif
+ return Qnil;
+ }
+ args[1] = INT2FIX(O_RDWR);
+ args[0] = INT2NUM(fd);
+ con = rb_class_new_instance(2, args, klass);
GetOpenFile(con, fptr);
+ fptr->pathv = rb_obj_freeze(rb_str_new2(CONSOLE_DEVICE));
+#ifdef CONSOLE_DEVICE_FOR_WRITING
GetOpenFile(out, ofptr);
# ifdef HAVE_RB_IO_GET_WRITE_IO
-# ifdef _WIN32
- ofptr->pathv = fptr->pathv = rb_str_new2(CONSOLE_DEVICE);
-# endif
+ ofptr->pathv = fptr->pathv;
fptr->tied_io_for_writing = out;
# else
fptr->f2 = ofptr->f;
ofptr->f = 0;
# endif
- fptr->mode |= FMODE_WRITABLE;
#endif
rb_const_set(klass, id_console, con);
}