public Method

IO.pos=(p1)

ios.pos = integer     integer

Seeks to the given position (in bytes) in ios.

f = File.new("testfile")
f.pos = 17
f.gets   #=> "This is line two\n"

Source Code

/*
*  call-seq:
*     ios.pos = integer    => integer
*  
*  Seeks to the given position (in bytes) in <em>ios</em>.
*     
*     f = File.new("testfile")
*     f.pos = 17
*     f.gets   #=> "This is line two\n"
*/

static VALUE
rb_io_set_pos(io, offset)
    VALUE io, offset;
{
   OpenFile *fptr;
   off_t pos;

   pos = NUM2OFFT(offset);
   GetOpenFile(io, fptr);
   pos = io_seek(fptr, pos, SEEK_SET);
   if (pos != 0) rb_sys_fail(fptr->path);
   clearerr(fptr->f);

   return OFFT2NUM(pos);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.