From 17ba3f1d5dd3bda8d0ed592ae9b211bb6fe81fcb Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Wed, 27 Nov 2019 22:32:53 -0700 Subject: [PATCH] POSIX/t/time.t: Reset LC_CTYPE to C The C standard says about the format in strftime(): "The format shall be a multibyte character sequence, beginning and ending in its initial shift state" Tony Cook and I interpret that as meaning that to be sure, not only does LC_TIME have to be reset, but LC_CTYPE to account for all possible variations in these tests. --- ext/POSIX/t/time.t | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ext/POSIX/t/time.t b/ext/POSIX/t/time.t index 4b10eb8..b19ed70 100644 --- a/ext/POSIX/t/time.t +++ b/ext/POSIX/t/time.t @@ -52,11 +52,16 @@ is(asctime(POSIX::localtime(12345678)), ctime(12345678), "asctime() and ctime() at 12345678"); # Careful! strftime() is locale sensitive. Let's take care of that -my $orig_loc = 'C'; +my $orig_time_loc = 'C'; +my $orig_ctype_loc = 'C'; if (locales_enabled('LC_TIME')) { - $orig_loc = setlocale(LC_TIME) || die "Cannot get locale information: $!"; + $orig_time_loc = setlocale(LC_TIME) || die "Cannot get time locale information: $!"; setlocale(LC_TIME, "C") || die "Cannot setlocale() to C: $!"; } +if (locales_enabled('LC_CTYPE')) { + $orig_ctype_loc = setlocale(LC_CTYPE) || die "Cannot get ctype locale information: $!"; + setlocale(LC_CTYPE, "C") || die "Cannot setlocale() to C: $!"; +} my $jan_16 = 15 * 86400; is(ctime($jan_16), strftime("%a %b %d %H:%M:%S %Y\n", CORE::localtime($jan_16)), "get ctime() equal to strftime()"); @@ -78,7 +83,10 @@ is(ord strftime($ss, POSIX::localtime(time)), unlike($ss, qr/\w/, 'Still not internally UTF-8 encoded'); if (locales_enabled('LC_TIME')) { - setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!"; + setlocale(LC_TIME, $orig_time_loc) || die "Cannot setlocale(LC_TIME) back to orig: $!"; +} +if (locales_enabled('LC_CTYPE')) { + setlocale(LC_TIME, $orig_ctype_loc) || die "Cannot setlocale(LC_CTYPE) back to orig: $!"; } # clock() seems to have different definitions of what it does between POSIX -- 1.8.3.1