home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdio / ungetc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-12  |  575 b   |  33 lines

  1. /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  2. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  3. #include <stdio.h>
  4. #include <libc/file.h>
  5.  
  6. int
  7. ungetc(int c, FILE *f)
  8. {
  9.   if (c == EOF
  10.       || (f->_flag & (_IOREAD|_IORW)) == 0
  11.       || f->_ptr == NULL
  12.       || f->_base == NULL)
  13.     return EOF;
  14.  
  15.   if (f->_ptr == f->_base)
  16.   {
  17.     if (f->_cnt == 0)
  18.       f->_ptr++;
  19.     else
  20.       return EOF;
  21.   }
  22.  
  23.   f->_cnt++;
  24.   f->_ptr--;
  25.   if(*f->_ptr != c)
  26.   {
  27.     f->_flag |= _IOUNGETC;
  28.     *f->_ptr = c;
  29.   }
  30.  
  31.   return c;
  32. }
  33.