Add wcstof_l, wcstod_l and wcstold_l.

This commit is contained in:
joerg 2013-04-18 22:23:17 +00:00
parent ceb51ddcad
commit 9a7fa6ff3c
6 changed files with 48 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wchar.h,v 1.32 2013/04/16 16:52:13 joerg Exp $ */
/* $NetBSD: wchar.h,v 1.33 2013/04/18 22:23:17 joerg Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
@ -211,6 +211,10 @@ __END_DECLS
typedef struct _locale *locale_t;
# define __LOCALE_T_DECLARED
# endif
float wcstof_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t);
double wcstod_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t);
long double wcstold_l(const wchar_t * __restrict, wchar_t ** __restrict,
locale_t);
long int wcstol_l(const wchar_t * __restrict, wchar_t ** __restrict, int,
locale_t);
unsigned long int wcstoul_l(const wchar_t * __restrict,

View File

@ -1,4 +1,4 @@
/* $NetBSD: namespace.h,v 1.159 2013/04/18 21:54:11 joerg Exp $ */
/* $NetBSD: namespace.h,v 1.160 2013/04/18 22:23:17 joerg Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@ -707,8 +707,11 @@
#define wcsdup _wcsdup
#define wcsncasecmp _wcsncasecmp
#define wcstof _wcstof
#define wcstof_l _wcstof_l
#define wcstod _wcstod
#define wcstod_l _wcstod_l
#define wcstold _wcstold
#define wcstold_l _wcstold_l
#define wcwidth _wcwidth
#define wcwidth_l _wcwidth_l
#define xdr_accepted_reply _xdr_accepted_reply

View File

@ -1,4 +1,4 @@
/* $NetBSD: _wcstod.h,v 1.2 2010/12/16 17:42:27 wiz Exp $ */
/* $NetBSD: _wcstod.h,v 1.3 2013/04/18 22:23:17 joerg Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
@ -6,7 +6,7 @@
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* aINre 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
@ -41,6 +41,11 @@
#ifndef __WCSTOD_H_
#define __WCSTOD_H_
#include <locale.h>
#include "setlocale_local.h"
#define INT_NAME_(pre, middle, post) pre ## middle ## post
#define INT_NAME(pre, middle, post) INT_NAME_(pre, middle, post)
/*
* Convert a string to a double-precision number.
*
@ -51,8 +56,9 @@
* 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)
static _RETURN_TYPE
INT_NAME(_int_, _FUNCNAME, _l)(const wchar_t * __restrict nptr,
wchar_t ** __restrict endptr, locale_t loc)
{
const wchar_t *src, *start;
_RETURN_TYPE val;
@ -63,7 +69,7 @@ _FUNCNAME(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
/* endptr may be null */
src = nptr;
while (iswspace((wint_t)*src) != 0)
while (iswspace_l((wint_t)*src, loc) != 0)
++src;
if (*src == L'\0')
goto no_convert;
@ -79,7 +85,7 @@ _FUNCNAME(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
* slows down the most common cases.
*/
start = src;
len = wcstombs(NULL, src, 0);
len = wcstombs_l(NULL, src, 0, loc);
if (len == (size_t)-1)
/* errno = EILSEQ */
goto no_convert;
@ -92,13 +98,13 @@ _FUNCNAME(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
/* errno = ENOMEM */
goto no_convert;
len = wcstombs(buf, src, bufsiz + 1);
len = wcstombs_l(buf, src, bufsiz + 1, loc);
_DIAGASSERT(len == bufsiz);
_DIAGASSERT(buf[len] == '\0');
/* Let strto{f,d,ld}() do most of the work for us. */
val = _STRTOD_FUNC(buf, &end);
val = _STRTOD_FUNC(buf, &end, loc);
if (buf == end) {
free(buf);
goto no_convert;
@ -123,4 +129,20 @@ no_convert:
*endptr = __UNCONST(nptr);
return 0;
}
_RETURN_TYPE
INT_NAME(, _FUNCNAME, )(const wchar_t * __restrict nptr,
wchar_t ** __restrict endptr)
{
return INT_NAME(_int_, _FUNCNAME, _l)(nptr, endptr, *_current_locale());
}
_RETURN_TYPE
INT_NAME(, _FUNCNAME, _l)(const wchar_t * __restrict nptr,
wchar_t ** __restrict endptr, locale_t loc)
{
if (loc == NULL)
loc = _C_locale;
return INT_NAME(_int_, _FUNCNAME, _l)(nptr, endptr, loc);
}
#endif /*__WCSTOD_H_*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: wcstod.c,v 1.14 2008/04/25 16:43:00 christos Exp $ */
/* $NetBSD: wcstod.c,v 1.15 2013/04/18 22:23:17 joerg Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstod.c,v 1.14 2008/04/25 16:43:00 christos Exp $");
__RCSID("$NetBSD: wcstod.c,v 1.15 2013/04/18 22:23:17 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -45,6 +45,6 @@ __weak_alias(wcstod,_wcstod)
#define _FUNCNAME wcstod
#define _RETURN_TYPE double
#define _STRTOD_FUNC strtod
#define _STRTOD_FUNC strtod_l
#include "_wcstod.h"

View File

@ -1,4 +1,4 @@
/* $NetBSD: wcstof.c,v 1.3 2008/04/25 16:43:00 christos Exp $ */
/* $NetBSD: wcstof.c,v 1.4 2013/04/18 22:23:18 joerg Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstof.c,v 1.3 2008/04/25 16:43:00 christos Exp $");
__RCSID("$NetBSD: wcstof.c,v 1.4 2013/04/18 22:23:18 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -45,6 +45,6 @@ __weak_alias(wcstof,_wcstof)
#define _FUNCNAME wcstof
#define _RETURN_TYPE float
#define _STRTOD_FUNC strtof
#define _STRTOD_FUNC strtof_l
#include "_wcstod.h"

View File

@ -1,4 +1,4 @@
/* $NetBSD: wcstold.c,v 1.3 2008/07/08 00:23:28 gmcgarry Exp $ */
/* $NetBSD: wcstold.c,v 1.4 2013/04/18 22:23:18 joerg Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstold.c,v 1.3 2008/07/08 00:23:28 gmcgarry Exp $");
__RCSID("$NetBSD: wcstold.c,v 1.4 2013/04/18 22:23:18 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -45,6 +45,6 @@ __weak_alias(wcstold,_wcstold)
#define _FUNCNAME wcstold
#define _RETURN_TYPE long double
#define _STRTOD_FUNC strtold
#define _STRTOD_FUNC strtold_l
#include "_wcstod.h"