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
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "loc_incl.h"
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2019-06-15 11:07:10 +00:00
|
|
|
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE
|
2018-06-23 16:54:40 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
int ungetc(int ch, FILE* stream)
|
1989-05-30 13:34:25 +00:00
|
|
|
{
|
2018-06-21 20:33:47 +00:00
|
|
|
unsigned char* p;
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
if (ch == EOF || !io_testflag(stream, _IOREADING))
|
1989-05-30 13:34:25 +00:00
|
|
|
return EOF;
|
2018-06-21 20:33:47 +00:00
|
|
|
if (stream->_ptr == stream->_buf)
|
|
|
|
{
|
|
|
|
if (stream->_count != 0)
|
|
|
|
return EOF;
|
1989-05-30 13:34:25 +00:00
|
|
|
stream->_ptr++;
|
|
|
|
}
|
|
|
|
stream->_count++;
|
2018-06-21 20:33:47 +00:00
|
|
|
p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */
|
1990-03-28 16:33:05 +00:00
|
|
|
/* ungetc() in sscanf() shouldn't write in rom */
|
2018-06-21 20:33:47 +00:00
|
|
|
if (*p != (unsigned char)ch)
|
|
|
|
*p = (unsigned char)ch;
|
1989-05-30 13:34:25 +00:00
|
|
|
return ch;
|
|
|
|
}
|
2018-06-23 16:54:40 +00:00
|
|
|
|
|
|
|
#endif
|