Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdio Add the missing wide char support functions f...
details: https://anonhg.NetBSD.org/src/rev/2340b9337d98
branches: trunk
changeset: 580894:2340b9337d98
user: christos <christos%NetBSD.org@localhost>
date: Sat May 14 23:51:02 2005 +0000
description:
Add the missing wide char support functions from freebsd.
XXX: long double support is missing until we get gdtoa, and add the
necessary wide functions.
diffstat:
lib/libc/stdio/Makefile.inc | 37 +-
lib/libc/stdio/fgetstr.c | 6 +-
lib/libc/stdio/fgetwln.3 | 121 ++
lib/libc/stdio/fgetwln.c | 78 +
lib/libc/stdio/floatio.h | 13 +-
lib/libc/stdio/fwprintf.c | 53 +
lib/libc/stdio/fwscanf.c | 53 +
lib/libc/stdio/local.h | 7 +-
lib/libc/stdio/swprintf.c | 53 +
lib/libc/stdio/swscanf.c | 53 +
lib/libc/stdio/vfwprintf.c | 1748 +++++++++++++++++++++++++++++++++++++++++++
lib/libc/stdio/vfwscanf.c | 886 +++++++++++++++++++++
lib/libc/stdio/vswprintf.c | 100 ++
lib/libc/stdio/vswscanf.c | 104 ++
lib/libc/stdio/vwprintf.c | 47 +
lib/libc/stdio/vwscanf.c | 47 +
lib/libc/stdio/wprintf.3 | 623 +++++++++++++++
lib/libc/stdio/wprintf.c | 53 +
lib/libc/stdio/wscanf.3 | 484 +++++++++++
lib/libc/stdio/wscanf.c | 53 +
20 files changed, 4598 insertions(+), 21 deletions(-)
diffs (truncated from 4756 to 300 lines):
diff -r 93872ab1843a -r 2340b9337d98 lib/libc/stdio/Makefile.inc
--- a/lib/libc/stdio/Makefile.inc Sat May 14 20:03:31 2005 +0000
+++ b/lib/libc/stdio/Makefile.inc Sat May 14 23:51:02 2005 +0000
@@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 5.7 (Berkeley) 6/27/91
-# $NetBSD: Makefile.inc,v 1.28 2004/05/10 17:02:21 drochner Exp $
+# $NetBSD: Makefile.inc,v 1.29 2005/05/14 23:51:02 christos Exp $
# stdio sources
.PATH: ${.CURDIR}/stdio
@@ -7,17 +7,19 @@
CPPFLAGS+=-DFLOATING_POINT
SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c \
- fgetc.c fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c \
- flockfile.c fopen.c fprintf.c fpurge.c fputc.c fputs.c fread.c \
+ fgetc.c fgetln.c fgetpos.c fgets.c fgetstr.c fgetwc.c fgetwln.c \
+ fgetws.c fileno.c findfp.c flags.c flockfile.c fopen.c fparseln.c \
+ fprintf.c fpurge.c fputc.c fputs.c fputwc.c fputws.c fread.c \
freopen.c fscanf.c fseek.c fseeko.c fsetpos.c ftell.c ftello.c \
- funopen.c fvwrite.c fwalk.c fwrite.c getc.c getchar.c gettemp.c \
- getw.c makebuf.c mkdtemp.c mkstemp.c perror.c printf.c putc.c \
- 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 fputws.c \
- fgetwc.c fgetws.c ungetwc.c putwc.c putwchar.c getwc.c getwchar.c \
- fwide.c fparseln.c fgetstr.c
+ funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwrite.c fwscanf.c \
+ getc.c getchar.c gettemp.c getw.c getwc.c getwchar.c makebuf.c \
+ mkdtemp.c mkstemp.c perror.c printf.c putc.c putchar.c puts.c \
+ putw.c putwc.c putwchar.c refill.c remove.c rewind.c rget.c \
+ scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sscanf.c \
+ stdio.c swprintf.c swscanf.c tmpfile.c ungetc.c ungetwc.c \
+ vasprintf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c vprintf.c \
+ vscanf.c vsnprintf.c vsscanf.c vswprintf.c vswscanf.c vwprintf.c \
+ vwscanf.c wbuf.c wprintf.c wscanf.c wsetup.c
.if !defined(AUDIT)
SRCS+= gets.c sprintf.c vsprintf.c tempnam.c tmpnam.c mktemp.c
@@ -26,10 +28,11 @@
# namespace purity wrappers
SRCS+= _fileno.c _fseeko.c _ftello.c
-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 fgetws.3 fputws.3
+MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \
+ flockfile.3 fopen.3 fparseln.3 fputs.3 fputws.3 fread.3 fseek.3 \
+ funopen.3 fwide.3 getc.3 getwc.3 mktemp.3 perror.3 printf.3 \
+ putc.3 putwc.3 remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 \
+ ungetc.3 ungetwc.3 wprintf.3 wscanf.3
MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
MLINKS+=fflush.3 fpurge.3
@@ -55,3 +58,7 @@
MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3
MLINKS+=putwc.3 fputwc.3 putwc.3 putwchar.3
MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3
+MLINKS+=wprintf.3 fwprintf.3 wprintf.3 swprintf.3
+MLINKS+=wprintf.3 vwprintf.3 wprintf.3 vfwprintf.3 wprintf.3 vswprintf.3
+MLINKS+=wscanf.3 fwscanf.3 wscanf.3 swscanf.3 wscanf.3 vwscanf.3
+MLINKS+=wscanf.3 vswscanf.3 wscanf.3 vfwscanf.3
diff -r 93872ab1843a -r 2340b9337d98 lib/libc/stdio/fgetstr.c
--- a/lib/libc/stdio/fgetstr.c Sat May 14 20:03:31 2005 +0000
+++ b/lib/libc/stdio/fgetstr.c Sat May 14 23:51:02 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fgetstr.c,v 1.2 2004/05/10 16:47:11 drochner Exp $ */
+/* $NetBSD: fgetstr.c,v 1.3 2005/05/14 23:51:02 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)fgetline.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: fgetstr.c,v 1.2 2004/05/10 16:47:11 drochner Exp $");
+__RCSID("$NetBSD: fgetstr.c,v 1.3 2005/05/14 23:51:02 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -50,8 +50,6 @@
#include "reentrant.h"
#include "local.h"
-int __slbexpand __P((FILE *, size_t));
-
/*
* Expand the line buffer. Return -1 on error.
#ifdef notdef
diff -r 93872ab1843a -r 2340b9337d98 lib/libc/stdio/fgetwln.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/stdio/fgetwln.3 Sat May 14 23:51:02 2005 +0000
@@ -0,0 +1,121 @@
+.\" $NetBSD: fgetwln.3,v 1.1 2005/05/14 23:51:02 christos Exp $
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. 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.
+.\" 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.
+.\"
+.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
+.\" $FreeBSD: src/lib/libc/stdio/fgetwln.3,v 1.1 2004/07/16 06:06:09 tjr Exp $
+.\"
+.Dd July 16, 2004
+.Dt FGETWLN 3
+.Os
+.Sh NAME
+.Nm fgetwln
+.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 fgetwln "FILE * restrict stream" "size_t * restrict len"
+.Sh DESCRIPTION
+The
+.Fn fgetwln
+function
+returns a pointer to the next line from the stream referenced by
+.Fa stream .
+This line is
+.Em not
+a standard wide character string as it does not end with a terminating
+null wide character.
+The length of the line, including the final newline,
+is stored in the memory location to which
+.Fa len
+points.
+(Note, however, that if the line is the last
+in a file that does not end in a newline,
+the returned text will not contain a newline.)
+.Sh RETURN VALUES
+Upon successful completion a pointer is returned;
+this pointer becomes invalid after the next
+.Tn I/O
+operation on
+.Fa stream
+(whether successful or not)
+or as soon as the stream is closed.
+Otherwise,
+.Dv NULL
+is returned.
+The
+.Fn fgetwln
+function
+does not distinguish between end-of-file and error; the routines
+.Xr feof 3
+and
+.Xr ferror 3
+must be used
+to determine which occurred.
+If an error occurs, the global variable
+.Va errno
+is set to indicate the error.
+The end-of-file condition is remembered, even on a terminal, and all
+subsequent attempts to read will return
+.Dv NULL
+until the condition is
+cleared with
+.Xr clearerr 3 .
+.Pp
+The text to which the returned pointer points may be modified,
+provided that no changes are made beyond the returned size.
+These changes are lost as soon as the pointer becomes invalid.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EBADF
+The argument
+.Fa stream
+is not a stream open for reading.
+.El
+.Pp
+The
+.Fn fgetwln
+function
+may also fail and set
+.Va errno
+for any of the errors specified for the routines
+.Xr mbrtowc 3 ,
+.Xr realloc 3 ,
+or
+.Xr read 2 .
+.Sh SEE ALSO
+.Xr ferror 3 ,
+.Xr fgetln 3 ,
+.Xr fgetws 3 ,
+.Xr fopen 3
diff -r 93872ab1843a -r 2340b9337d98 lib/libc/stdio/fgetwln.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/stdio/fgetwln.c Sat May 14 23:51:02 2005 +0000
@@ -0,0 +1,78 @@
+/* $NetBSD: fgetwln.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002-2004 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 <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwln.c,v 1.2 2004/08/06 17:00:09 tjr Exp $");
+#else
+__RCSID("$NetBSD: fgetwln.c,v 1.1 2005/05/14 23:51:02 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <stdio.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(fgetwln,_fgetwln)
+#endif
+
+wchar_t *
+fgetwln(FILE * __restrict fp, size_t *lenp)
+{
+ wint_t wc;
+ size_t len;
+
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, 1);
+
+ len = 0;
+ while ((wc = __fgetwc_unlock(fp)) != WEOF) {
+#define GROW 512
+ if (len * sizeof(wchar_t) >= fp->_lb._size &&
+ __slbexpand(fp, (len + GROW) * sizeof(wchar_t)))
+ goto error;
+ *((wchar_t *)(void *)fp->_lb._base + len++) = wc;
+ if (wc == L'\n')
+ break;
+ }
+ if (len == 0)
+ goto error;
+
+ FUNLOCKFILE(fp);
+ *lenp = len;
+ return ((wchar_t *)(void *)fp->_lb._base);
+
+error:
+ FUNLOCKFILE(fp);
+ *lenp = 0;
+ return (NULL);
+}
diff -r 93872ab1843a -r 2340b9337d98 lib/libc/stdio/floatio.h
--- a/lib/libc/stdio/floatio.h Sat May 14 20:03:31 2005 +0000
Home |
Main Index |
Thread Index |
Old Index