summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fgetws.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-09-20 13:25:40 +0000
committertjr <tjr@FreeBSD.org>2002-09-20 13:25:40 +0000
commitdbed35f0682712f2e168f49a242e96a8686105d5 (patch)
tree29ca5fb47314e22cb303f3692525157b85b73387 /lib/libc/stdio/fgetws.c
parentff2a681918f0536be0bd28669d15a78b8d1ed571 (diff)
downloadFreeBSD-src-dbed35f0682712f2e168f49a242e96a8686105d5.zip
FreeBSD-src-dbed35f0682712f2e168f49a242e96a8686105d5.tar.gz
Lock the file once per call and use the unlocked fgetwc()/fputwc() variants.
Diffstat (limited to 'lib/libc/stdio/fgetws.c')
-rw-r--r--lib/libc/stdio/fgetws.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/libc/stdio/fgetws.c b/lib/libc/stdio/fgetws.c
index d39b082..29ab4dc 100644
--- a/lib/libc/stdio/fgetws.c
+++ b/lib/libc/stdio/fgetws.c
@@ -41,20 +41,23 @@ fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
wchar_t *wsp;
wint_t wc;
- ORIENTLOCK(fp, 1);
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
- if (n <= 0)
- return (NULL);
+ if (n <= 0) {
+ errno = EINVAL;
+ goto error;
+ }
wsp = ws;
while (n-- > 1) {
/* XXX Inefficient */
- if ((wc = fgetwc(fp)) == WEOF && errno == EILSEQ)
- return (NULL);
+ if ((wc = __fgetwc(fp)) == WEOF && errno == EILSEQ)
+ goto error;
if (wc == WEOF) {
if (wsp == ws)
/* EOF/error, no characters read yet. */
- return (NULL);
+ goto error;
break;
}
*wsp++ = (wchar_t)wc;
@@ -62,6 +65,11 @@ fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
break;
}
*wsp++ = L'\0';
+ FUNLOCKFILE(fp);
return (ws);
+
+error:
+ FUNLOCKFILE(fp);
+ return (NULL);
}
OpenPOWER on IntegriCloud