aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2004-04-07 09:47:56 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2004-04-07 09:47:56 +0000
commitdc763237dac6f1391d35533691691b118e21272b (patch)
tree11fa0f1538982249c0bab94e73e6639ddeab7213
parented870c6a8e17a94f7e99d16246bde847e0f8887f (diff)
downloadsrc-dc763237dac6f1391d35533691691b118e21272b.tar.gz
src-dc763237dac6f1391d35533691691b118e21272b.zip
Notes
-rw-r--r--lib/libc/locale/wcsftime.c15
-rw-r--r--lib/libc/locale/wcstod.c12
-rw-r--r--lib/libc/locale/wcstof.c8
-rw-r--r--lib/libc/locale/wcstold.c8
-rw-r--r--lib/libc/string/wcscoll.c8
-rw-r--r--lib/libc/string/wcsxfrm.c8
6 files changed, 38 insertions, 21 deletions
diff --git a/lib/libc/locale/wcsftime.c b/lib/libc/locale/wcsftime.c
index bd1cee15c256..7a54fc053c5a 100644
--- a/lib/libc/locale/wcsftime.c
+++ b/lib/libc/locale/wcsftime.c
@@ -50,6 +50,8 @@ size_t
wcsftime(wchar_t * __restrict wcs, size_t maxsize,
const wchar_t * __restrict format, const struct tm * __restrict timeptr)
{
+ static const mbstate_t initial;
+ mbstate_t mbs;
char *dst, *dstp, *sformat;
size_t n, sflen;
int sverrno;
@@ -59,17 +61,15 @@ wcsftime(wchar_t * __restrict wcs, size_t maxsize,
/*
* Convert the supplied format string to a multibyte representation
* for strftime(), which only handles single-byte characters.
- *
- * We pass NULL as the state pointer to wcrtomb() because we don't
- * support state-dependent encodings and don't want to waste time
- * creating a zeroed mbstate_t that will not be used.
*/
- sflen = wcsrtombs(NULL, &format, 0, NULL);
+ mbs = initial;
+ sflen = wcsrtombs(NULL, &format, 0, &mbs);
if (sflen == (size_t)-1)
goto error;
if ((sformat = malloc(sflen + 1)) == NULL)
goto error;
- wcsrtombs(sformat, &format, sflen + 1, NULL);
+ mbs = initial;
+ wcsrtombs(sformat, &format, sflen + 1, &mbs);
/*
* Allocate memory for longest multibyte sequence that will fit
@@ -87,7 +87,8 @@ wcsftime(wchar_t * __restrict wcs, size_t maxsize,
if (strftime(dst, maxsize, sformat, timeptr) == 0)
goto error;
dstp = dst;
- n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, NULL);
+ mbs = initial;
+ n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, &mbs);
if (n == (size_t)-2 || n == (size_t)-1 || dstp != NULL)
goto error;
diff --git a/lib/libc/locale/wcstod.c b/lib/libc/locale/wcstod.c
index 1f13e2f1e2c6..68df1eddfedd 100644
--- a/lib/libc/locale/wcstod.c
+++ b/lib/libc/locale/wcstod.c
@@ -43,6 +43,8 @@ __FBSDID("$FreeBSD$");
double
wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
+ static const mbstate_t initial;
+ mbstate_t mbs;
double val;
char *buf, *end;
const wchar_t *wcp;
@@ -60,20 +62,18 @@ wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
* 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.
- *
- * We pass NULL as the state pointer to wcrtomb() because we don't
- * support state-dependent encodings and don't want to waste time
- * creating a zeroed mbstate_t that will not be used.
*/
wcp = nptr;
- if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1) {
+ mbs = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
if (endptr != NULL)
*endptr = (wchar_t *)nptr;
return (0.0);
}
if ((buf = malloc(len + 1)) == NULL)
return (0.0);
- wcsrtombs(buf, &wcp, len + 1, NULL);
+ mbs = initial;
+ wcsrtombs(buf, &wcp, len + 1, &mbs);
/* Let strtod() do most of the work for us. */
val = strtod(buf, &end);
diff --git a/lib/libc/locale/wcstof.c b/lib/libc/locale/wcstof.c
index 909db0b067f7..ba238d459031 100644
--- a/lib/libc/locale/wcstof.c
+++ b/lib/libc/locale/wcstof.c
@@ -37,6 +37,8 @@ __FBSDID("$FreeBSD$");
float
wcstof(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
+ static const mbstate_t initial;
+ mbstate_t mbs;
float val;
char *buf, *end;
const wchar_t *wcp;
@@ -46,14 +48,16 @@ wcstof(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
nptr++;
wcp = nptr;
- if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1) {
+ mbs = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
if (endptr != NULL)
*endptr = (wchar_t *)nptr;
return (0.0);
}
if ((buf = malloc(len + 1)) == NULL)
return (0.0);
- wcsrtombs(buf, &wcp, len + 1, NULL);
+ mbs = initial;
+ wcsrtombs(buf, &wcp, len + 1, &mbs);
val = strtof(buf, &end);
diff --git a/lib/libc/locale/wcstold.c b/lib/libc/locale/wcstold.c
index 76158c1e7441..cf9d87464c5d 100644
--- a/lib/libc/locale/wcstold.c
+++ b/lib/libc/locale/wcstold.c
@@ -37,6 +37,8 @@ __FBSDID("$FreeBSD$");
long double
wcstold(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
+ static const mbstate_t initial;
+ mbstate_t mbs;
long double val;
char *buf, *end;
const wchar_t *wcp;
@@ -46,14 +48,16 @@ wcstold(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
nptr++;
wcp = nptr;
- if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1) {
+ mbs = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
if (endptr != NULL)
*endptr = (wchar_t *)nptr;
return (0.0);
}
if ((buf = malloc(len + 1)) == NULL)
return (0.0);
- wcsrtombs(buf, &wcp, len + 1, NULL);
+ mbs = initial;
+ wcsrtombs(buf, &wcp, len + 1, &mbs);
val = strtold(buf, &end);
diff --git a/lib/libc/string/wcscoll.c b/lib/libc/string/wcscoll.c
index b042a2576fa6..dbfbcfa919a7 100644
--- a/lib/libc/string/wcscoll.c
+++ b/lib/libc/string/wcscoll.c
@@ -79,16 +79,20 @@ wcscoll(const wchar_t *ws1, const wchar_t *ws2)
static char *
__mbsdup(const wchar_t *ws)
{
+ static const mbstate_t initial;
+ mbstate_t st;
const wchar_t *wcp;
size_t len;
char *mbs;
wcp = ws;
- if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1)
+ st = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1)
return (NULL);
if ((mbs = malloc(len + 1)) == NULL)
return (NULL);
- wcsrtombs(mbs, &ws, len + 1, NULL);
+ st = initial;
+ wcsrtombs(mbs, &ws, len + 1, &st);
return (mbs);
}
diff --git a/lib/libc/string/wcsxfrm.c b/lib/libc/string/wcsxfrm.c
index 4e988af47b01..5e47ad946ee6 100644
--- a/lib/libc/string/wcsxfrm.c
+++ b/lib/libc/string/wcsxfrm.c
@@ -97,16 +97,20 @@ wcsxfrm(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len)
static char *
__mbsdup(const wchar_t *ws)
{
+ static const mbstate_t initial;
+ mbstate_t st;
const wchar_t *wcp;
size_t len;
char *mbs;
wcp = ws;
- if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1)
+ st = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1)
return (NULL);
if ((mbs = malloc(len + 1)) == NULL)
return (NULL);
- wcsrtombs(mbs, &ws, len + 1, NULL);
+ st = initial;
+ wcsrtombs(mbs, &ws, len + 1, &st);
return (mbs);
}