add c99 wcstof(3) and wcstold(3).

requested by skrll AT netbsd DOT org, thanks.

bump libc minor 138 -> 139.
This commit is contained in:
tnozaki 2006-04-15 12:17:22 +00:00
parent 6abe9ac90a
commit f9de1ba57e
11 changed files with 352 additions and 94 deletions

View File

@ -1,6 +1,6 @@
# $NetBSD: shl.mi,v 1.348 2006/03/30 12:53:20 martin Exp $
# $NetBSD: shl.mi,v 1.349 2006/04/15 12:17:22 tnozaki Exp $
# Note: libtermcap and libtermlib are hardlinked and share the same version.
./lib/libc.so.12.138 base-sys-shlib
./lib/libc.so.12.139 base-sys-shlib
./lib/libcrypt.so.0.2 base-sys-shlib
./lib/libcrypto.so.3.1 base-crypto-shlib crypto
./lib/libedit.so.2.9 base-sys-shlib
@ -35,7 +35,7 @@
./usr/lib/libasn1.so.6.1 base-krb5-shlib kerberos
./usr/lib/libbsdmalloc.so.0.0 base-sys-shlib
./usr/lib/libbz2.so.1.0 base-sys-shlib
./usr/lib/libc.so.12.138 base-sys-shlib
./usr/lib/libc.so.12.139 base-sys-shlib
./usr/lib/libcdk.so.1.0 base-obsolete obsolete
./usr/lib/libcom_err.so.4.1 base-krb5-shlib kerberos
./usr/lib/libcrypt.so.0.2 base-sys-shlib

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.870 2006/04/14 13:21:49 blymn Exp $
# $NetBSD: mi,v 1.871 2006/04/15 12:17:22 tnozaki Exp $
./etc/mtree/set.comp comp-sys-root
./usr/bin/addr2line comp-debug-bin bfd
./usr/bin/ar comp-util-bin bfd
@ -4759,7 +4759,10 @@
./usr/share/man/cat3/wcsrtombs.0 comp-c-catman .cat
./usr/share/man/cat3/wcsspn.0 comp-c-catman .cat
./usr/share/man/cat3/wcsstr.0 comp-c-catman .cat
./usr/share/man/cat3/wcstod.0 comp-c-catman .cat
./usr/share/man/cat3/wcstof.0 comp-c-catman .cat
./usr/share/man/cat3/wcstok.0 comp-c-catman .cat
./usr/share/man/cat3/wcstold.0 comp-c-catman .cat
./usr/share/man/cat3/wcstombs.0 comp-c-catman .cat
./usr/share/man/cat3/wctob.0 comp-c-catman .cat
./usr/share/man/cat3/wctomb.0 comp-c-catman .cat
@ -8720,7 +8723,10 @@
./usr/share/man/man3/wcsrtombs.3 comp-c-man .man
./usr/share/man/man3/wcsspn.3 comp-c-man .man
./usr/share/man/man3/wcsstr.3 comp-c-man .man
./usr/share/man/man3/wcstod.3 comp-c-man .man
./usr/share/man/man3/wcstof.3 comp-c-man .man
./usr/share/man/man3/wcstok.3 comp-c-man .man
./usr/share/man/man3/wcstold.3 comp-c-man .man
./usr/share/man/man3/wcstombs.3 comp-c-man .man
./usr/share/man/man3/wctob.3 comp-c-man .man
./usr/share/man/man3/wctomb.3 comp-c-man .man

View File

