[BACK]Return to patch-main_stdtime_localtime.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / comms / asterisk16 / patches

File: [cvs.NetBSD.org] / pkgsrc / comms / asterisk16 / patches / patch-main_stdtime_localtime.c (download)

Revision 1.1, Tue Aug 20 13:47:42 2019 UTC (4 years, 7 months ago) by ryoon
Branch: MAIN
CVS Tags: pkgsrc-2024Q1-base, pkgsrc-2024Q1, pkgsrc-2023Q4-base, pkgsrc-2023Q4, pkgsrc-2023Q3-base, pkgsrc-2023Q3, pkgsrc-2023Q2-base, pkgsrc-2023Q2, pkgsrc-2023Q1-base, pkgsrc-2023Q1, pkgsrc-2022Q4-base, pkgsrc-2022Q4, pkgsrc-2022Q3-base, pkgsrc-2022Q3, pkgsrc-2022Q2-base, pkgsrc-2022Q2, pkgsrc-2022Q1-base, pkgsrc-2022Q1, pkgsrc-2021Q4-base, pkgsrc-2021Q4, pkgsrc-2021Q3-base, pkgsrc-2021Q3, pkgsrc-2021Q2-base, pkgsrc-2021Q2, pkgsrc-2021Q1-base, pkgsrc-2021Q1, pkgsrc-2020Q4-base, pkgsrc-2020Q4, pkgsrc-2020Q3-base, pkgsrc-2020Q3, pkgsrc-2020Q2-base, pkgsrc-2020Q2, pkgsrc-2020Q1-base, pkgsrc-2020Q1, pkgsrc-2019Q4-base, pkgsrc-2019Q4, pkgsrc-2019Q3-base, pkgsrc-2019Q3, HEAD

comms/asterisk16: import asterisk-16.5.0

Asterisk is a complete PBX in software.  It provides all of the
features you would expect from a PBX and more. Asterisk does voice
over IP in three protocols, and can interoperate with almost all
standards-based telephony equipment using relatively inexpensive
hardware.

Asterisk provides Voicemail services with Directory, Call Conferencing,
Interactive Voice Response, Call Queuing. It has support for
three-way calling, caller ID services, ADSI, SIP and H.323 (as both
client and gateway).

$NetBSD: patch-main_stdtime_localtime.c,v 1.1 2019/08/20 13:47:42 ryoon Exp $

--- main/stdtime/localtime.c.orig	2018-05-01 20:12:26.000000000 +0000
+++ main/stdtime/localtime.c
@@ -65,6 +65,10 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #endif
+#ifdef __sun
+#include <time.h>
+#include <xlocale.h>
+#endif
 
 #include "private.h"
 #include "tzfile.h"
@@ -74,6 +78,7 @@
 #include "asterisk/localtime.h"
 #include "asterisk/strings.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/autoconfig.h"
 #include "asterisk/utils.h"
 #include "asterisk/test.h"
 
@@ -310,7 +315,7 @@ static struct state *	sstate_alloc(void)
 static void		sstate_free(struct state *p);
 
 static AST_LIST_HEAD_STATIC(zonelist, state);
-#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE)
+#if defined(HAVE_NEWLOCALE) && (defined(HAVE_USELOCALE) || HAVE_STRFTIME_L || HAVE_STRPTIME_L)
 static AST_LIST_HEAD_STATIC(localelist, locale_entry);
 #endif
 
@@ -2362,7 +2367,8 @@ struct timeval ast_mktime(struct ast_tm 
 	return time1(tmp, localsub, 0L, sp);
 }
 
-#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE)
+#if defined(HAVE_NEWLOCALE) && (defined(HAVE_USELOCALE) || HAVE_STRFTIME_L || HAVE_STRPTIME_L)
+#if defined HAVE_USELOCALE
 static struct locale_entry *find_by_locale(locale_t locale)
 {
 	struct locale_entry *cur;
@@ -2373,6 +2379,7 @@ static struct locale_entry *find_by_loca
 	}
 	return NULL;
 }
+#endif
 
 static struct locale_entry *find_by_name(const char *name)
 {
@@ -2385,6 +2392,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;
@@ -2442,6 +2466,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)
 {
@@ -2455,7 +2480,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) {
@@ -2510,6 +2537,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);
 	}
@@ -2517,6 +2552,7 @@ defcase:	*fptr++ = *tmp;
 	if (locale) {
 		ast_setlocale(prevlocale);
 	}
+#endif
 	ast_free(format);
 	return res;
 }
@@ -2530,11 +2566,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