Lock and unlock the file once per call and use the unlocked version of
ungetc() instead of having ungetc() recurse on the lock.
This commit is contained in:
parent
8f030a44b8
commit
9260341650
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user