Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / stdio / ungetc.c
1 /*
2  * ungetc.c - push a character back onto an input stream
3  */
4 /* $Id: ungetc.c,v 1.4 1994/06/24 11:51:56 ceriel Exp $ */
5
6 #include        <stdio.h>
7 #include        "loc_incl.h"
8
9 int
10 ungetc(int ch, FILE *stream)
11 {
12         unsigned char *p;
13
14         if (ch == EOF  || !io_testflag(stream,_IOREADING))
15                 return EOF;
16         if (stream->_ptr == stream->_buf) {
17                 if (stream->_count != 0) return EOF;
18                 stream->_ptr++;
19         }
20         stream->_count++;
21         p = --(stream->_ptr);           /* ??? Bloody vax assembler !!! */
22         /* ungetc() in sscanf() shouldn't write in rom */
23         if (*p != (unsigned char) ch)
24                 *p = (unsigned char) ch;
25         return ch;
26 }