about summary refs log tree commit homepage
path: root/ext/kgio/my_fileno.h
diff options
context:
space:
mode:
Diffstat (limited to 'ext/kgio/my_fileno.h')
-rw-r--r--ext/kgio/my_fileno.h32
1 files changed, 5 insertions, 27 deletions
diff --git a/ext/kgio/my_fileno.h b/ext/kgio/my_fileno.h
index d9bda3c..6dbd083 100644
--- a/ext/kgio/my_fileno.h
+++ b/ext/kgio/my_fileno.h
@@ -1,30 +1,11 @@
 #include <ruby.h>
-#ifdef HAVE_RUBY_IO_H
-#  include <ruby/io.h>
-#else
-#  include <stdio.h>
-#  include <rubyio.h>
-#endif
-
-#if ! HAVE_RB_IO_T
-#  define rb_io_t OpenFile
-#endif
-
-#ifdef GetReadFile
-#  define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr)))
-#else
-#  if !HAVE_RB_IO_T || (RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8)
-#    define FPTR_TO_FD(fptr) fileno(fptr->f)
-#  else
-#    define FPTR_TO_FD(fptr) fptr->fd
-#  endif
-#endif
+#include <ruby/io.h>
 
 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");
+                io = rb_io_get_io(io);
 
         return rb_io_descriptor(io);
 #else
@@ -32,12 +13,9 @@ static int my_fileno(VALUE io)
         int fd;
 
         if (TYPE(io) != T_FILE)
-                io = rb_convert_type(io, T_FILE, "IO", "to_io");
+                io = rb_io_get_io(io);
         GetOpenFile(io, fptr);
-        fd = FPTR_TO_FD(fptr);
-
-        if (fd < 0)
-                rb_raise(rb_eIOError, "closed stream");
-        return fd;
+        rb_io_check_closed(fptr);
+        return fptr->fd;
 #endif
 }