summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/ungetwc.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-09-20 13:23:26 +0000
committertjr <tjr@FreeBSD.org>2002-09-20 13:23:26 +0000
commitff2a681918f0536be0bd28669d15a78b8d1ed571 (patch)
tree29cc23ea2809c3db0cbb1a8f6c811b4e86954c53 /lib/libc/stdio/ungetwc.c
parent124e10a79789354088f943545a5e56f4cc7c94bd (diff)
downloadFreeBSD-src-ff2a681918f0536be0bd28669d15a78b8d1ed571.zip
FreeBSD-src-ff2a681918f0536be0bd28669d15a78b8d1ed571.tar.gz
Lock and unlock the file once per call and use the unlocked version of
ungetc() instead of having ungetc() recurse on the lock.
Diffstat (limited to 'lib/libc/stdio/ungetwc.c')
-rw-r--r--lib/libc/stdio/ungetwc.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/libc/stdio/ungetwc.c b/lib/libc/stdio/ungetwc.c
index 0783fa9..7602718 100644
--- a/lib/libc/stdio/ungetwc.c
+++ b/lib/libc/stdio/ungetwc.c
@@ -43,17 +43,21 @@ ungetwc(wint_t wc, FILE *fp)
mbstate_t mbs;
size_t len;
- ORIENTLOCK(fp, 1);
-
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
if (wc == WEOF)
- return (WEOF);
-
+ goto error;
memset(&mbs, 0, sizeof(mbs));
if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1)
- return (WEOF);
+ goto error;
while (len-- != 0)
- if (ungetc((unsigned char)buf[len], fp) == EOF)
- return (WEOF);
+ if (__ungetc((unsigned char)buf[len], fp) == EOF)
+ goto error;
+ FUNLOCKFILE(fp);
return (wc);
+
+error:
+ FUNLOCKFILE(fp);
+ return (WEOF);
}
OpenPOWER on IntegriCloud