Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/posixtm.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | static | - | ||||||||||||||||||||||||
7 | _Bool | - | ||||||||||||||||||||||||
8 | - | |||||||||||||||||||||||||
9 | year (struct tm *tm, const int *digit_pair, size_t n, unsigned int syntax_bits) | - | ||||||||||||||||||||||||
10 | { | - | ||||||||||||||||||||||||
11 | switch (n) | - | ||||||||||||||||||||||||
12 | { | - | ||||||||||||||||||||||||
13 | case executed 1 time by 1 test: 1:case 1: Executed by:
executed 1 time by 1 test: case 1: Executed by:
| 1 | ||||||||||||||||||||||||
14 | tm->tm_year = *digit_pair; | - | ||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||
16 | - | |||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||
18 | if (digit_pair[0] <= 68
| 0-1 | ||||||||||||||||||||||||
19 | { | - | ||||||||||||||||||||||||
20 | if (syntax_bits & 8
| 0-1 | ||||||||||||||||||||||||
21 | return executed 1 time by 1 test: return 0 ; Executed by:
executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
22 | 0 executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
23 | ; executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
24 | tm->tm_year += 100; | - | ||||||||||||||||||||||||
25 | } never executed: end of block | 0 | ||||||||||||||||||||||||
26 | break; never executed: break; | 0 | ||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||
28 | case executed 2 times by 1 test: 2:case 2: Executed by:
executed 2 times by 1 test: case 2: Executed by:
| 2 | ||||||||||||||||||||||||
29 | if (! (syntax_bits & 2)
| 0-2 | ||||||||||||||||||||||||
30 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
31 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
32 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
33 | tm->tm_year = digit_pair[0] * 100 + digit_pair[1] - 1900; | - | ||||||||||||||||||||||||
34 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | case executed 4 times by 1 test: 0:case 0: Executed by:
executed 4 times by 1 test: case 0: Executed by:
| 4 | ||||||||||||||||||||||||
37 | { | - | ||||||||||||||||||||||||
38 | time_t now; | - | ||||||||||||||||||||||||
39 | struct tm *tmp; | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | time (&now); | - | ||||||||||||||||||||||||
43 | tmp = localtime (&now); | - | ||||||||||||||||||||||||
44 | if (! tmp
| 0-4 | ||||||||||||||||||||||||
45 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
46 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
47 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
48 | tm->tm_year = tmp->tm_year; | - | ||||||||||||||||||||||||
49 | } | - | ||||||||||||||||||||||||
50 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
53 | abort (); never executed: abort (); | 0 | ||||||||||||||||||||||||
54 | } | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | return executed 6 times by 1 test: return 1 ; Executed by:
executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
57 | 1 executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
58 | ; executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
59 | } | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | static | - | ||||||||||||||||||||||||
62 | _Bool | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) | - | ||||||||||||||||||||||||
65 | { | - | ||||||||||||||||||||||||
66 | const char *dot = | - | ||||||||||||||||||||||||
67 | ((void *)0) | - | ||||||||||||||||||||||||
68 | ; | - | ||||||||||||||||||||||||
69 | int pair[6]; | - | ||||||||||||||||||||||||
70 | int *p; | - | ||||||||||||||||||||||||
71 | size_t i; | - | ||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||
73 | size_t s_len = strlen (s); | - | ||||||||||||||||||||||||
74 | size_t len = s_len; | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | if (syntax_bits & 4
| 3-5 | ||||||||||||||||||||||||
77 | { | - | ||||||||||||||||||||||||
78 | dot = | - | ||||||||||||||||||||||||
79 | (__extension__ (__builtin_constant_p (
| 0-3 | ||||||||||||||||||||||||
80 | '.'
| 0-3 | ||||||||||||||||||||||||
81 | )
| 0-3 | ||||||||||||||||||||||||
82 | s
| 0-3 | ||||||||||||||||||||||||
83 | )
| 0-3 | ||||||||||||||||||||||||
84 | '.'
| 0-3 | ||||||||||||||||||||||||
85 | ) == '\0'
| 0-3 | ||||||||||||||||||||||||
86 | s | - | ||||||||||||||||||||||||
87 | , | - | ||||||||||||||||||||||||
88 | '.' | - | ||||||||||||||||||||||||
89 | ) : __builtin_strchr ( | - | ||||||||||||||||||||||||
90 | s | - | ||||||||||||||||||||||||
91 | , | - | ||||||||||||||||||||||||
92 | '.' | - | ||||||||||||||||||||||||
93 | ))) | - | ||||||||||||||||||||||||
94 | ; | - | ||||||||||||||||||||||||
95 | if (dot
| 1-2 | ||||||||||||||||||||||||
96 | { | - | ||||||||||||||||||||||||
97 | len = dot - s; | - | ||||||||||||||||||||||||
98 | if (s_len - len != 3
| 0-2 | ||||||||||||||||||||||||
99 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
100 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
101 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
102 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
103 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | if (! (8 <= len
| 0-7 | ||||||||||||||||||||||||
106 | return executed 1 time by 1 test: return 0 ; Executed by:
executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
107 | 0 executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
108 | ; executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||
110 | for (i = 0; i < len
| 7-66 | ||||||||||||||||||||||||
111 | if (!((unsigned int) (s[i]) - '0' <= 9)
| 0-66 | ||||||||||||||||||||||||
112 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
113 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
114 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | len /= 2; | - | ||||||||||||||||||||||||
117 | for (i = 0; i < len
| 7-33 | ||||||||||||||||||||||||
118 | pair[i] = 10 * (s[2*i] - '0') + s[2*i + 1] - '0'; executed 33 times by 1 test: pair[i] = 10 * (s[2*i] - '0') + s[2*i + 1] - '0'; Executed by:
| 33 | ||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||
120 | p = pair; | - | ||||||||||||||||||||||||
121 | if (! (syntax_bits & 1)
| 2-5 | ||||||||||||||||||||||||
122 | { | - | ||||||||||||||||||||||||
123 | if (! year (tm, p, len - 4, syntax_bits)
| 0-2 | ||||||||||||||||||||||||
124 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
125 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
126 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
127 | p += len - 4; | - | ||||||||||||||||||||||||
128 | len = 4; | - | ||||||||||||||||||||||||
129 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | - | |||||||||||||||||||||||||
132 | tm->tm_mon = *p++ - 1; | - | ||||||||||||||||||||||||
133 | tm->tm_mday = *p++; | - | ||||||||||||||||||||||||
134 | tm->tm_hour = *p++; | - | ||||||||||||||||||||||||
135 | tm->tm_min = *p++; | - | ||||||||||||||||||||||||
136 | len -= 4; | - | ||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||
138 | - | |||||||||||||||||||||||||
139 | if (syntax_bits & 1
| 2-5 | ||||||||||||||||||||||||
140 | { | - | ||||||||||||||||||||||||
141 | if (! year (tm, p, len, syntax_bits)
| 1-4 | ||||||||||||||||||||||||
142 | return executed 1 time by 1 test: return 0 ; Executed by:
executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
143 | 0 executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
144 | ; executed 1 time by 1 test: return 0 ; Executed by:
| 1 | ||||||||||||||||||||||||
145 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | if (!dot
| 2-4 | ||||||||||||||||||||||||
149 | tm->tm_sec = 0; executed 4 times by 1 test: tm->tm_sec = 0; Executed by:
| 4 | ||||||||||||||||||||||||
150 | else if (((
| 0-2 | ||||||||||||||||||||||||
151 | tm->tm_sec = 10 * (dot[1] - '0') + dot[2] - '0'; executed 2 times by 1 test: tm->tm_sec = 10 * (dot[1] - '0') + dot[2] - '0'; Executed by:
| 2 | ||||||||||||||||||||||||
152 | else | - | ||||||||||||||||||||||||
153 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
154 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
155 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | return executed 6 times by 1 test: return 1 ; Executed by:
executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
158 | 1 executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
159 | ; executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
160 | } | - | ||||||||||||||||||||||||
161 | - | |||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||
165 | _Bool | - | ||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||
167 | posixtime (time_t *p, const char *s, unsigned int syntax_bits) | - | ||||||||||||||||||||||||
168 | { | - | ||||||||||||||||||||||||
169 | struct tm tm0; | - | ||||||||||||||||||||||||
170 | struct tm tm1; | - | ||||||||||||||||||||||||
171 | struct tm const *tm; | - | ||||||||||||||||||||||||
172 | time_t t; | - | ||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | if (! posix_time_parse (&tm0, s, syntax_bits)
| 2-6 | ||||||||||||||||||||||||
175 | return executed 2 times by 1 test: return 0 ; Executed by:
executed 2 times by 1 test: return 0 ; Executed by:
| 2 | ||||||||||||||||||||||||
176 | 0 executed 2 times by 1 test: return 0 ; Executed by:
| 2 | ||||||||||||||||||||||||
177 | ; executed 2 times by 1 test: return 0 ; Executed by:
| 2 | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | tm1.tm_sec = tm0.tm_sec; | - | ||||||||||||||||||||||||
180 | tm1.tm_min = tm0.tm_min; | - | ||||||||||||||||||||||||
181 | tm1.tm_hour = tm0.tm_hour; | - | ||||||||||||||||||||||||
182 | tm1.tm_mday = tm0.tm_mday; | - | ||||||||||||||||||||||||
183 | tm1.tm_mon = tm0.tm_mon; | - | ||||||||||||||||||||||||
184 | tm1.tm_year = tm0.tm_year; | - | ||||||||||||||||||||||||
185 | tm1.tm_isdst = -1; | - | ||||||||||||||||||||||||
186 | t = mktime (&tm1); | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | if (t != (time_t) -1
| 0-6 | ||||||||||||||||||||||||
189 | tm = &tm1; executed 6 times by 1 test: tm = &tm1; Executed by:
| 6 | ||||||||||||||||||||||||
190 | else | - | ||||||||||||||||||||||||
191 | { | - | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | tm = localtime (&t); | - | ||||||||||||||||||||||||
195 | if (! tm
| 0 | ||||||||||||||||||||||||
196 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
197 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
198 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
199 | } never executed: end of block | 0 | ||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | if ((
| 1-5 | ||||||||||||||||||||||||
206 | | (tm0.tm_mon ^ tm->tm_mon)
| 1-5 | ||||||||||||||||||||||||
207 | | (tm0.tm_mday ^ tm->tm_mday)
| 1-5 | ||||||||||||||||||||||||
208 | | (tm0.tm_hour ^ tm->tm_hour)
| 1-5 | ||||||||||||||||||||||||
209 | | (tm0.tm_min ^ tm->tm_min)
| 1-5 | ||||||||||||||||||||||||
210 | | (tm0.tm_sec ^ tm->tm_sec)
| 1-5 | ||||||||||||||||||||||||
211 | { | - | ||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||
213 | if (tm0.tm_sec != 60
| 0-1 | ||||||||||||||||||||||||
214 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
215 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
216 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||
218 | { | - | ||||||||||||||||||||||||
219 | - | |||||||||||||||||||||||||
220 | time_t dummy; | - | ||||||||||||||||||||||||
221 | char buf[16]; | - | ||||||||||||||||||||||||
222 | char *b = stpcpy (buf, s); | - | ||||||||||||||||||||||||
223 | strcpy (b - 2, "59"); | - | ||||||||||||||||||||||||
224 | if (!posixtime (&dummy, buf, syntax_bits)
| 0-1 | ||||||||||||||||||||||||
225 | return never executed: return 0 ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
226 | 0 never executed: return 0 ; | 0 | ||||||||||||||||||||||||
227 | ; never executed: return 0 ; | 0 | ||||||||||||||||||||||||
228 | } | - | ||||||||||||||||||||||||
229 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||
231 | *p = t; | - | ||||||||||||||||||||||||
232 | return executed 6 times by 1 test: return 1 ; Executed by:
executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
233 | 1 executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
234 | ; executed 6 times by 1 test: return 1 ; Executed by:
| 6 | ||||||||||||||||||||||||
235 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |