home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / ungetc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-28  |  1.6 KB  |  93 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: ungetc.c,v 1.2 1997/01/28 15:32:34 digulla Exp $
  4.  
  5.     Desc: ANSI C function ungetc()
  6.     Lang: english
  7. */
  8. #include <errno.h>
  9. #include <dos/dos.h>
  10. #include <dos/dosextens.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include "__errno.h"
  14.  
  15. /*****************************************************************************
  16.  
  17.     NAME */
  18. #include <stdio.h>
  19.  
  20.     int ungetc (
  21.  
  22. /*  SYNOPSIS */
  23.     int    c,
  24.     FILE * stream)
  25.  
  26. /*  FUNCTION
  27.     Puch the character c character back into the stream.
  28.  
  29.     INPUTS
  30.     c - Put this character back into the stream. The next read will
  31.         return this character. If you push back more than one
  32.         character, then they will be returned in reverse order.
  33.         The function gurantees that one character can be
  34.         pushed back but no more. It is possible to push the EOF
  35.         character back into the stream.
  36.     stream - Read from this stream
  37.  
  38.     RESULT
  39.     c or EOF on error.
  40.  
  41.     NOTES
  42.  
  43.     EXAMPLE
  44.  
  45.     BUGS
  46.  
  47.     SEE ALSO
  48.     fgetc(), getc(), fputc(), putc()
  49.  
  50.     INTERNALS
  51.  
  52.     HISTORY
  53.     10.12.1996 digulla created
  54.  
  55. ******************************************************************************/
  56. {
  57.     BPTR fh;
  58.  
  59.     switch ((IPTR)stream)
  60.     {
  61.     case 1: /* Stdin */
  62.     fh = Input ();
  63.     break;
  64.  
  65.     case 2: /* Stdout */
  66.     case 3: /* Stderr */
  67.     errno = EINVAL;
  68.     return EOF;
  69.  
  70.     default:
  71.     fh = (BPTR)stream->fh;
  72.     break;
  73.     }
  74.  
  75.     if (c < -1)
  76.     c = (unsigned int)c;
  77.  
  78.     if (!UnGetC (fh, c))
  79.     {
  80.     errno = IoErr2errno (IoErr ());
  81.  
  82.     if (errno)
  83.         stream->flags |= _STDIO_FILEFLAG_ERROR;
  84.     else
  85.         stream->flags |= _STDIO_FILEFLAG_EOF;
  86.  
  87.     return EOF;
  88.     }
  89.  
  90.     return c;
  91. } /* ungetc */
  92.  
  93.