summaryrefslogtreecommitdiffstats
path: root/lib/libc/locale/wcsftime.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/locale/wcsftime.c')
-rw-r--r--lib/libc/locale/wcsftime.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/libc/locale/wcsftime.c b/lib/libc/locale/wcsftime.c
index 1ed5b07..bd1cee1 100644
--- a/lib/libc/locale/wcsftime.c
+++ b/lib/libc/locale/wcsftime.c
@@ -50,8 +50,6 @@ 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 state;
char *dst, *dstp, *sformat;
size_t n, sflen;
int sverrno;
@@ -61,15 +59,17 @@ 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.
*/
- state = initial;
- sflen = wcsrtombs(NULL, &format, 0, &state);
+ sflen = wcsrtombs(NULL, &format, 0, NULL);
if (sflen == (size_t)-1)
goto error;
if ((sformat = malloc(sflen + 1)) == NULL)
goto error;
- state = initial;
- wcsrtombs(sformat, &format, sflen + 1, &state);
+ wcsrtombs(sformat, &format, sflen + 1, NULL);
/*
* Allocate memory for longest multibyte sequence that will fit
@@ -86,9 +86,8 @@ wcsftime(wchar_t * __restrict wcs, size_t maxsize,
goto error;
if (strftime(dst, maxsize, sformat, timeptr) == 0)
goto error;
- state = initial;
dstp = dst;
- n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, &state);
+ n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, NULL);
if (n == (size_t)-2 || n == (size_t)-1 || dstp != NULL)
goto error;
OpenPOWER on IntegriCloud