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