Make sure strftime is always used in C locate

This commit is contained in:
Jamie Cameron
2009-02-27 00:21:42 +00:00
parent 4003ce6203
commit 47f2d8a75b
4 changed files with 40 additions and 5 deletions

View File

@@ -107,7 +107,10 @@ if ($config{'date_subs'}) {
eval "use POSIX";
eval "use posix" if ($@);
local @tm = localtime(time());
return strftime($_[0], @tm);
&clear_time_locale();
local $rv = strftime($_[0], @tm);
&reset_time_locale();
return $rv;
}
else {
return $_[0];

View File

@@ -727,7 +727,10 @@ if ($config{'date_subs'}) {
eval "use POSIX";
eval "use posix" if ($@);
local @tm = localtime(time());
return strftime($_[0], @tm);
&clear_time_locale();
local $rv = strftime($_[0], @tm);
&reset_time_locale();
return $rv;
}
else {
return $_[0];

View File

@@ -707,7 +707,10 @@ if ($config{'date_subs'}) {
eval "use POSIX";
eval "use posix" if ($@);
local @tm = localtime(time());
return strftime($_[0], @tm);
&clear_time_locale();
local $rv = strftime($_[0], @tm);
&reset_time_locale();
return $rv;
}
else {
return $_[0];

View File

@@ -8400,16 +8400,16 @@ return &get_module_variable('$module_name');
sub get_module_variable
{
my ($v, $wantref) = @_;
my $slash = $wantref ? "\\" : "";
if (__PACKAGE__ eq 'WebminCore') {
my ($vt, $vn) = split('', $v, 2);
my $callpkg;
for(my $i=0; ($callpkg) = caller($i); $i++) {
last if ($callpkg ne __PACKAGE__);
}
my $slash = $wantref ? "\\" : "";
return eval "${slash}${vt}${callpkg}::${vn}";
}
return eval "$v";
return eval "${slash}${v}";
}
# set_module_variable(name, value)
@@ -8420,6 +8420,32 @@ my ($v, $value) = @_;
# XXX
}
# clear_time_locale()
# Temporarily force the locale to C, until reset_time_locale is called
sub clear_time_locale
{
if ($main::clear_time_locale_count == 0) {
eval {
$main::clear_time_locale_old = POSIX::setlocale(POSIX::LC_TIME);
POSIX::setlocale(POSIX::LC_TIME, "C");
};
}
$main::clear_time_locale_count++;
}
# reset_time_locale()
# Revert the locale to whatever it was before clear_time_locale was called
sub reset_time_locale
{
if ($main::clear_time_locale_count == 1) {
eval {
POSIX::setlocale(POSIX::LC_TIME, $main::clear_time_locale_old);
$main::clear_time_locale_old = undef;
};
}
$main::clear_time_locale_count--;
}
$done_web_lib_funcs = 1;
1;