syswrite(p1)
public
Writes the given string to ios using a low-level write. Returns the number of bytes written. Do not mix with other methods that
write to ios or you may get
unpredictable results. Raises SystemCallError on error.
f = File.new("out", "w")
f.syswrite("ABCDEF")
Show source
static VALUE
rb_io_syswrite(VALUE io, VALUE str)
{
rb_io_t *fptr;
long n;
rb_secure(4);
if (TYPE(str) != T_STRING)
str = rb_obj_as_string(str);
io = GetWriteIO(io);
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
if (fptr->wbuf.len) {
rb_warn("syswrite for buffered IO");
}
if (!rb_thread_fd_writable(fptr->fd)) {
rb_io_check_closed(fptr);
}
n = rb_write_internal(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
if (n == -1) rb_sys_fail_path(fptr->pathv);
return LONG2FIX(n);
}