truncate(p1)
public
Truncates the buffer string to at most
integer bytes. The strio
must be opened for writing.
Show source
static VALUE
strio_truncate(VALUE self, VALUE len)
{
VALUE string = writable(StringIO(self))->string;
long l = NUM2LONG(len);
long plen = RSTRING_LEN(string);
if (l < 0) {
error_inval("negative legnth");
}
rb_str_resize(string, l);
if (plen < l) {
MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
}
return len;
}