netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / ungetwc.c
blob25b12b8871532c1cbc83bc61c2fe5c7751c6298a
1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
8 #include "_stdio.h"
10 /* Note: This is the application-callable ungetwc. If wscanf calls this, it
11 * should also set stream->__ungot[1] to 0 if this is the only ungot, as well
12 * as reset stream->__ungot_width[1] for use by _stdio_adjpos().
15 wint_t ungetwc(wint_t c, register FILE *stream)
17 __STDIO_AUTO_THREADLOCK_VAR;
19 __STDIO_AUTO_THREADLOCK(stream);
20 __STDIO_STREAM_VALIDATE(stream); /* debugging only */
22 /* Note: Even if c == WEOF, we need to initialize/verify the
23 * stream's orientation and ensure the stream is in reading
24 * mode (if readable and properly oriented). */
25 if ((!__STDIO_STREAM_IS_WIDE_READING(stream)
26 && __STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_WIDE))
27 || ((stream->__modeflags & __FLAG_UNGOT)
28 && ((stream->__modeflags & 1) || stream->__ungot[1]))
29 || (c == WEOF)
30 ) {
31 c = WEOF;
32 } else {
33 /* In the wide case, getc macros should already be disabled. */
34 /* __STDIO_STREAM_DISABLE_GETC(stream); */
36 /* Flag this as a user ungot, as scanf does the necessary fixup. */
37 stream->__ungot[1] = 1;
38 stream->__ungot[(++stream->__modeflags) & 1] = c;
39 /* Note: ungot_width is handled by fgetwc. */
41 __STDIO_STREAM_CLEAR_EOF(stream); /* Must clear end-of-file flag. */
44 __STDIO_STREAM_VALIDATE(stream);
45 __STDIO_AUTO_THREADUNLOCK(stream);
47 return c;
49 libc_hidden_def(ungetwc)