126665Sdonn #if defined(LIBC_SCCS) && !defined(lint) 2*26938Sbloom static char sccsid[] = "@(#)ungetc.c 5.3 (Berkeley) 03/26/86"; 326665Sdonn #endif LIBC_SCCS and not lint 415084Ssam 52037Swnj #include <stdio.h> 62037Swnj 72037Swnj ungetc(c, iop) 815084Ssam register FILE *iop; 92037Swnj { 1017951Sserge if (c == EOF || (iop->_flag & (_IOREAD|_IORW)) == 0 || 1117951Sserge iop->_ptr == NULL || iop->_base == NULL) 1217951Sserge return (EOF); 1317951Sserge 1417951Sserge if (iop->_ptr == iop->_base) 15*26938Sbloom if (iop->_cnt == 0) 16*26938Sbloom iop->_ptr++; 17*26938Sbloom else 18*26938Sbloom return (EOF); 1917951Sserge 202037Swnj iop->_cnt++; 212037Swnj *--iop->_ptr = c; 2217951Sserge 2315084Ssam return (c); 242037Swnj } 25