seek(p1, p2 = v2)
public
Seeks to a given offset amount in the stream according to the
value of whence (see IO#seek).
Show source
static VALUE
strio_seek(int argc, VALUE *argv, VALUE self)
{
VALUE whence;
struct StringIO *ptr = StringIO(self);
long offset;
rb_scan_args(argc, argv, "11", NULL, &whence);
offset = NUM2LONG(argv[0]);
if (CLOSED(ptr)) {
rb_raise(rb_eIOError, "closed stream");
}
switch (NIL_P(whence) ? 0 : NUM2LONG(whence)) {
case 0:
break;
case 1:
offset += ptr->pos;
break;
case 2:
offset += RSTRING_LEN(ptr->string);
break;
default:
error_inval("invalid whence");
}
if (offset < 0) {
error_inval(0);
}
ptr->pos = offset;
return INT2FIX(0);
}