@ -1,4 +1,4 @@
/* $NetBSD: wchar.h,v 1.24 2005/05/15 21:10:52 christos Exp $ */
/* $NetBSD: wchar.h,v 1.25 2006/04/15 12:17:22 tnozaki Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
@ -146,6 +146,9 @@ double wcstod(const wchar_t * __restrict, wchar_t ** __restrict);
#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) > 199901L || \
defined(_NETBSD_SOURCE)
float wcstof(const wchar_t * __restrict, wchar_t ** __restrict);
long double wcstold(const wchar_t * __restrict, wchar_t ** __restrict);
/* LONGLONG */
long long int wcstoll(const wchar_t * __restrict,
wchar_t ** __restrict, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: namespace.h,v 1.111 2006/03/15 17:35:18 kleink Exp $ */
/* $NetBSD: namespace.h,v 1.112 2006/04/15 12:17:23 tnozaki Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@ -608,6 +608,9 @@
#define wait _wait
#define wait3 _wait3
#define waitpid _waitpid
#define wcstod _wcstod
#define wcstof _wcstof
#define wcstold _wcstold
#define wcwidth _wcwidth
#define xdr_accepted_reply _xdr_accepted_reply
#define xdr_array _xdr_array

View File

@ -1,16 +1,19 @@
# from: @(#)Makefile.inc 5.1 (Berkeley) 2/18/91
# $NetBSD: Makefile.inc,v 1.47 2005/03/30 10:15:12 wiz Exp $
# $NetBSD: Makefile.inc,v 1.48 2006/04/15 12:17:23 tnozaki Exp $
# locale sources
.PATH: ${ARCHDIR}/locale ${.CURDIR}/locale
SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \
ctypeio.c localeconv.c nl_langinfo.c setlocale.c setlocale1.c \
setlocale32.c __mb_cur_max.c wcscoll.c wcsftime.c wcstod.c \
setlocale32.c __mb_cur_max.c wcscoll.c wcsftime.c \
wcstol.c wcstoll.c wcstoimax.c wcstoul.c wcstoull.c wcstoumax.c \
wcsxfrm.c aliasname.c
MAN+= nl_langinfo.3 setlocale.3
SRCS+= wcstod.c wcstof.c wcstold.c
MAN+= wcstod.3
MLINKS+=setlocale.3 localeconv.3
.if ${CITRUS} == "no"
@ -42,3 +45,4 @@ MLINKS+=iswalnum.3 iswalpha.3 iswalnum.3 iswblank.3 \
iswalnum.3 iswspace.3 iswalnum.3 iswupper.3 \
iswalnum.3 iswxdigit.3
MLINKS+=towlower.3 towupper.3
MLINKS+=wcstod.3 wcstof.3 wcstod.3 wcstold.3

126
lib/libc/locale/_wcstod.h Normal file
View File

@ -0,0 +1,126 @@
/* $NetBSD: _wcstod.h,v 1.1 2006/04/15 12:17:23 tnozaki Exp $ */
/*-
* 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.
*
* Original version ID:
* FreeBSD: /repoman/r/ncvs/src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp
* NetBSD: wcstod.c,v 1.8 2006/04/13 01:25:13 tnozaki Exp
*/
/*
* function template for wcstof, wcstod, wcstold.
*
* parameters:
* _FUNCNAME : function name
* _RETURN_TYPE : return type
* _STRTOD_FUNC : real conversion function
*/
#ifndef __WCSTOD_H_
#define __WCSTOD_H_
/*
* Convert a string to a double-precision number.
*
* This is the wide-character counterpart of strto{f,d,ld}(). So that
* we do not have to duplicate the code of strto{f,d,ld}() here,
* we convert the supplied wide character string to multibyte and
* call strto{f,d,ld}() on the result.
* This assumes that the multibyte encoding is compatible with ASCII
* for at least the digits, radix character and letters.
*/
_RETURN_TYPE
_FUNCNAME(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
const wchar_t *src, *start;
_RETURN_TYPE val;
char *buf, *end;
size_t bufsiz, len;
_DIAGASSERT(nptr != NULL);
/* endptr may be null */
src = nptr;
while (iswspace((wint_t)*src) != 0)
++src;
if (*src == L'\0')
goto no_convert;
/*
* Convert the supplied numeric wide char. string to multibyte.
*
* We could attempt to find the end of the numeric portion of the
* wide char. string to avoid converting unneeded characters but
* choose not to bother; optimising the uncommon case where
* the input string contains a lot of text after the number
* duplicates a lot of strto{f,d,ld}()'s functionality and
* slows down the most common cases.
*/
start = src;
len = wcstombs(NULL, src, 0);
if (len == (size_t)-1)
/* errno = EILSEQ */
goto no_convert;
_DIAGASSERT(len > 0);
bufsiz = len;
buf = (void *)malloc(bufsiz + 1);
if (buf == NULL)
/* errno = ENOMEM */
goto no_convert;
len = wcstombs(buf, src, bufsiz + 1);
_DIAGASSERT(len == bufsiz);
_DIAGASSERT(buf[len] == '\0');
/* Let strto{f,d,ld}() do most of the work for us. */
val = _STRTOD_FUNC(buf, &end);
if (buf == end) {
free(buf);
goto no_convert;
}
/*
* We only know where the number ended in the _multibyte_
* representation of the string. If the caller wants to know
* where it ended, count multibyte characters to find the
* corresponding position in the wide char string.
*/
if (endptr != NULL)
/* XXX Assume each wide char is one byte. */
*endptr = __UNCONST(start + (size_t)(end - buf));
free(buf);
return val;
no_convert:
if (endptr != NULL)
*endptr = __UNCONST(nptr);
return 0;
}
#endif /*__WCSTOD_H_*/

75
lib/libc/locale/wcstod.3 Normal file
View File

@ -0,0 +1,75 @@
.\" $NeyBSD$
.\"
.\" Copyright (c) 2002, 2003 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.
.\"
.\" $FreeBSD: wcstod.3,v 1.4 2003/05/22 13:02:27 ru Exp $
.\"
.Dd February 22, 2003
.Dt WCSTOD 3
.Os
.Sh NAME
.Nm wcstof ,
.Nm wcstod ,
.Nm wcstold
.Nd convert string to
.Vt float , double
or
.Vt "long double"
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In wchar.h
.Ft float
.Fn wcstof "const wchar_t * restrict nptr" "wchar_t ** restrict endptr"
.Ft "long double"
.Fn wcstold "const wchar_t * restrict nptr" "wchar_t ** restrict endptr"
.Ft double
.Fn wcstod "const wchar_t * restrict nptr" "wchar_t ** restrict endptr"
.Sh DESCRIPTION
The
.Fn wcstof ,
.Fn wcstod
and
.Fn wcstold
functions are the wide-character versions of the
.Fn strtof ,
.Fn strtod
and
.Fn strtold
functions.
Refer to
.Xr strtod 3
for details.
.Sh SEE ALSO
.Xr strtod 3 ,
.Xr wcstol 3
.Sh STANDARDS
The
.Fn wcstof ,
.Fn wcstod
and
.Fn wcstold
functions conform to
.St -isoC-99 .

View File

@ -1,7 +1,7 @@
/* $NetBSD: wcstod.c,v 1.8 2006/04/13 01:25:13 tnozaki Exp $ */
/* $NetBSD: wcstod.c,v 1.9 2006/04/15 12:17:23 tnozaki Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* Copyright (c)2006 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -24,101 +24,38 @@
* 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.
*
* Original version ID:
* FreeBSD: /repoman/r/ncvs/src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstod.c,v 1.8 2006/04/13 01:25:13 tnozaki Exp $");
__RCSID("$NetBSD: wcstod.c,v 1.9 2006/04/15 12:17:23 tnozaki Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
/*
* Convert a string to a double-precision number.
*
* This is the wide-character counterpart of strtod(). So that we do not
* have to duplicate the code of strtod() here, we convert the supplied
* wide character string to multibyte and call strtod() on the result.
* This assumes that the multibyte encoding is compatible with ASCII
* for at least the digits, radix character and letters.
*/
double
wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
const wchar_t *src, *start;
double val;
char *buf, *end;
size_t bufsiz, len;
#ifndef __HAVE_LONG_DOUBLE
#ifdef __strong_alias
__strong_alias(_wcstold,wcstod)
#endif
#ifdef __weak_alias
__weak_alias(wcstold,_wcstold)
#endif
#endif
_DIAGASSERT(nptr != NULL);
/* endptr may be null */
#ifdef __weak_alias
__weak_alias(wcstod,_wcstod)
#endif
src = nptr;
while (iswspace((wint_t)*src) != 0)
++src;
if (*src == L'\0')
goto no_convert;
#define _FUNCNAME wcstod
#define _RETURN_TYPE double
#define _STRTOD_FUNC strtod
/*
* Convert the supplied numeric wide char. string to multibyte.
*
* We could attempt to find the end of the numeric portion of the
* wide char. string to avoid converting unneeded characters but
* choose not to bother; optimising the uncommon case where
* the input string contains a lot of text after the number
* duplicates a lot of strtod()'s functionality and slows down the
* most common cases.
*/
start = src;
len = wcstombs(NULL, src, 0);
if (len == (size_t)-1)
/* errno = EILSEQ */
goto no_convert;
_DIAGASSERT(len > 0);
bufsiz = len;
buf = (void *)malloc(bufsiz + 1);
if (buf == NULL)
/* errno = ENOMEM */
goto no_convert;
len = wcstombs(buf, src, bufsiz + 1);
_DIAGASSERT(len == bufsiz);
_DIAGASSERT(buf[len] == '\0');
/* Let strtod() do most of the work for us. */
val = strtod(buf, &end);
if (buf == end) {
free(buf);
goto no_convert;
}
/*
* We only know where the number ended in the _multibyte_
* representation of the string. If the caller wants to know
* where it ended, count multibyte characters to find the
* corresponding position in the wide char string.
*/
if (endptr != NULL)
/* XXX Assume each wide char is one byte. */
*endptr = __UNCONST(start + (size_t)(end - buf));
free(buf);
return val;
no_convert:
if (endptr != NULL)
*endptr = __UNCONST(nptr);
return 0;
}
#include "_wcstod.h"

