compiler/clib: Rename IoErr2errno() to __arosc_ioerr2errno(); function is now defined...
[AROS.git] / compiler / clib / ungetc.c
blob48083a936300748497a17bd9be891e01f90648e0
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C 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"
15 /*****************************************************************************
17 NAME */
18 #include <stdio.h>
20 int ungetc (
22 /* SYNOPSIS */
23 int c,
24 FILE * stream)
26 /* FUNCTION
27 Push the character c character back into the stream.
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
38 RESULT
39 c or EOF on error.
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 fgetc(), getc(), fputc(), putc()
50 INTERNALS
52 ******************************************************************************/
54 fdesc *fdesc = __getfdesc(stream->fd);
56 if (!fdesc)
58 stream->flags |= _STDIO_ERROR;
59 errno = EBADF;
60 return EOF;
63 /* Note: changes here might require changes in vfscanf.c!! */
65 if (c < -1)
66 c = (unsigned int)c;
68 if (!UnGetC ((BPTR)fdesc->fcb->fh, c))
70 errno = __arosc_ioerr2errno (IoErr ());
72 if (errno)
73 stream->flags |= _STDIO_ERROR;
74 else
75 stream->flags |= _STDIO_EOF;
77 c = EOF;
80 return c;
81 } /* ungetc */