]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/wcsftime.c.patch
02c81ea8dd0e6c551352ab9c506b06c60628f482
[apple/libc.git] / locale / FreeBSD / wcsftime.c.patch
1 --- wcsftime.c.bsdnew 2009-11-09 15:05:25.000000000 -0800
2 +++ wcsftime.c 2009-11-09 17:45:28.000000000 -0800
3 @@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.6 2009/01/15 20:45:59 rdivacky Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <errno.h>
10 #include <limits.h>
11 #include <stdlib.h>
12 @@ -47,8 +49,9 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
13 * format specifications in the format string.
14 */
15 size_t
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,
20 + locale_t loc)
21 {
22 static const mbstate_t initial;
23 mbstate_t mbs;
24 @@ -58,6 +61,7 @@ wcsftime(wchar_t * __restrict wcs, size_
25 size_t n, sflen;
26 int sverrno;
27
28 + NORMALIZE_LOCALE(loc);
29 sformat = dst = NULL;
30
31 /*
32 @@ -66,13 +70,13 @@ wcsftime(wchar_t * __restrict wcs, size_
33 */
34 mbs = initial;
35 formatp = format;
36 - sflen = wcsrtombs(NULL, &formatp, 0, &mbs);
37 + sflen = wcsrtombs_l(NULL, &formatp, 0, &mbs, loc);
38 if (sflen == (size_t)-1)
39 goto error;
40 if ((sformat = malloc(sflen + 1)) == NULL)
41 goto error;
42 mbs = initial;
43 - wcsrtombs(sformat, &formatp, sflen + 1, &mbs);
44 + wcsrtombs_l(sformat, &formatp, sflen + 1, &mbs, loc);
45
46 /*
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.
51 */
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. */
55 errno = EINVAL;
56 goto error;
57 }
58 - if ((dst = malloc(maxsize * MB_CUR_MAX)) == NULL)
59 + if ((dst = malloc(maxsize * MB_CUR_MAX_L(loc))) == NULL)
60 goto error;
61 - if (strftime(dst, maxsize, sformat, timeptr) == 0)
62 + if (strftime_l(dst, maxsize, sformat, timeptr, loc) == 0)
63 goto error;
64 dstp = dst;
65 mbs = initial;
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)
69 goto error;
70
71 @@ -106,3 +110,10 @@ error:
72 errno = sverrno;
73 return (0);
74 }
75 +
76 +size_t
77 +wcsftime(wchar_t * __restrict wcs, size_t maxsize,
78 + const wchar_t * __restrict format, const struct tm * __restrict timeptr)
79 +{
80 + return wcsftime_l(wcs, maxsize, format, timeptr, __current_locale());
81 +}