52
lib/libc/locale/wcstof.c Normal file
View File

@ -0,0 +1,52 @@
/* $NetBSD: wcstof.c,v 1.1 2006/04/15 12:17:23 tnozaki Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
* 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)
__RCSID("$NetBSD: wcstof.c,v 1.1 2006/04/15 12:17:23 tnozaki Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#ifdef __weak_alias
__weak_alias(wcstof,_wcstof)
#endif
#define _FUNCNAME wcstof
#define _RETURN_TYPE float
#define _STRTOD_FUNC strtof
#include "_wcstod.h"

52
lib/libc/locale/wcstold.c Normal file
View File

@ -0,0 +1,52 @@
/* $NetBSD: wcstold.c,v 1.1 2006/04/15 12:17:23 tnozaki Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
* 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)
__RCSID("$NetBSD: wcstold.c,v 1.1 2006/04/15 12:17:23 tnozaki Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#ifdef __weak_alias
__weak_alias(wcstold,_wcstold)
#endif
#define _FUNCNAME wcstold
#define _RETURN_TYPE long double
#define _STRTOD_FUNC strtold
#include "_wcstod.h"

View File

@ -1,4 +1,4 @@
# $NetBSD: shlib_version,v 1.173 2006/03/30 01:23:50 christos Exp $
# $NetBSD: shlib_version,v 1.174 2006/04/15 12:17:23 tnozaki Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
# things we wish to do on next major version bump:
@ -17,4 +17,4 @@
# - libc/net/getnet{ent,namadr}.c, netdb.h: remove __n_pad0
#
major=12
minor=138
minor=139