]> git.saurik.com Git - apple/libc.git/blame_incremental - locale/FreeBSD/wcsftime.c.patch
Libc-498.tar.gz
[apple/libc.git] / locale / FreeBSD / wcsftime.c.patch
... / ...
CommitLineData
1--- wcsftime.c.orig 2004-11-25 11:38:20.000000000 -0800
2+++ wcsftime.c 2005-02-24 00:53:36.000000000 -0800
3@@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr 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 @@
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@@ -56,6 +59,7 @@
25 size_t n, sflen;
26 int sverrno;
27
28+ NORMALIZE_LOCALE(loc);
29 sformat = dst = NULL;
30
31 /*
32@@ -63,13 +67,13 @@
33 * for strftime(), which only handles single-byte characters.
34 */
35 mbs = initial;
36- sflen = wcsrtombs(NULL, &format, 0, &mbs);
37+ sflen = wcsrtombs_l(NULL, &format, 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, &format, sflen + 1, &mbs);
44+ wcsrtombs_l(sformat, &format, sflen + 1, &mbs, loc);
45
46 /*
47 * Allocate memory for longest multibyte sequence that will fit
48@@ -77,18 +81,18 @@
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, (const char **)&dstp, maxsize, &mbs);
67+ n = mbsrtowcs_l(wcs, (const char **)&dstp, maxsize, &mbs, loc);
68 if (n == (size_t)-2 || n == (size_t)-1 || dstp != NULL)
69 goto error;
70
71@@ -103,3 +107,10 @@
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+}