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.getbyte
f.getbyte
Show source
VALUE
rb_io_getbyte(VALUE io)
{
rb_io_t *fptr;
int c;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
READ_CHECK(fptr);
if (fptr->fd == 0 && (fptr->mode & FMODE_TTY) && TYPE(rb_stdout) == T_FILE) {
rb_io_t *ofp;
GetOpenFile(rb_stdout, ofp);
if (ofp->mode & FMODE_TTY) {
rb_io_flush(rb_stdout);
}
}
if (io_fillbuf(fptr) < 0) {
return Qnil;
}
fptr->rbuf_off++;
fptr->rbuf_len--;
c = (unsigned char)fptr->rbuf[fptr->rbuf_off-1];
return INT2FIX(c & 0xff);
}