public Method

IO.getc

ios.getc    fixnum or nil

Gets the next 8-bit byte (0..255) from ios. Returns nil if called at end of file.

f = File.new("testfile")
f.getc   #=> 84
f.getc   #=> 104

Source Code

/*
*  call-seq:
*     ios.getc   => fixnum or nil
*  
*  Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
*  <code>nil</code> if called at end of file.
*     
*     f = File.new("testfile")
*     f.getc   #=> 84
*     f.getc   #=> 104
*/

VALUE
rb_io_getc(io)
   VALUE io;
{
   OpenFile *fptr;
   FILE *f;
   int c;

   GetOpenFile(io, fptr);
   rb_io_check_readable(fptr);
   f = fptr->f;

 retry:
   READ_CHECK(f);
   clearerr(f);
   TRAP_BEG;
   c = getc(f);
   TRAP_END;

   if (c == EOF) {
       if (ferror(f)) {
           clearerr(f);
           if (!rb_io_wait_readable(fileno(f)))
               rb_sys_fail(fptr->path);
           goto retry;
       }
       return Qnil;
   }
   return INT2FIX(c & 0xff);
}
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.