about summary refs log tree commit homepage
path: root/ext/raindrops/my_fileno.h
diff options
context:
space:
mode:
Diffstat (limited to 'ext/raindrops/my_fileno.h')
-rw-r--r--ext/raindrops/my_fileno.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/ext/raindrops/my_fileno.h b/ext/raindrops/my_fileno.h
index 4c8ffba..00c5d29 100644
--- a/ext/raindrops/my_fileno.h
+++ b/ext/raindrops/my_fileno.h
@@ -3,6 +3,12 @@
 
 static int my_fileno(VALUE io)
 {
+#ifdef HAVE_RB_IO_DESCRIPTOR
+        if (TYPE(io) != T_FILE)
+                io = rb_convert_type(io, T_FILE, "IO", "to_io");
+
+        return rb_io_descriptor(io);
+#else
         rb_io_t *fptr;
 
         if (TYPE(io) != T_FILE)
@@ -12,4 +18,5 @@ static int my_fileno(VALUE io)
         if (fptr->fd < 0)
                 rb_raise(rb_eIOError, "closed stream");
         return fptr->fd;
+#endif
 }