ack/lang/cem/libcc.ansi/stdio/ungetc.c

27 lines
537 B
C
Raw Normal View History

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
#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 !!! */
1990-03-28 16:33:05 +00:00
/* ungetc() in sscanf() shouldn't write in rom */
if (*p != (unsigned char) ch)
*p = (unsigned char) ch;
1989-05-30 13:34:25 +00:00
return ch;
}