1 --- wcsftime.c.bsdnew 2009-11-09 15:05:25.000000000 -0800
2 +++ wcsftime.c 2009-11-09 17:45:28.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.6 2009/01/15 20:45:59 rdivacky Exp $");
7 +#include "xlocale_private.h"
12 @@ -47,8 +49,9 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
13 * format specifications in the format string.
16 -wcsftime(wchar_t * __restrict wcs, size_t maxsize,
17 - const wchar_t * __restrict format, const struct tm * __restrict timeptr)
18 +wcsftime_l(wchar_t * __restrict wcs, size_t maxsize,
19 + const wchar_t * __restrict format, const struct tm * __restrict timeptr,
22 static const mbstate_t initial;
24 @@ -58,6 +61,7 @@ wcsftime(wchar_t * __restrict wcs, size_
28 + NORMALIZE_LOCALE(loc);
32 @@ -66,13 +70,13 @@ wcsftime(wchar_t * __restrict wcs, size_
36 - sflen = wcsrtombs(NULL, &formatp, 0, &mbs);
37 + sflen = wcsrtombs_l(NULL, &formatp, 0, &mbs, loc);
38 if (sflen == (size_t)-1)
40 if ((sformat = malloc(sflen + 1)) == NULL)
43 - wcsrtombs(sformat, &formatp, sflen + 1, &mbs);
44 + wcsrtombs_l(sformat, &formatp, sflen + 1, &mbs, loc);
47 * Allocate memory for longest multibyte sequence that will fit
48 @@ -80,18 +84,18 @@ wcsftime(wchar_t * __restrict wcs, size_
49 * Then, copy and convert the result back into wide characters in
50 * the caller's buffer.
52 - if (SIZE_T_MAX / MB_CUR_MAX <= maxsize) {
53 + if (SIZE_T_MAX / MB_CUR_MAX_L(loc) <= maxsize) {
54 /* maxsize is prepostorously large - avoid int. overflow. */
58 - if ((dst = malloc(maxsize * MB_CUR_MAX)) == NULL)
59 + if ((dst = malloc(maxsize * MB_CUR_MAX_L(loc))) == NULL)
61 - if (strftime(dst, maxsize, sformat, timeptr) == 0)
62 + if (strftime_l(dst, maxsize, sformat, timeptr, loc) == 0)
66 - n = mbsrtowcs(wcs, &dstp, maxsize, &mbs);
67 + n = mbsrtowcs_l(wcs, &dstp, maxsize, &mbs, loc);
68 if (n == (size_t)-2 || n == (size_t)-1 || dstp != NULL)
71 @@ -106,3 +110,10 @@ error:
77 +wcsftime(wchar_t * __restrict wcs, size_t maxsize,
78 + const wchar_t * __restrict format, const struct tm * __restrict timeptr)
80 + return wcsftime_l(wcs, maxsize, format, timeptr, __current_locale());