Index: include/wchar.h =================================================================== RCS file: /home/cvs/NetBSD/src/include/wchar.h,v retrieving revision 1.14 diff -u -r1.14 wchar.h --- include/wchar.h 3 Mar 2003 07:39:53 -0000 1.14 +++ include/wchar.h 6 Mar 2003 02:42:21 -0000 @@ -148,9 +148,11 @@ wint_t ungetwc __P((wint_t, FILE *)); wint_t fgetwc __P((FILE *)); +wchar_t *fgetws __P((wchar_t * __restrict, int, FILE * __restrict)); wint_t getwc __P((FILE *)); wint_t getwchar __P((void)); wint_t fputwc __P((wchar_t, FILE *)); +int fputws __P((const wchar_t * __restrict, FILE * __restrict)); wint_t putwc __P((wchar_t, FILE *)); wint_t putwchar __P((wchar_t)); Index: lib/libc/stdio/Makefile.inc =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdio/Makefile.inc,v retrieving revision 1.24 diff -u -r1.24 Makefile.inc --- lib/libc/stdio/Makefile.inc 28 Jan 2003 20:26:04 -0000 1.24 +++ lib/libc/stdio/Makefile.inc 6 Mar 2003 02:26:35 -0000 @@ -15,8 +15,8 @@ putchar.c puts.c putw.c refill.c remove.c rewind.c rget.c scanf.c \ setbuf.c setbuffer.c setvbuf.c snprintf.c sscanf.c stdio.c tmpfile.c \ ungetc.c vasprintf.c vfprintf.c vfscanf.c vprintf.c vscanf.c \ - vsnprintf.c vsscanf.c wbuf.c wsetup.c fputwc.c \ - fgetwc.c ungetwc.c putwc.c putwchar.c getwc.c getwchar.c \ + vsnprintf.c vsscanf.c wbuf.c wsetup.c fputwc.c fputws.c \ + fgetwc.c fgetws.c ungetwc.c putwc.c putwchar.c getwc.c getwchar.c \ fwide.c fparseln.c .if !defined(AUDIT) @@ -29,7 +29,7 @@ MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 flockfile.3 fopen.3 \ fputs.3 fread.3 fseek.3 funopen.3 getc.3 mktemp.3 perror.3 printf.3 \ putc.3 remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 ungetc.3 putwc.3 \ - getwc.3 ungetwc.3 fwide.3 fparseln.3 + getwc.3 ungetwc.3 fwide.3 fparseln.3 fgetws.3 fputws.3 MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3 MLINKS+=fflush.3 fpurge.3 Index: lib/libc/stdio/fgetwc.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdio/fgetwc.c,v retrieving revision 1.2 diff -u -r1.2 fgetwc.c --- lib/libc/stdio/fgetwc.c 18 Jan 2003 11:29:51 -0000 1.2 +++ lib/libc/stdio/fgetwc.c 6 Mar 2003 02:14:54 -0000 @@ -36,7 +36,7 @@ #include "local.h" wint_t -fgetwc(FILE *fp) +__fgetwc_unlock(FILE *fp) { struct wchar_io_data *wcio; mbstate_t *st; @@ -45,11 +45,9 @@ _DIAGASSERT(fp != NULL); - FLOCKFILE(fp); _SET_ORIENTATION(fp, 1); wcio = WCIO_GET(fp); if (wcio == 0) { - FUNLOCKFILE(fp); errno = ENOMEM; return WEOF; } @@ -57,7 +55,6 @@ /* if there're ungetwc'ed wchars, use them */ if (wcio->wcio_ungetwc_inbuf) { wc = wcio->wcio_ungetwc_buf[--wcio->wcio_ungetwc_inbuf]; - FUNLOCKFILE(fp); return wc; } @@ -69,21 +66,33 @@ int ch = __sgetc(fp); if (ch == EOF) { - FUNLOCKFILE(fp); return WEOF; } c = ch; size = mbrtowc(&wc, &c, 1, st); if (size == (size_t)-1) { - FUNLOCKFILE(fp); errno = EILSEQ; return WEOF; } } while (size == (size_t)-2); - FUNLOCKFILE(fp); _DIAGASSERT(size == 1); return wc; } + +wint_t +fgetwc(FILE *fp) +{ + wint_t r; + + _DIAGASSERT(fp != NULL); + + FLOCKFILE(fp); + r = __fgetwc_unlock(fp); + FUNLOCKFILE(fp); + + return (r); +} + Index: lib/libc/stdio/fgetws.3 =================================================================== RCS file: lib/libc/stdio/fgetws.3 diff -N lib/libc/stdio/fgetws.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdio/fgetws.3 6 Mar 2003 02:27:36 -0000 @@ -0,0 +1,122 @@ +.\" Copyright (c) 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Chris Torek and the American National Standards Committee X3, +.\" on Information Processing Systems. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93 +.\" FreeBSD: src/lib/libc/stdio/fgets.3,v 1.16 2002/05/31 05:01:17 archie Exp +.\" $NetBSD$ +.\" +.Dd August 6, 2002 +.Dt FGETWS 3 +.Os +.Sh NAME +.Nm fgetws +.Nd get a line of wide characters from a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.In wchar.h +.Ft "wchar_t *" +.Fn fgetws "wchar_t * restrict ws" "int n" "FILE * restrict fp" +.Sh DESCRIPTION +The +.Fn fgetws +function +reads at most one less than the number of characters specified by +.Fa n +from the given +.Fa fp +and stores them in the wide character string +.Fa ws . +Reading stops when a newline character is found, +at end-of-file or error. +The newline, if any, is retained. +If any characters are read and there is no error, a +.Ql \e0 +character is appended to end the string. +.Sh RETURN VALUES +Upon successful completion, +.Fn fgetws +returns +.Fa ws . +If end-of-file occurs before any characters are read, +.Fn fgetws +returns +.Dv NULL +and the buffer contents remain unchanged. +If an error occurs, +.Fn fgetws +returns +.Dv NULL +and the buffer contents are indeterminate. +The +.Fn fgetws +function +does not distinguish between end-of-file and error, and callers must use +.Xr feof 3 +and +.Xr ferror 3 +to determine which occurred. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +The given +.Fa fp +argument is not a readable stream. +.It Bq Er EILSEQ +The data obtained from the input stream does not form a valid +multibyte character. +.El +.Pp +The function +.Fn fgetws +may also fail and set +.Va errno +for any of the errors specified for the routines +.Xr fflush 3 , +.Xr fstat 2 , +.Xr read 2 , +or +.Xr malloc 3 . +.Sh SEE ALSO +.Xr feof 3 , +.Xr ferror 3 , +.Xr fgets 3 +.Sh STANDARDS +The +.Fn fgetws +function +conforms to +.St -p1003.1-2001 . Index: lib/libc/stdio/fgetws.c =================================================================== RCS file: lib/libc/stdio/fgetws.c diff -N lib/libc/stdio/fgetws.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdio/fgetws.c 6 Mar 2003 02:46:01 -0000 @@ -0,0 +1,87 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c) 2002 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#if defined(LIB_SCCS) && !defined(lint) +__RCSID("$NetBSD$"); +#endif + +#include +#include +#include +#include +#include "reentrant.h" +#include "local.h" + +wchar_t * +fgetws(ws, n, fp) + wchar_t * __restrict ws; + int n; + FILE * __restrict fp; +{ + wchar_t *wsp; + wint_t wc; + + _DIAGASSERT(fp != NULL); + _DIAGASSERT(ws != NULL); + + FLOCKFILE(fp); + _SET_ORIENTATION(fp, 1); + + if (n <= 0) { + errno = EINVAL; + goto error; + } + + wsp = ws; + while (n-- > 1) { + if ((wc = __fgetwc_unlock(fp)) == WEOF && errno == EILSEQ) { + goto error; + } + if (wc == WEOF) { + if (wsp == ws) { + /* EOF/error, no characters read yet. */ + goto error; + } + break; + } + *wsp++ = (wchar_t)wc; + if (wc == L'\n') { + break; + } + } + + *wsp++ = L'\0'; + FUNLOCKFILE(fp); + + return (ws); + +error: + FUNLOCKFILE(fp); + return (NULL); +} Index: lib/libc/stdio/fputwc.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdio/fputwc.c,v retrieving revision 1.2 diff -u -r1.2 fputwc.c --- lib/libc/stdio/fputwc.c 18 Jan 2003 11:29:53 -0000 1.2 +++ lib/libc/stdio/fputwc.c 6 Mar 2003 02:14:21 -0000 @@ -38,7 +38,7 @@ #include "fvwrite.h" wint_t -fputwc(wchar_t wc, FILE *fp) +__fputwc_unlock(wchar_t wc, FILE *fp) { struct wchar_io_data *wcio; mbstate_t *st; @@ -54,11 +54,9 @@ uio.uio_iov = &iov; uio.uio_iovcnt = 1; - FLOCKFILE(fp); _SET_ORIENTATION(fp, 1); wcio = WCIO_GET(fp); if (wcio == 0) { - FUNLOCKFILE(fp); errno = ENOMEM; return WEOF; } @@ -68,7 +66,6 @@ size = wcrtomb(buf, wc, st); if (size == (size_t)-1) { - FUNLOCKFILE(fp); errno = EILSEQ; return WEOF; } @@ -77,11 +74,22 @@ uio.uio_resid = iov.iov_len = size; if (__sfvwrite(fp, &uio)) { - FUNLOCKFILE(fp); return WEOF; } + return (wint_t)wc; +} + +wint_t +fputwc(wchar_t wc, FILE *fp) +{ + wint_t r; + + _DIAGASSERT(fp != NULL); + + FLOCKFILE(fp); + r = __fputwc_unlock(wc, fp); FUNLOCKFILE(fp); - return (wint_t)wc; + return (r); } Index: lib/libc/stdio/fputws.3 =================================================================== RCS file: lib/libc/stdio/fputws.3 diff -N lib/libc/stdio/fputws.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdio/fputws.3 6 Mar 2003 02:27:09 -0000 @@ -0,0 +1,89 @@ +.\" Copyright (c) 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Chris Torek and the American National Standards Committee X3, +.\" on Information Processing Systems. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)fputs.3 8.1 (Berkeley) 6/4/93 +.\" FreeBSD: src/lib/libc/stdio/fputs.3,v 1.8 2001/10/01 16:08:59 ru Exp +.\" $NetBSD$ +.\" +.Dd August 6, 2002 +.Dt FPUTWS 3 +.Os +.Sh NAME +.Nm fputws +.Nd output a line of wide characters to a stream +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.In wchar.h +.Ft int +.Fn fputws "const wchar_t * restrict ws" "FILE * restrict fp" +.Sh DESCRIPTION +The +.Fn fputws +function writes the wide character string pointed to by +.Fa ws +to the stream pointed to by +.Fa fp . +.Sh RETURN VALUES +The +.Fn fputws +function +returns 0 on success and \-1 on error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fp +argument supplied +is not a writable stream. +.El +.Pp +The +.Fn fputws +function may also fail and set +.Va errno +for any of the errors specified for the routine +.Xr write 2 . +.Sh SEE ALSO +.Xr ferror 3 , +.Xr fputs 3 , +.Xr putwc 3 , +.Xr stdio 3 +.Sh STANDARDS +The +.Fn fputws +function conforms to +.St -p1003.1-2001 . Index: lib/libc/stdio/fputws.c =================================================================== RCS file: lib/libc/stdio/fputws.c diff -N lib/libc/stdio/fputws.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdio/fputws.c 6 Mar 2003 02:45:01 -0000 @@ -0,0 +1,62 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c) 2002 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD$"); +#endif + +#include +#include +#include +#include +#include "reentrant.h" +#include "local.h" + +int +fputws(ws, fp) + const wchar_t * __restrict ws; + FILE * __restrict fp; +{ + _DIAGASSERT(fp != NULL); + _DIAGASSERT(ws != NULL); + + FLOCKFILE(fp); + _SET_ORIENTATION(fp, 1); + + while (*ws != '\0') { + if (__fputwc_unlock(*ws++, fp) == WEOF) { + FUNLOCKFILE(fp); + return (-1); + } + } + + FUNLOCKFILE(fp); + + return (0); +} Index: lib/libc/stdio/local.h =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdio/local.h,v retrieving revision 1.14 diff -u -r1.14 local.h --- lib/libc/stdio/local.h 1 Feb 2003 03:25:00 -0000 1.14 +++ lib/libc/stdio/local.h 6 Mar 2003 02:18:22 -0000 @@ -73,6 +73,8 @@ extern int __gettemp __P((char *, int *, int)); +extern wint_t __fgetwc_unlock __P((FILE *)); +extern wint_t __fputwc_unlock __P((wchar_t, FILE *)); /* * Return true iff the given FILE cannot be written now. */