summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorjoerg <joerg@NetBSD.org>2013-04-18 22:23:17 +0000
committerjoerg <joerg@NetBSD.org>2013-04-18 22:23:17 +0000
commita01984ea389d0f99eaa2d3fb6539c299e89bee89 (patch)
tree8edb49dd747a2163c3695459991c08b05d205bdd /lib/libc
parent58a085140cefc241d8da6d36ecdea47bbddd26e3 (diff)
Add wcstof_l, wcstod_l and wcstold_l.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/include/namespace.h5
-rw-r--r--lib/libc/locale/_wcstod.h38
-rw-r--r--lib/libc/locale/wcstod.c6
-rw-r--r--lib/libc/locale/wcstof.c6
-rw-r--r--lib/libc/locale/wcstold.c6
5 files changed, 43 insertions, 18 deletions
diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h
index b7d2a57b78a..32adb92af75 100644
--- a/lib/libc/include/namespace.h
+++ b/lib/libc/include/namespace.h
@@ -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
diff --git a/lib/libc/locale/_wcstod.h b/lib/libc/locale/_wcstod.h
index 99a3f7e8f30..04719f75c82 100644
--- a/lib/libc/locale/_wcstod.h
+++ b/lib/libc/locale/_wcstod.h
@@ -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_*/
diff --git a/lib/libc/locale/wcstod.c b/lib/libc/locale/wcstod.c
index 849dfd21293..94cfd001c84 100644
--- a/lib/libc/locale/wcstod.c
+++ b/lib/libc/locale/wcstod.c
@@ -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"
diff --git a/lib/libc/locale/wcstof.c b/lib/libc/locale/wcstof.c
index 9b4e436bd67..9052cd3d386 100644
--- a/lib/libc/locale/wcstof.c
+++ b/lib/libc/locale/wcstof.c
@@ -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"
diff --git a/lib/libc/locale/wcstold.c b/lib/libc/locale/wcstold.c
index a9eaab8dd19..35e4c9231ad 100644
--- a/lib/libc/locale/wcstold.c
+++ b/lib/libc/locale/wcstold.c
@@ -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"