Handle hostnames with upper-case letters
[webmin.git] / time / solaris-lib.pl
1 # Functions for getting and setting the timezone on Linux
2
3 $timezone_file = "/etc/TIMEZONE";
4 $timezones_dir = "/usr/share/lib/zoneinfo";
5 $rtc_config = "/etc/rtc_config";
6
7 # list_timezones()
8 sub list_timezones
9 {
10 local @rv;
11 local $file;
12 &open_execute_command(FIND, "find $timezones_dir -type f", 1);
13 while($file = <FIND>) {
14         chop($file);
15         local $buf;
16         &open_readfile(INFO, $file);
17         read(INFO, $buf, 2);
18         close(INFO);
19         if ($buf eq "TZ") {
20                 # A timezone file we can use!
21                 $file =~ s/^$timezones_dir\///;
22                 push(@rv, [ $file, undef ]);
23                 }
24         }
25 close(FIND);
26 return sort { $a->[0] cmp $b->[0] } @rv;
27 }
28
29 # get_current_timezone()
30 sub get_current_timezone
31 {
32 local %tz;
33 &read_env_file($timezone_file, \%tz);
34 $tz{'TZ'} =~ s/^://;
35 return $tz{'TZ'};
36 }
37
38 # set_current_timezone(zone)
39 sub set_current_timezone
40 {
41 local %tz;
42 &lock_file($timezone_file);
43 &read_env_file($timezone_file, \%tz);
44 $tz{'TZ'} = $_[0];
45 &write_env_file($timezone_file, \%tz);
46 &unlock_file($timezone_file);
47
48 if (-r $rtc_config) {
49         # Update x86 RTC timezone too
50         &lock_file($rtc_config);
51         local %rtc;
52         &read_env_file($rtc_config, \%rtc);
53         $rtc{'zone_info'} = $_[0];
54         &write_env_file($rtc_config, \%rtc);
55         &unlock_file($rtc_config);
56         }
57 }
58
59 sub os_has_timezones
60 {
61 return -r $timezone_file && -d $timezones_dir;
62 }
63
64 sub timezone_files
65 {
66 return ( $timezone_file );
67 }
68
69 1;
70