Created
March 10, 2009 17:04
-
-
Save patrickt/76998 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, VALUE str) | |
{ | |
rb_io_t *fptr; | |
long n; | |
VALUE tmp; | |
rb_secure(4); | |
io = GetWriteIO(io); | |
str = rb_obj_as_string(str); | |
tmp = rb_io_check_io(io); | |
if (NIL_P(tmp)) { | |
/* port is not IO, call write method for it. */ | |
return rb_funcall(io, id_write, 1, str); | |
} | |
io = tmp; | |
if (RSTRING_LEN(str) == 0) return INT2FIX(0); | |
GetOpenFile(io, fptr); | |
rb_io_check_writable(fptr); | |
n = io_fwrite(str, fptr); | |
if (n == -1L) rb_sys_fail(fptr->path); | |
return LONG2FIX(n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment