line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
#include |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
namespace panda { namespace time { |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
|
|
|
static inline bool _from_etc_localtime (char* lzname) { |
7
|
1
|
50
|
|
|
|
|
if (access("/etc/localtime", R_OK) != 0) return false; |
8
|
0
|
|
|
|
|
|
strcpy(lzname, ":/etc/localtime"); |
9
|
0
|
|
|
|
|
|
return true; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
|
static inline bool _from_usr_local_etc_localtime (char* lzname) { |
13
|
1
|
50
|
|
|
|
|
if (access("/usr/local/etc/localtime", R_OK) != 0) return false; |
14
|
0
|
|
|
|
|
|
strcpy(lzname, ":/usr/local/etc/localtime"); |
15
|
0
|
|
|
|
|
|
return true; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
|
static inline bool _from_regex (char* lzname, const char* filename, regex_t* pattern, int nmatch) { |
19
|
2
|
50
|
|
|
|
|
string content = readfile(filename); |
20
|
1
|
50
|
|
|
|
|
if (!content) return false; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
// null-terminate |
23
|
1
|
50
|
|
|
|
|
content.reserve(content.length()+1); |
24
|
1
|
50
|
|
|
|
|
content[content.length()] = 0; |
|
|
50
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
regmatch_t m[10]; |
27
|
1
|
50
|
|
|
|
|
if (regexec(pattern, content.data(), 10, m, 0) != 0) return false; // no match |
|
|
50
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
|
size_t len = m[nmatch].rm_eo - m[nmatch].rm_so; |
30
|
1
|
50
|
|
|
|
|
if (len < 1 || len > TZNAME_MAX) return false; |
|
|
50
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
|
strncpy(lzname, content.data() + m[nmatch].rm_so, len); |
33
|
1
|
|
|
|
|
|
lzname[len] = '\0'; |
34
|
1
|
|
|
|
|
|
return true; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
|
static inline bool _from_etc_timezone (char* lzname) { |
38
|
|
|
|
|
|
|
regex_t pattern; |
39
|
1
|
50
|
|
|
|
|
int err = regcomp(&pattern, "([^[:space:]]+)", REG_EXTENDED|REG_NEWLINE); |
40
|
1
|
50
|
|
|
|
|
assert(err == 0); |
41
|
1
|
50
|
|
|
|
|
return _from_regex(lzname, "/etc/timezone", &pattern, 1); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
static inline bool _from_etc_TIMEZONE (char* lzname) { |
45
|
|
|
|
|
|
|
regex_t pattern; |
46
|
0
|
0
|
|
|
|
|
int err = regcomp(&pattern, "^[[:space:]]*TZ[[:space:]]*=[[:space:]]*([^[:space:]]+)", REG_EXTENDED|REG_NEWLINE); |
47
|
0
|
0
|
|
|
|
|
assert(err == 0); |
48
|
0
|
0
|
|
|
|
|
return _from_regex(lzname, "/etc/TIMEZONE", &pattern, 1); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
static inline bool _from_etc_sysconfig_clock (char* lzname) { |
52
|
|
|
|
|
|
|
regex_t pattern; |
53
|
0
|
0
|
|
|
|
|
int err = regcomp(&pattern, "^[[:space:]]*(TIME)?ZONE[[:space:]]*=[[:space:]]*\"([^\"]+)\"", REG_EXTENDED|REG_NEWLINE); |
54
|
0
|
0
|
|
|
|
|
assert(err == 0); |
55
|
0
|
0
|
|
|
|
|
return _from_regex(lzname, "/etc/sysconfig/clock", &pattern, 2); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
static inline bool _from_etc_default_init (char* lzname) { |
59
|
|
|
|
|
|
|
regex_t pattern; |
60
|
0
|
0
|
|
|
|
|
int err = regcomp(&pattern, "^[[:space:]]*TZ[[:space:]]*=[[:space:]]*([^[:space:]]+)", REG_EXTENDED|REG_NEWLINE); |
61
|
0
|
0
|
|
|
|
|
assert(err == 0); |
62
|
0
|
0
|
|
|
|
|
return _from_regex(lzname, "/etc/default/init", &pattern, 1); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
|
static bool _tz_lzname (char* lzname) { |
66
|
1
|
50
|
|
|
|
|
if ( |
67
|
2
|
50
|
|
|
|
|
_from_etc_localtime(lzname) || |
68
|
2
|
50
|
|
|
|
|
_from_usr_local_etc_localtime(lzname) || |
69
|
1
|
0
|
|
|
|
|
_from_etc_timezone(lzname) || |
70
|
0
|
0
|
|
|
|
|
_from_etc_TIMEZONE(lzname) || |
71
|
2
|
50
|
|
|
|
|
_from_etc_sysconfig_clock(lzname) || |
|
|
0
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
_from_etc_default_init(lzname) |
73
|
1
|
|
|
|
|
|
) return true; |
74
|
0
|
|
|
|
|
|
return false; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
}} |