manual page distributed with 4.2BSD
[unix-history] / usr / src / lib / libc / stdio / ungetc.c
CommitLineData
41e01b3e 1/* ungetc.c 4.3 85/02/13 */
bec69c1e 2
52dc310d
BJ
3#include <stdio.h>
4
5ungetc(c, iop)
bec69c1e 6 register FILE *iop;
52dc310d 7{
41e01b3e
S
8 if (c == EOF || (iop->_flag & (_IOREAD|_IORW)) == 0 ||
9 iop->_ptr == NULL || iop->_base == NULL)
10 return (EOF);
11
12 if (iop->_ptr == iop->_base)
13 iop->_ptr++;
14
52dc310d
BJ
15 iop->_cnt++;
16 *--iop->_ptr = c;
41e01b3e 17
bec69c1e 18 return (c);
52dc310d 19}