console.c in io-console-0.4.1 vs console.c in io-console-0.4.2
- old
+ new
@@ -5,10 +5,12 @@
#include "ruby.h"
#ifdef HAVE_RUBY_IO_H
#include "ruby/io.h"
#else
#include "rubyio.h"
+/* assumes rb_io_t doesn't have pathv */
+#include "util.h" /* for ruby_strdup() */
#endif
#ifndef HAVE_RB_IO_T
typedef OpenFile rb_io_t;
#endif
@@ -21,10 +23,14 @@
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
+#ifndef RB_TYPE_P
+#define RB_TYPE_P(obj, type) (TYPE(obj) == type)
+#endif
+
#if defined HAVE_TERMIOS_H
# include <termios.h>
typedef struct termios conmode;
static int
@@ -99,15 +105,32 @@
static rawmode_arg_t *
rawmode_opt(int argc, VALUE *argv, rawmode_arg_t *opts)
{
rawmode_arg_t *optp = NULL;
VALUE vopts;
+#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
rb_scan_args(argc, argv, "0:", &vopts);
+#else
+ vopts = Qnil;
+ if (argc > 0) {
+ vopts = argv[--argc];
+ if (!NIL_P(vopts)) {
+# ifdef HAVE_RB_CHECK_HASH_TYPE
+ vopts = rb_check_hash_type(vopts);
+ if (NIL_P(vopts)) ++argc;
+# else
+ Check_Type(vopts, T_HASH);
+# endif
+ }
+ }
+ rb_scan_args(argc, argv, "0");
+#endif
if (!NIL_P(vopts)) {
VALUE vmin = rb_hash_aref(vopts, ID2SYM(rb_intern("min")));
VALUE vtime = rb_hash_aref(vopts, ID2SYM(rb_intern("time")));
- opts->vmin = 0;
+ /* default values by `stty raw` */
+ opts->vmin = 1;
opts->vtime = 0;
if (!NIL_P(vmin)) {
opts->vmin = NUM2INT(vmin);
optp = opts;
}
@@ -641,10 +664,27 @@
}
#endif
return io;
}
+#ifndef HAVE_RB_CLOEXEC_OPEN
+static int
+rb_cloexec_open(const char *pathname, int flags, mode_t mode)
+{
+ int ret;
+#ifdef O_CLOEXEC
+ /* O_CLOEXEC is available since Linux 2.6.23. Linux 2.6.18 silently ignore it. */
+ flags |= O_CLOEXEC;
+#elif defined O_NOINHERIT
+ flags |= O_NOINHERIT;
+#endif
+ return open(pathname, flags, mode);
+}
+
+#define rb_update_max_fd(fd) (void)(fd)
+#endif
+
/*
* call-seq:
* IO.console -> #<File:/dev/tty>
*
* Returns an File instance opened console.
@@ -702,10 +742,14 @@
rb_update_max_fd(fd);
args[1] = INT2FIX(O_RDWR);
args[0] = INT2NUM(fd);
con = rb_class_new_instance(2, args, klass);
GetOpenFile(con, fptr);
+#ifdef HAVE_RUBY_IO_H
fptr->pathv = rb_obj_freeze(rb_str_new2(CONSOLE_DEVICE));
+#else
+ fptr->path = ruby_strdup(CONSOLE_DEVICE);
+#endif
#ifdef CONSOLE_DEVICE_FOR_WRITING
GetOpenFile(out, ofptr);
# ifdef HAVE_RB_IO_GET_WRITE_IO
ofptr->pathv = fptr->pathv;
fptr->tied_io_for_writing = out;