/*
* call-seq:
* ios.ungetc(integer) => nil
*
* Pushes back one character (passed as a parameter) onto <em>ios</em>,
* such that a subsequent buffered read will return it. Only one character
* may be pushed back before a subsequent read operation (that is,
* you will be able to read only the last of several characters that have been pushed
* back). Has no effect with unbuffered reads (such as <code>IO#sysread</code>).
*
* f = File.new("testfile") #=> #<File:testfile>
* c = f.getc #=> 84
* f.ungetc(c) #=> nil
* f.getc #=> 84
*/
VALUE
rb_io_ungetc(io, c)
VALUE io, c;
{
OpenFile *fptr;
int cc = NUM2INT(c);
GetOpenFile(io, fptr);
if (!(fptr->mode & FMODE_RBUF))
rb_raise(rb_eIOError, "unread stream");
rb_io_check_readable(fptr);
if (ungetc(cc, fptr->f) == EOF && cc != EOF) {
rb_raise(rb_eIOError, "ungetc failed");
}
return Qnil;
}