Skip to content

Instantly share code, notes, and snippets.

@patrickt
Created March 10, 2009 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickt/76994 to your computer and use it in GitHub Desktop.
Save patrickt/76994 to your computer and use it in GitHub Desktop.
static VALUE
io_write(VALUE io, SEL sel, VALUE to_write)
{
rb_io_t *io_struct;
VALUE to_write;
UInt8 *buffer;
CFIndex length;
rb_secure(4);
io_struct = ExtractIOStruct(io);
rb_io_assert_writable(io_struct);
// TODO: Account for the port not being IO, use funcall to call .write()
// instead.
to_write = rb_obj_as_string(to_write);
buffer = (UInt8*)rb_str_byteptr(to_write);
length = (CFIndex)rb_str_bytelen(to_write);
if(length == 0) {
return INT2FIX(0);
}
return LONG2FIX(CFWriteStreamWrite(io_struct->writeStream, buffer, length));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment