getbyte()
public
Gets the next 8-bit byte (0..255) from ios. Returns nil
if called at end of file.
f = File.new("testfile")
f.getc
f.getc
Show source
/*
* 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;
{
rb_io_t *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);
}