File#file_descriptor

Hopefully someone knows this... I've googled for a while.

When writing a C extension, how does one access the file descriptor of a File object from the C code?

Thanks!

   ~Wayne

s///g
Wayne E. Seguin
Sr. Systems Architect & Systems Administrator

Wayne E. Seguin wrote:

Hopefully someone knows this... I've googled for a while.

When writing a C extension, how does one access the file descriptor of a File object from the C code?

Take a look at this method in io.c:

static VALUE
rb_io_fileno(io)
     VALUE io;
{
     OpenFile *fptr;
     int fd;

     GetOpenFile(io, fptr);
     fd = fileno(fptr->f);
     return INT2FIX(fd);
}

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

$ ri IO#fileno
-------------------------------------------------------------- IO#fileno
      ios.fileno => fixnum
      ios.to_i => fixnum

···

On Sep 11, 2007, at 14:16, Wayne E. Seguin wrote:

Hopefully someone knows this... I've googled for a while.

When writing a C extension, how does one access the file descriptor of a File object from the C code?

------------------------------------------------------------------------
      Returns an integer representing the numeric file descriptor for
      ios.

         $stdin.fileno #=> 0
         $stdout.fileno #=> 1

      (also known as to_i)

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars

Wayne E. Seguin wrote:

Hopefully someone knows this... I've googled for a while.

When writing a C extension, how does one access the file descriptor of a File object from the C code?

Thanks!

  ~Wayne

s///g
Wayne E. Seguin
Sr. Systems Architect & Systems Administrator

Check the GetOpenFile macro in rubyio.h.

···

--
RMagick OS X Installer [http://rubyforge.org/projects/rmagick/\]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618\]
RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html\]

Joel,

Awesome, this is exactly what I was looking for!

Thank you!

   ~Wayne

s///g
Wayne E. Seguin
Sr. Systems Architect & Systems Administrator

···

On Sep 11, 2007, at 17:26 , Joel VanderWerf wrote:

Wayne E. Seguin wrote:

Hopefully someone knows this... I've googled for a while.
When writing a C extension, how does one access the file descriptor of a File object from the C code?

Take a look at this method in io.c:

static VALUE
rb_io_fileno(io)
    VALUE io;
{
    OpenFile *fptr;
    int fd;

    GetOpenFile(io, fptr);
    fd = fileno(fptr->f);
    return INT2FIX(fd);
}

Thank you Tim! Most helpful.

   ~Wayne

s///g
Wayne E. Seguin
Sr. Systems Architect & Systems Administrator

···

On Sep 11, 2007, at 17:30 , Tim Hunter wrote:

Wayne E. Seguin wrote:

Hopefully someone knows this... I've googled for a while.

When writing a C extension, how does one access the file descriptor of a File object from the C code?

Thanks!

  ~Wayne

s///g
Wayne E. Seguin
Sr. Systems Architect & Systems Administrator

Check the GetOpenFile macro in rubyio.h.