mirror of https://git.musl-libc.org/git/musl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
523 B
30 lines
523 B
#include "stdio_impl.h"
|
|
|
|
wint_t ungetwc(wint_t c, FILE *f)
|
|
{
|
|
unsigned char mbc[MB_LEN_MAX];
|
|
int l=1;
|
|
|
|
if (c == WEOF) return c;
|
|
|
|
/* Try conversion early so we can fail without locking if invalid */
|
|
if (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0)
|
|
return WEOF;
|
|
|
|
FLOCK(f);
|
|
|
|
f->mode |= f->mode+1;
|
|
|
|
if ((!f->rend && __toread(f)) || f->rpos < f->buf - UNGET + l) {
|
|
FUNLOCK(f);
|
|
return EOF;
|
|
}
|
|
|
|
if (isascii(c)) *--f->rpos = c;
|
|
else memcpy(f->rpos -= l, mbc, l);
|
|
|
|
f->flags &= ~F_EOF;
|
|
|
|
FUNLOCK(f);
|
|
return c;
|
|
}
|
|
|