Make sure strftime is always used in C locate
authorJamie Cameron <jcameron@webmin.com>
Fri, 27 Feb 2009 00:21:42 +0000 (00:21 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 27 Feb 2009 00:21:42 +0000 (00:21 +0000)
fsdump/fsdump-lib.pl
mysql/mysql-lib.pl
postgresql/postgresql-lib.pl
web-lib-funcs.pl

index 1f7d8c2..09956f5 100644 (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];
index 72ace89..36f2773 100644 (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];
index c835717..43ee3a2 100644 (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];
index 95b2486..35642d5 100755 (executable)
@@ -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;