ungetwc.c\stdio\src - musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/stdio/ungetwc.c
blob: 8cc85a6bfd2a00b615ecccdc96fbfc519e4b77f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "stdio_impl.h"
#include <wchar.h>
#include <limits.h>
#include <ctype.h>
#include <string.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;
}
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月25日 20:16:33 +0000

AltStyle によって変換されたページ (->オリジナル) /