summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/POSIX/lib/POSIX.pod3
-rw-r--r--locale.c18
2 files changed, 16 insertions, 5 deletions
diff --git a/ext/POSIX/lib/POSIX.pod b/ext/POSIX/lib/POSIX.pod
index 30f224a2f6..c7e9bad2bb 100644
--- a/ext/POSIX/lib/POSIX.pod
+++ b/ext/POSIX/lib/POSIX.pod
@@ -1854,9 +1854,6 @@ The given arguments are made consistent as though by calling
C<mktime()> before calling your system's C<strftime()> function,
except that the C<isdst> value is not affected.
-Note that mojibake can result on some platforms if LC_TIME and LC_CTYPE
-are not the same locale.
-
The string for Tuesday, December 12, 1995.
$str = POSIX::strftime( "%A, %B %d, %Y",
diff --git a/locale.c b/locale.c
index 073897a25a..5b9ca50b3b 100644
--- a/locale.c
+++ b/locale.c
@@ -4867,6 +4867,11 @@ and LC_TIME are not the same locale.
mytm.tm_zone = mytm2.tm_zone;
# endif
#endif
+#if defined(USE_LOCALE_CTYPE) && defined(USE_LOCALE_TIME)
+
+ const char * orig_CTYPE_LOCALE = toggle_locale_c(LC_CTYPE,
+ querylocale_c(LC_TIME));
+#endif
/* Guess an initial size for the returned string based on an expansion
* factor of the input format, but with a minimum that should handle most
@@ -4892,7 +4897,7 @@ and LC_TIME are not the same locale.
* indicates we have at least one byte of spare space (which will be
* used for the terminating NUL). */
if (inRANGE(len, 1, bufsize - 1)) {
- return buf;
+ goto strftime_success;
}
/* There are several possible reasons for a 0 return code for a
@@ -4916,7 +4921,7 @@ and LC_TIME are not the same locale.
if (strEQ(fmt, "%p")) {
Renew(buf, 1, char);
*buf = '\0';
- return buf;
+ goto strftime_success;
}
/* The other reason is that the format string is malformed. Probably it is
@@ -4924,6 +4929,15 @@ and LC_TIME are not the same locale.
Safefree(buf);
return NULL;
+ strftime_success:
+
+#if defined(USE_LOCALE_CTYPE) && defined(USE_LOCALE_TIME)
+
+ restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_LOCALE);
+
+#endif
+ return buf;
+
#else
Perl_croak(aTHX_ "panic: no strftime");
return NULL;