>>>>> "B" == Brett W Denner <Brett.W.Denner / lmco.com> writes:

B> I need to write a Ruby extension which reads binary data from a C FILE
B> pointer (using
B> fread) which corresponds to a Ruby File object.  In other words, I want to
B> use
B> File.new inside Ruby, then pass the file descriptor into a C function which
B> reads from
B> the file I opened in Ruby.

 Look at ruby.h

pigeon% less ruby.h
[...]
struct RFile {
    struct RBasic basic;
    struct OpenFile *fptr;
};
[...]
pigeon%

 Now in rubyio.h

pigeon% less rubyio.h
[...]
typedef struct OpenFile {
    FILE *f;                    /* stdio ptr for read/write */
    FILE *f2;                   /* additional ptr for rw pipes */
    int mode;                   /* mode flags */
    int pid;                    /* child's pid (for pipes) */
    int lineno;                 /* number of lines read */
    char *path;                 /* pathname for file */
    void (*finalize)();         /* finalize proc */
} OpenFile;
[...]
pigeon%

 This mean that in your C program, you can write

 FILE *fd = RFILE(io)->fptr->f;

 where `io' is the object created by File::new



Guy Decoux