Fixed compatibility of output.
[AROS.git] / compiler / posixc / ungetc.c
blobc1e32ac7f2beb7c0f3c8f2b4ac84219c77e51ebb
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function ungetc().
6 */
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 "__fdesc.h"
14 #include "__stdio.h"
16 /*****************************************************************************
18 NAME */
19 #include <stdio.h>
21 int ungetc (
23 /* SYNOPSIS */
24 int c,
25 FILE * stream)
27 /* FUNCTION
28 Push the character c character back into the stream.
30 INPUTS
31 c - Put this character back into the stream. The next read will
32 return this character. If you push back more than one
33 character, then they will be returned in reverse order.
34 The function gurantees that one character can be
35 pushed back but no more. It is possible to push the EOF
36 character back into the stream.
37 stream - Read from this stream
39 RESULT
40 c or EOF on error.
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
49 fgetc(), getc(), fputc(), putc()
51 INTERNALS
53 ******************************************************************************/
55 fdesc *fdesc = __getfdesc(stream->fd);
57 if (!fdesc)
59 stream->flags |= __POSIXC_STDIO_ERROR;
60 errno = EBADF;
61 return EOF;
64 /* Note: changes here might require changes in vfscanf.c!! */
66 if (c < -1)
67 c = (unsigned int)c;
69 if (!UnGetC (fdesc->fcb->handle, c))
71 errno = __stdc_ioerr2errno (IoErr ());
73 if (errno)
74 stream->flags |= __POSIXC_STDIO_ERROR;
75 else
76 stream->flags |= __POSIXC_STDIO_EOF;
78 c = EOF;
81 return c;
82 } /* ungetc */