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
/*
* call-seq:
* ios.syswrite(string) => integer
*
* Writes the given string to <em>ios</em> using a low-level write.
* Returns the number of bytes written. Do not mix with other methods
* that write to <em>ios</em> or you may get unpredictable results.
* Raises <code>SystemCallError</code> on error.
*
* f = File.new("out", "w")
* f.syswrite("ABCDEF")
*/
static VALUE
rb_io_syswrite(io, str)
VALUE io, str;
{
OpenFile *fptr;
FILE *f;
long n;
rb_secure(4);
if (TYPE(str) != T_STRING)
str = rb_obj_as_string(str);
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
if (fptr->mode & FMODE_WBUF) {
rb_warn("syswrite for buffered IO");
}
if (!rb_thread_fd_writable(fileno(f))) {
rb_io_check_closed(fptr);
}
TRAP_BEG;
n = write(fileno(f), RSTRING(str)->ptr, RSTRING(str)->len);
TRAP_END;
if (n == -1) rb_sys_fail(fptr->path);
return LONG2FIX(n);
}