sysseek(p1, p2 = v2)
public
Seeks to a given offset in the stream according to the value of
whence (see IO#seek for values of
whence). Returns the new offset
into the file.
f = File.new("testfile")
f.sysseek(-13, IO::SEEK_END)
f.sysread(10)
Show source
static VALUE
rb_io_sysseek(int argc, VALUE *argv, VALUE io)
{
VALUE offset, ptrname;
int whence = SEEK_SET;
rb_io_t *fptr;
off_t pos;
if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
whence = NUM2INT(ptrname);
}
pos = NUM2OFFT(offset);
GetOpenFile(io, fptr);
if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr)) {
rb_raise(rb_eIOError, "sysseek for buffered IO");
}
if ((fptr->mode & FMODE_WRITABLE) && fptr->wbuf_len) {
rb_warn("sysseek for buffered IO");
}
pos = lseek(fptr->fd, pos, whence);
if (pos == -1) rb_sys_fail_path(fptr->pathv);
return OFFT2NUM(pos);
}