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
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015年06月06日 18:11:17 +0000
committerRich Felker <dalias@aerifal.cx>2015年06月06日 18:11:17 +0000
commit7e816a6487932cbb3cb71d94b609e50e81f4e5bf (patch)
tree3742adde5771700ba3ca39682b5105e518e87e82 /src/stdio/ungetwc.c
parent63f4b9f18f3674124d8bcb119739fec85e6da005 (diff)
downloadmusl-7e816a6487932cbb3cb71d94b609e50e81f4e5bf.tar.gz
remove invalid skip of locking in ungetwc
aside from being invalid, the early check only optimized the error case, and likely pessimized the common case by separating the two branches on isascii(c) at opposite ends of the function.
Diffstat (limited to 'src/stdio/ungetwc.c')
-rw-r--r--src/stdio/ungetwc.c 9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c
index 913f7168..0a4cd7a1 100644
--- a/src/stdio/ungetwc.c
+++ b/src/stdio/ungetwc.c
@@ -11,18 +11,15 @@ wint_t ungetwc(wint_t c, FILE *f)
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->rpos) __toread(f);
- if (!f->rpos || f->rpos < f->buf - UNGET + l) {
+ if (!f->rpos || f->rpos < f->buf - UNGET + l ||
+ (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0)) {
FUNLOCK(f);
- return EOF;
+ return WEOF;
}
if (isascii(c)) *--f->rpos = c;
generated by cgit v1.2.1 (git 2.18.0) at 2025年10月03日 14:01:05 +0000

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