Created
March 10, 2009 17:03
-
-
Save patrickt/76994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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