home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / update~4.z / update~4 / lib_stdio_ungetc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  859 b   |  36 lines

  1. /*                u n g e t c
  2.  *
  3.  * This function pushes a character back into an input stream. The
  4.  * character will be returned by the next getc call on the stream.
  5.  * One character of pushback is guaranteed provided something
  6.  * is read from the stream.
  7.  *
  8.  * Attempts to pushback EOF will fail and the function will return
  9.  * EOF, otherwise the character pushed back will be returned. EOF
  10.  * will also be returned if the attempt to pushback fails.
  11.  *
  12.  * Patchlevel 1.0
  13.  *
  14.  * Edit History:
  15.  */
  16.  
  17. #include "stdiolib.h"
  18.  
  19. /*LINTLIBRARY*/
  20.  
  21. int ungetc(ch, fp)
  22.  
  23. int ch;                    /* character to push back */
  24. FILE *fp;
  25.  
  26. {
  27.   if (ch == EOF  || TESTFLAG(fp, _IOREAD) == 0 ||
  28.       fp->_base == NULL || (fp->_ptr == fp->_base && ! TESTFLAG(fp, _IONBF)))
  29.     return EOF;
  30.  
  31.   if (TESTFLAG(fp, _IONBF) != 0)
  32.     fp->_ptr = fp->_end = fp->_base + fp->_bufsiz;
  33.  
  34.   return *--fp->_ptr = ch;
  35. }
  36.