Can I write to a File object from a C extension?

T

Tim Hunter

I have a function written in C that wants to write to a FILE *
returned from fopen. I'd like to use this function to write to a File
object that has been opened for output by File.open().

Is this possible? If so, how?
 
W

why the lucky stiff

I have a function written in C that wants to write to a FILE *
returned from fopen. I'd like to use this function to write to a File
object that has been opened for output by File.open().

Is this possible? If so, how?

Poke around in rubyio.h and you'll find some macros and functions pertinent to
this.

VALUE rubyFilePtr;
OpenFile *openFilePtr;
FILE *cFilePtr;

rubyFile = rb_file_open( 'filename', 'rw' );
GetOpenFile(rubyFilePtr, openFilePtr);
rb_io_check_writable(openFilePtr);
cFilePtr = GetWriteFile(openFilePtr);

_why
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top