diff -ubr termios-0.9.4/termios.c termios-0.9.4.patched/termios.c
--- termios-0.9.4/termios.c	2009-04-02 06:08:18.000000000 -0700
+++ termios-0.9.4.patched/termios.c	2009-04-02 06:07:08.000000000 -0700
@@ -7,11 +7,21 @@
  */
 
 #include "ruby.h"
-#include "rubyio.h"
+#include "ruby/io.h"
 #include <termios.h>
 #include <unistd.h>
 #include <string.h>
 
+#ifndef GetReadFile
+#define FPTR_TO_FD(fptr) (fptr->fd)
+#else
+#define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr)))
+#endif
+
+#ifndef HAVE_RB_IO_T
+#define rb_io_t OpenFile
+#endif
+
 static VALUE mTermios;
 static VALUE cTermios;
 static VALUE tcsetattr_opt, tcflush_qs, tcflow_act;
@@ -179,8 +189,8 @@
 
     cc_ary = rb_ivar_get(obj, id_cc);
     for (i = 0; i < NCCS; i++) {
-	if (TYPE(RARRAY(cc_ary)->ptr[i]) == T_FIXNUM) {
-	    t->c_cc[i] = NUM2INT(RARRAY(cc_ary)->ptr[i]);
+	if (TYPE(RARRAY_PTR(cc_ary)[i]) == T_FIXNUM) {
+	    t->c_cc[i] = NUM2INT(RARRAY_PTR(cc_ary)[i]);
 	}
 	else {
 	    t->c_cc[i] = 0;
@@ -197,11 +207,11 @@
     VALUE io;
 {
     struct termios t;
-    OpenFile *fptr;
+    rb_io_t *fptr;
 
     Check_Type(io, T_FILE);
     GetOpenFile(io, fptr);
-    if (tcgetattr(fileno(fptr->f), &t) < 0) {
+    if (tcgetattr(FPTR_TO_FD(fptr), &t) < 0) {
 	rb_raise(rb_eRuntimeError, 
 		 "can't get terminal parameters (%s)", strerror(errno));
     }
@@ -221,7 +231,7 @@
     VALUE io, opt, param;
 {
     VALUE old;
-    OpenFile *fptr;
+    rb_io_t *fptr;
     struct termios t;
     int tcsetattr_option;
 
@@ -243,7 +253,7 @@
     old = termios_tcgetattr(io);
     GetOpenFile(io, fptr);
     Termios_to_termios(param, &t);
-    if (tcsetattr(fileno(fptr->f), tcsetattr_option, &t) < 0) {
+    if (tcsetattr(FPTR_TO_FD(fptr), tcsetattr_option, &t) < 0) {
 	rb_raise(rb_eRuntimeError,
 		 "can't set terminal parameters (%s)", strerror(errno));
     }
@@ -262,13 +272,13 @@
 termios_tcsendbreak(io, duration)
     VALUE io, duration;
 {
-    OpenFile *fptr;
+    rb_io_t *fptr;
 
     Check_Type(io,       T_FILE);
     Check_Type(duration, T_FIXNUM);
 
     GetOpenFile(io, fptr);
-    if (tcsendbreak(fileno(fptr->f), FIX2INT(duration)) < 0) {
+    if (tcsendbreak(FPTR_TO_FD(fptr), FIX2INT(duration)) < 0) {
 	rb_raise(rb_eRuntimeError, 
 		 "can't transmits break (%s)", strerror(errno));
     }
@@ -287,12 +297,12 @@
 termios_tcdrain(io)
     VALUE io;
 {
-    OpenFile *fptr;
+    rb_io_t *fptr;
 
     Check_Type(io, T_FILE);
 
     GetOpenFile(io, fptr);
-    if (tcdrain(fileno(fptr->f)) < 0) {
+    if (tcdrain(FPTR_TO_FD(fptr)) < 0) {
 	rb_raise(rb_eRuntimeError, "can't drain (%s)", strerror(errno));
     }
 
@@ -310,7 +320,7 @@
 termios_tcflush(io, qs)
     VALUE io, qs;
 {
-    OpenFile *fptr;
+    rb_io_t *fptr;
     int queue_selector;
 
     Check_Type(io, T_FILE);
@@ -322,7 +332,7 @@
     }
 
     GetOpenFile(io, fptr);
-    if (tcflush(fileno(fptr->f), queue_selector) < 0) {
+    if (tcflush(FPTR_TO_FD(fptr), queue_selector) < 0) {
 	rb_raise(rb_eRuntimeError, "can't flush (%s)", strerror(errno));
     }
 
@@ -340,7 +350,7 @@
 termios_tcflow(io, act)
     VALUE io, act;
 {
-    OpenFile *fptr;
+    rb_io_t *fptr;
     int action;
 
     Check_Type(io,  T_FILE);
@@ -352,7 +362,7 @@
     }
 
     GetOpenFile(io, fptr);
-    if (tcflow(fileno(fptr->f), action) < 0) {
+    if (tcflow(FPTR_TO_FD(fptr), action) < 0) {
 	rb_raise(rb_eRuntimeError, 
 		 "can't control transmitting data flow (%s)", strerror(errno));
     }
@@ -371,12 +381,12 @@
 termios_tcgetpgrp(io)
     VALUE io;
 {
-    OpenFile *fptr;
+    rb_io_t *fptr;
     int pid;
 
     Check_Type(io,  T_FILE);
     GetOpenFile(io, fptr);
-    if ((pid = tcgetpgrp(fileno(fptr->f))) < 0) {
+    if ((pid = tcgetpgrp(FPTR_TO_FD(fptr))) < 0) {
 	rb_raise(rb_eRuntimeError, 
 		 "can't get process group id (%s)", strerror(errno));
     }
@@ -395,13 +405,13 @@
 termios_tcsetpgrp(io, pgrpid)
     VALUE io, pgrpid;
 {
-    OpenFile *fptr;
+    rb_io_t *fptr;
 
     Check_Type(io,     T_FILE);
     Check_Type(pgrpid, T_FIXNUM);
 
     GetOpenFile(io, fptr);
-    if (tcsetpgrp(fileno(fptr->f), FIX2INT(pgrpid)) < 0) {
+    if (tcsetpgrp(FPTR_TO_FD(fptr), FIX2INT(pgrpid)) < 0) {
 	rb_raise(rb_eRuntimeError, 
 		 "can't set process group id (%s)", strerror(errno));
     }
