Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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