ack/lang/cem/libcc.ansi/sys/stdio/ungetc.c
David Given 9109d7af7f First stage in modularising FILE*. Refactor so that printf/scanf don't rely on
FILE* innards; allow plats to replace the entire emulated FILE* system.
2019-06-15 13:07:10 +02:00

32 lines
600 B
C

/*
* ungetc.c - push a character back onto an input stream
*/
/* $Id$ */
#include <stdio.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE
int ungetc(int ch, FILE* stream)
{
unsigned char* p;
if (ch == EOF || !io_testflag(stream, _IOREADING))
return EOF;
if (stream->_ptr == stream->_buf)
{
if (stream->_count != 0)
return EOF;
stream->_ptr++;
}
stream->_count++;
p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */
/* ungetc() in sscanf() shouldn't write in rom */
if (*p != (unsigned char)ch)
*p = (unsigned char)ch;
return ch;
}
#endif