1 #include "stdio_impl.h"
3 wint_t ungetwc(wint_t c, FILE *f)
5 unsigned char mbc[MB_LEN_MAX];
8 if (c == WEOF) return c;
10 /* Try conversion early so we can fail without locking if invalid */
11 if (!isascii(c) && (l = wctomb(mbc, c)) < 0)
18 /* Fail if unreadable or writing and unable to flush */
19 if ((f->flags & (F_ERR|F_NORD)) || (f->wpos && __oflow(f))) {
24 /* Clear write mode */
25 f->wpos = f->wstop = f->wend = 0;
27 /* Put the file in read mode */
28 if (!f->rpos) f->rpos = f->rend = f->buf;
30 /* If unget buffer is nonempty, fail. */
31 if (f->rpos < f->buf) {
36 /* Put character back into the buffer */
37 if (isascii(c)) *--f->rpos = c;
38 else memcpy(f->rpos -= l, mbc, l);