Method: OCI8::LOB#seek
- Defined in:
- ext/oci8/lob.c
#seek(amount, whence = IO::SEEK_SET) ⇒ self
Seeks to the given offset in the stream. The new position, measured in characters, is obtained by adding offset amount to the position specified by whence. If whence is set to IO::SEEK_SET, IO::SEEK_CUR, or IO::SEEK_END, the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively.
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'ext/oci8/lob.c', line 519
static VALUE oci8_lob_seek(int argc, VALUE *argv, VALUE self)
{
oci8_lob_t *lob = TO_LOB(self);
VALUE position, whence;
rb_scan_args(argc, argv, "11", &position, &whence);
if (argc == 2 && (whence != seek_set && whence != seek_cur && whence != seek_end)) {
if (FIXNUM_P(whence)) {
rb_raise(rb_eArgError, "expect IO::SEEK_SET, IO::SEEK_CUR or IO::SEEK_END but %d",
FIX2INT(whence));
} else {
rb_raise(rb_eArgError, "expect IO::SEEK_SET, IO::SEEK_CUR or IO::SEEK_END but %s",
rb_class2name(CLASS_OF(whence)));
}
}
if (whence == seek_cur) {
position = rb_funcall(ULL2NUM(lob->pos), id_plus, 1, position);
} else if (whence == seek_end) {
position = rb_funcall(ULL2NUM(oci8_lob_get_length(lob)), id_plus, 1, position);
}
lob->pos = NUM2ULL(position);
return self;
}
|