summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-09-20 13:25:40 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-09-20 13:25:40 +0000
commit7591ae56aeeefc978363f92d208d5e1140090f96 (patch)
tree29ca5fb47314e22cb303f3692525157b85b73387 /lib/libc
parent92603416509015063df9d8c5ec8318b290d2a683 (diff)
Notes
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/fgetws.c20
-rw-r--r--lib/libc/stdio/fputws.c9
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/libc/stdio/fgetws.c b/lib/libc/stdio/fgetws.c
index d39b082ac51f..29ab4dc72366 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);
}
diff --git a/lib/libc/stdio/fputws.c b/lib/libc/stdio/fputws.c
index 254b4f9de191..467f0982745b 100644
--- a/lib/libc/stdio/fputws.c
+++ b/lib/libc/stdio/fputws.c
@@ -39,12 +39,15 @@ int
fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
{
- ORIENTLOCK(fp, 1);
-
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
/* XXX Inefficient */
while (*ws != '\0')
- if (fputwc(*ws++, fp) == WEOF)
+ if (__fputwc(*ws++, fp) == WEOF) {
+ FUNLOCKFILE(fp);
return (-1);
+ }
+ FUNLOCKFILE(fp);
return (0);
}