Lock the file once per call and use the unlocked fgetwc()/fputwc() variants.
This commit is contained in:
parent
9260341650
commit
7591ae56ae
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=103678
@ -41,20 +41,23 @@ fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
|
|||||||
wchar_t *wsp;
|
wchar_t *wsp;
|
||||||
wint_t wc;
|
wint_t wc;
|
||||||
|
|
||||||
ORIENTLOCK(fp, 1);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, 1);
|
||||||
|
|
||||||
if (n <= 0)
|
if (n <= 0) {
|
||||||
return (NULL);
|
errno = EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
wsp = ws;
|
wsp = ws;
|
||||||
while (n-- > 1) {
|
while (n-- > 1) {
|
||||||
/* XXX Inefficient */
|
/* XXX Inefficient */
|
||||||
if ((wc = fgetwc(fp)) == WEOF && errno == EILSEQ)
|
if ((wc = __fgetwc(fp)) == WEOF && errno == EILSEQ)
|
||||||
return (NULL);
|
goto error;
|
||||||
if (wc == WEOF) {
|
if (wc == WEOF) {
|
||||||
if (wsp == ws)
|
if (wsp == ws)
|
||||||
/* EOF/error, no characters read yet. */
|
/* EOF/error, no characters read yet. */
|
||||||
return (NULL);
|
goto error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*wsp++ = (wchar_t)wc;
|
*wsp++ = (wchar_t)wc;
|
||||||
@ -62,6 +65,11 @@ fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*wsp++ = L'\0';
|
*wsp++ = L'\0';
|
||||||
|
FUNLOCKFILE(fp);
|
||||||
|
|
||||||
return (ws);
|
return (ws);
|
||||||
|
|
||||||
|
error:
|
||||||
|
FUNLOCKFILE(fp);
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,15 @@ int
|
|||||||
fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
|
fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
|
||||||
{
|
{
|
||||||
|
|
||||||
ORIENTLOCK(fp, 1);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, 1);
|
||||||
/* XXX Inefficient */
|
/* XXX Inefficient */
|
||||||
while (*ws != '\0')
|
while (*ws != '\0')
|
||||||
if (fputwc(*ws++, fp) == WEOF)
|
if (__fputwc(*ws++, fp) == WEOF) {
|
||||||
|
FUNLOCKFILE(fp);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
}
|
||||||
|
FUNLOCKFILE(fp);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user