1989-05-30 13:34:25 +00:00
|
|
|
/*
|
1989-06-26 10:37:05 +00:00
|
|
|
* ungetc.c - push a character back onto an input stream
|
1989-05-30 13:34:25 +00:00
|
|
|
*/
|
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "loc_incl.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
ungetc(int ch, FILE *stream)
|
|
|
|
{
|
|
|
|
unsigned char *p;
|
|
|
|
|
1989-06-26 10:37:05 +00:00
|
|
|
if (ch == EOF || !io_testflag(stream,_IOREADING))
|
1989-05-30 13:34:25 +00:00
|
|
|
return EOF;
|
|
|
|
if (stream->_ptr == stream->_buf) {
|
|
|
|
if (stream->_count != 0) return EOF;
|
|
|
|
stream->_ptr++;
|
|
|
|
}
|
|
|
|
stream->_count++;
|
1989-06-26 10:37:05 +00:00
|
|
|
p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */
|
1989-05-30 13:34:25 +00:00
|
|
|
*p = (unsigned char) ch;
|
|
|
|
return ch;
|
|
|
|
}
|