1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
$NetBSD: patch-main_stdtime_localtime.c,v 1.2 2015/05/19 07:52:14 jnemeth Exp $
--- main/stdtime/localtime.c.orig 2015-03-10 17:42:57.000000000 +0000
+++ main/stdtime/localtime.c
@@ -733,7 +733,7 @@ static void *notify_daemon(void *data)
if (st.st_mtime > cur->mtime[0] || lst.st_mtime > cur->mtime[1]) {
#ifdef TEST_FRAMEWORK
if (test) {
- ast_test_status_update(test, "Removing cached TZ entry '%s' because underlying file changed. (%ld != %ld) or (%ld != %ld)\n", name, st.st_mtime, cur->mtime[0], lst.st_mtime, cur->mtime[1]);
+ ast_test_status_update(test, "Removing cached TZ entry '%s' because underlying file changed. (%jd != %jd) or (%jd != %jd)\n", name, (intmax_t)st.st_mtime, (intmax_t)cur->mtime[0], (intmax_t)lst.st_mtime, (intmax_t)cur->mtime[1]);
} else
#endif
{
@@ -2417,6 +2417,23 @@ static struct locale_entry *find_by_name
return NULL;
}
+#if HAVE_STRFTIME_L || HAVE_STRPTIME_L
+static locale_t ast_getlocale(const char *locale)
+{
+ struct locale_entry *cur;
+
+ AST_LIST_LOCK(&localelist);
+ if ((cur = find_by_name(locale)) == NULL) {
+ cur->locale = newlocale(LC_ALL_MASK, locale, NULL);
+ strcpy(cur->name, locale); /* SAFE */
+ AST_LIST_INSERT_TAIL(&localelist, cur, list);
+ }
+ AST_LIST_UNLOCK(&localelist);
+ return cur->locale;
+}
+#endif
+
+#if !HAVE_STRFTIME_L || !HAVE_STRPTIME_L
static const char *store_by_locale(locale_t prevlocale)
{
struct locale_entry *cur;
@@ -2474,6 +2491,7 @@ const char *ast_setlocale(const char *lo
AST_LIST_UNLOCK(&localelist);
return store_by_locale(prevlocale);
}
+#endif
#else
const char *ast_setlocale(const char *unused)
{
@@ -2487,7 +2505,9 @@ int ast_strftime_locale(char *buf, size_
char *format = ast_calloc(1, fmtlen), *fptr = format, *newfmt;
int decimals = -1, i, res;
long fraction;
+#if !HAVE_STRFTIME_L
const char *prevlocale;
+#endif
buf[0] = '\0';/* Ensure the buffer is initialized. */
if (!format) {
@@ -2542,6 +2562,14 @@ defcase: *fptr++ = *tmp;
}
*fptr = '\0';
#undef strftime
+#if HAVE_STRFTIME_L
+ if (locale) {
+ locale_t l = ast_getlocale(locale);
+ res = (int)strftime_l(buf, len, format, (struct tm *)tm, l);
+ } else {
+ res = (int)strftime(buf, len, format, (struct tm *)tm);
+ }
+#else
if (locale) {
prevlocale = ast_setlocale(locale);
}
@@ -2549,6 +2577,7 @@ defcase: *fptr++ = *tmp;
if (locale) {
ast_setlocale(prevlocale);
}
+#endif
ast_free(format);
return res;
}
@@ -2562,11 +2591,22 @@ char *ast_strptime_locale(const char *s,
{
struct tm tm2 = { 0, };
char *res;
+#if !HAVE_STRPTIME_L
const char *prevlocale;
+#endif
+#if HAVE_STRPTIME_L
+ if (locale) {
+ locale_t l = ast_getlocale(locale);
+ res = strptime_l(s, format, &tm2, l);
+ } else {
+ res = strptime(s, format, &tm2);
+ }
+#else
prevlocale = ast_setlocale(locale);
res = strptime(s, format, &tm2);
ast_setlocale(prevlocale);
+#endif
/* ast_time and tm are not the same size - tm is a subset of
* ast_time. Hence, the size of tm needs to be used for the
* memcpy
|