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);

}

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?

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

  Returns an integer representing the numeric file descriptor for
  ios.

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


  (also known as to_i)

Wayne E. Seguin wrote:

Wayne E. Seguin
Sr. Systems Architect & Systems Administrator

Check the GetOpenFile macro in rubyio.h.

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

{
OpenFile *fptr;
int fd;

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

}

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:30 , Tim H. wrote:

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

Check the GetOpenFile macro in rubyio.h.

Thank you Tim! Most helpful.

~Wayne

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