xref: /csrg-svn/lib/libc/stdio/ungetc.c (revision 15084)
1 /*	ungetc.c	4.2	83/09/25	*/
2 
3 #include <stdio.h>
4 
5 ungetc(c, iop)
6 	register FILE *iop;
7 {
8 	if (c == EOF)
9 		return (-1);
10 	if ((iop->_flag&_IOREAD) == 0 || iop->_ptr <= iop->_base)
11 		if (iop->_ptr == iop->_base && iop->_cnt == 0)
12 			*iop->_ptr++;
13 		else
14 			return (EOF);
15 	iop->_cnt++;
16 	*--iop->_ptr = c;
17 	return (c);
18 }
19