fix copy/paste error in popen changes that broke signals
[musl] / src / stdio / ungetwc.c
1 #include "stdio_impl.h"
2
3 wint_t ungetwc(wint_t c, FILE *f)
4 {
5         unsigned char mbc[MB_LEN_MAX];
6         int l=1;
7
8         if (c == WEOF) return c;
9
10         /* Try conversion early so we can fail without locking if invalid */
11         if (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0)
12                 return WEOF;
13
14         FLOCK(f);
15
16         f->mode |= f->mode+1;
17
18         if ((!f->rend && __toread(f)) || f->rpos < f->buf - UNGET + l) {
19                 FUNLOCK(f);
20                 return EOF;
21         }
22
23         if (isascii(c)) *--f->rpos = c;
24         else memcpy(f->rpos -= l, mbc, l);
25
26         f->flags &= ~F_EOF;
27
28         FUNLOCK(f);
29         return c;
30 }