diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/locale/wcsftime.c | 15 | ||||
-rw-r--r-- | lib/libc/locale/wcstod.c | 12 | ||||
-rw-r--r-- | lib/libc/locale/wcstof.c | 8 | ||||
-rw-r--r-- | lib/libc/locale/wcstold.c | 8 | ||||
-rw-r--r-- | lib/libc/string/wcscoll.c | 8 | ||||
-rw-r--r-- | lib/libc/string/wcsxfrm.c | 8 |
6 files changed, 38 insertions, 21 deletions
diff --git a/lib/libc/locale/wcsftime.c b/lib/libc/locale/wcsftime.c index bd1cee1..7a54fc0 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 1f13e2f..68df1ed 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 909db0b..ba238d4 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 76158c1..cf9d874 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 b042a25..dbfbcfa 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 4e988af..5e47ad9 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); } |