Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/utimecmp.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | enum { SYSCALL_RESOLUTION = 1 }; | - | ||||||||||||||||||
5 | struct fs_res | - | ||||||||||||||||||
6 | { | - | ||||||||||||||||||
7 | - | |||||||||||||||||||
8 | dev_t dev; | - | ||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | - | |||||||||||||||||||
15 | int resolution; | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | - | |||||||||||||||||||
18 | - | |||||||||||||||||||
19 | - | |||||||||||||||||||
20 | _Bool | - | ||||||||||||||||||
21 | exact; | - | ||||||||||||||||||
22 | }; | - | ||||||||||||||||||
23 | - | |||||||||||||||||||
24 | - | |||||||||||||||||||
25 | static size_t | - | ||||||||||||||||||
26 | dev_info_hash (void const *x, size_t table_size) | - | ||||||||||||||||||
27 | { | - | ||||||||||||||||||
28 | struct fs_res const *p = x; | - | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | - | |||||||||||||||||||
31 | if ((
| 0-4 | ||||||||||||||||||
32 | (
| 0 | ||||||||||||||||||
33 | < ((0x7fffffff) > (((dev_t) (! (! ((dev_t) 0 < (dev_t) -1)) ? (dev_t) -1 : ((((dev_t) 1 << ((sizeof (dev_t) * 8) - 2)) - 1) * 2 + 1)))) ? (0x7fffffff) : (((dev_t) (! (! ((dev_t) 0 < (dev_t) -1)) ? (dev_t) -1 : ((((dev_t) 1 << ((sizeof (dev_t) * 8) - 2)) - 1) * 2 + 1)))))
| 0 | ||||||||||||||||||
34 | { | - | ||||||||||||||||||
35 | uintmax_t dev = p->dev; | - | ||||||||||||||||||
36 | return never executed: dev % table_size;return dev % table_size; never executed: return dev % table_size; | 0 | ||||||||||||||||||
37 | } | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | return executed 4 times by 1 test: p->dev % table_size;return p->dev % table_size; Executed by:
executed 4 times by 1 test: return p->dev % table_size; Executed by:
| 4 | ||||||||||||||||||
40 | } | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | - | |||||||||||||||||||
43 | static | - | ||||||||||||||||||
44 | _Bool | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | dev_info_compare (void const *x, void const *y) | - | ||||||||||||||||||
47 | { | - | ||||||||||||||||||
48 | struct fs_res const *a = x; | - | ||||||||||||||||||
49 | struct fs_res const *b = y; | - | ||||||||||||||||||
50 | return executed 2 times by 1 test: a->dev == b->dev;return a->dev == b->dev; Executed by:
executed 2 times by 1 test: return a->dev == b->dev; Executed by:
| 2 | ||||||||||||||||||
51 | } | - | ||||||||||||||||||
52 | int | - | ||||||||||||||||||
53 | utimecmp (char const *dst_name, | - | ||||||||||||||||||
54 | struct stat const *dst_stat, | - | ||||||||||||||||||
55 | struct stat const *src_stat, | - | ||||||||||||||||||
56 | int options) | - | ||||||||||||||||||
57 | { | - | ||||||||||||||||||
58 | return executed 16 times by 2 tests: utimecmpat (return utimecmpat ( -100 , dst_name, dst_stat, src_stat, options); Executed by:
executed 16 times by 2 tests: return utimecmpat ( -100 , dst_name, dst_stat, src_stat, options); Executed by:
| 16 | ||||||||||||||||||
59 | -100 executed 16 times by 2 tests: return utimecmpat ( -100 , dst_name, dst_stat, src_stat, options); Executed by:
| 16 | ||||||||||||||||||
60 | , dst_name, dst_stat, src_stat, options); executed 16 times by 2 tests: return utimecmpat ( -100 , dst_name, dst_stat, src_stat, options); Executed by:
| 16 | ||||||||||||||||||
61 | } | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | int | - | ||||||||||||||||||
64 | utimecmpat (int dfd, char const *dst_name, | - | ||||||||||||||||||
65 | struct stat const *dst_stat, | - | ||||||||||||||||||
66 | struct stat const *src_stat, | - | ||||||||||||||||||
67 | int options) | - | ||||||||||||||||||
68 | { | - | ||||||||||||||||||
69 | _Static_assert (((time_t) 1.5 == 1), "verify (" "TYPE_IS_INTEGER (time_t)" ")"); | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | - | |||||||||||||||||||
72 | time_t dst_s = dst_stat-> | - | ||||||||||||||||||
73 | st_mtim.tv_sec | - | ||||||||||||||||||
74 | ; | - | ||||||||||||||||||
75 | time_t src_s = src_stat-> | - | ||||||||||||||||||
76 | st_mtim.tv_sec | - | ||||||||||||||||||
77 | ; | - | ||||||||||||||||||
78 | int dst_ns = get_stat_mtime_ns (dst_stat); | - | ||||||||||||||||||
79 | int src_ns = get_stat_mtime_ns (src_stat); | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | if (options & UTIMECMP_TRUNCATE_SOURCE
| 8 | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | - | |||||||||||||||||||
85 | - | |||||||||||||||||||
86 | static Hash_table *ht; | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | - | |||||||||||||||||||
89 | static struct fs_res *new_dst_res; | - | ||||||||||||||||||
90 | struct fs_res *dst_res = | - | ||||||||||||||||||
91 | ((void *)0) | - | ||||||||||||||||||
92 | ; | - | ||||||||||||||||||
93 | struct fs_res tmp_dst_res; | - | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | - | |||||||||||||||||||
96 | int res; | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | - | |||||||||||||||||||
99 | - | |||||||||||||||||||
100 | - | |||||||||||||||||||
101 | if (dst_s == src_s
| 0-4 | ||||||||||||||||||
102 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
103 | if (dst_s <= src_s - 2
| 2-6 | ||||||||||||||||||
104 | return executed 2 times by 1 test: -1;return -1; Executed by:
executed 2 times by 1 test: return -1; Executed by:
| 2 | ||||||||||||||||||
105 | if (src_s <= dst_s - 2
| 2-4 | ||||||||||||||||||
106 | return executed 2 times by 1 test: 1;return 1; Executed by:
executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | - | |||||||||||||||||||
109 | - | |||||||||||||||||||
110 | if (! ht
| 2 | ||||||||||||||||||
111 | ht = hash_initialize (16, executed 2 times by 1 test: ht = hash_initialize (16, ((void *)0) , dev_info_hash, dev_info_compare, free); Executed by:
| 2 | ||||||||||||||||||
112 | ((void *)0) executed 2 times by 1 test: ht = hash_initialize (16, ((void *)0) , dev_info_hash, dev_info_compare, free); Executed by:
| 2 | ||||||||||||||||||
113 | , dev_info_hash, dev_info_compare, free); executed 2 times by 1 test: ht = hash_initialize (16, ((void *)0) , dev_info_hash, dev_info_compare, free); Executed by:
| 2 | ||||||||||||||||||
114 | if (ht
| 0-4 | ||||||||||||||||||
115 | { | - | ||||||||||||||||||
116 | if (! new_dst_res
| 0-4 | ||||||||||||||||||
117 | { | - | ||||||||||||||||||
118 | new_dst_res = malloc (sizeof *new_dst_res); | - | ||||||||||||||||||
119 | if (!new_dst_res
| 0-4 | ||||||||||||||||||
120 | goto never executed: low_memory;goto low_memory; never executed: goto low_memory; | 0 | ||||||||||||||||||
121 | new_dst_res->resolution = 2 * (1000 * 1000 * 1000); | - | ||||||||||||||||||
122 | new_dst_res->exact = | - | ||||||||||||||||||
123 | 0 | - | ||||||||||||||||||
124 | ; | - | ||||||||||||||||||
125 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
126 | new_dst_res->dev = dst_stat->st_dev; | - | ||||||||||||||||||
127 | dst_res = hash_insert (ht, new_dst_res); | - | ||||||||||||||||||
128 | if (! dst_res
| 0-4 | ||||||||||||||||||
129 | goto never executed: low_memory;goto low_memory; never executed: goto low_memory; | 0 | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | if (dst_res == new_dst_res
| 2 | ||||||||||||||||||
132 | { | - | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | - | |||||||||||||||||||
135 | new_dst_res = | - | ||||||||||||||||||
136 | ((void *)0) | - | ||||||||||||||||||
137 | ; | - | ||||||||||||||||||
138 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
139 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
140 | else | - | ||||||||||||||||||
141 | { | - | ||||||||||||||||||
142 | low_memory: | - | ||||||||||||||||||
143 | if (ht
| 0 | ||||||||||||||||||
144 | { | - | ||||||||||||||||||
145 | tmp_dst_res.dev = dst_stat->st_dev; | - | ||||||||||||||||||
146 | dst_res = hash_lookup (ht, &tmp_dst_res); | - | ||||||||||||||||||
147 | } never executed: end of block | 0 | ||||||||||||||||||
148 | if (!dst_res
| 0 | ||||||||||||||||||
149 | { | - | ||||||||||||||||||
150 | dst_res = &tmp_dst_res; | - | ||||||||||||||||||
151 | dst_res->resolution = 2 * (1000 * 1000 * 1000); | - | ||||||||||||||||||
152 | dst_res->exact = | - | ||||||||||||||||||
153 | 0 | - | ||||||||||||||||||
154 | ; | - | ||||||||||||||||||
155 | } never executed: end of block | 0 | ||||||||||||||||||
156 | } never executed: end of block | 0 | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | res = dst_res->resolution; | - | ||||||||||||||||||
159 | if (! dst_res->exact
| 2 | ||||||||||||||||||
160 | { | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | - | |||||||||||||||||||
163 | - | |||||||||||||||||||
164 | time_t dst_a_s = dst_stat-> | - | ||||||||||||||||||
165 | st_atim.tv_sec | - | ||||||||||||||||||
166 | ; | - | ||||||||||||||||||
167 | time_t dst_c_s = dst_stat-> | - | ||||||||||||||||||
168 | st_ctim.tv_sec | - | ||||||||||||||||||
169 | ; | - | ||||||||||||||||||
170 | time_t dst_m_s = dst_s; | - | ||||||||||||||||||
171 | int dst_a_ns = get_stat_atime_ns (dst_stat); | - | ||||||||||||||||||
172 | int dst_c_ns = get_stat_ctime_ns (dst_stat); | - | ||||||||||||||||||
173 | int dst_m_ns = dst_ns; | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | - | |||||||||||||||||||
176 | - | |||||||||||||||||||
177 | - | |||||||||||||||||||
178 | - | |||||||||||||||||||
179 | - | |||||||||||||||||||
180 | - | |||||||||||||||||||
181 | { | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | _Bool | - | ||||||||||||||||||
184 | odd_second = (dst_a_s | dst_c_s | dst_m_s) & 1; | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | if (SYSCALL_RESOLUTION == (1000 * 1000 * 1000)
| 0-2 | ||||||||||||||||||
187 | { | - | ||||||||||||||||||
188 | if (odd_second | dst_a_ns | dst_c_ns | dst_m_ns
| 0 | ||||||||||||||||||
189 | res = (1000 * 1000 * 1000); never executed: res = (1000 * 1000 * 1000); | 0 | ||||||||||||||||||
190 | } never executed: end of block | 0 | ||||||||||||||||||
191 | else | - | ||||||||||||||||||
192 | { | - | ||||||||||||||||||
193 | int a = dst_a_ns; | - | ||||||||||||||||||
194 | int c = dst_c_ns; | - | ||||||||||||||||||
195 | int m = dst_m_ns; | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | - | |||||||||||||||||||
198 | - | |||||||||||||||||||
199 | int SR10 = SYSCALL_RESOLUTION; SR10 *= 10; | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | if ((
| 0-2 | ||||||||||||||||||
202 | res = SYSCALL_RESOLUTION; executed 2 times by 1 test: res = SYSCALL_RESOLUTION; Executed by:
| 2 | ||||||||||||||||||
203 | else | - | ||||||||||||||||||
204 | for (res = SR10, a /= SR10, c /= SR10, m /= SR10; | - | ||||||||||||||||||
205 | (res < dst_res->resolution
| 0 | ||||||||||||||||||
206 | && (
| 0 | ||||||||||||||||||
207 | res *= 10, a /= 10, c /= 10, m /= 10) | - | ||||||||||||||||||
208 | if (res == (1000 * 1000 * 1000)
| 0 | ||||||||||||||||||
209 | { | - | ||||||||||||||||||
210 | if (! odd_second
| 0 | ||||||||||||||||||
211 | res *= 2; never executed: res *= 2; | 0 | ||||||||||||||||||
212 | break; never executed: break; | 0 | ||||||||||||||||||
213 | } | - | ||||||||||||||||||
214 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | dst_res->resolution = res; | - | ||||||||||||||||||
217 | } | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | if (SYSCALL_RESOLUTION < res
| 0-2 | ||||||||||||||||||
220 | { | - | ||||||||||||||||||
221 | struct timespec timespec[2]; | - | ||||||||||||||||||
222 | struct stat dst_status; | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | - | |||||||||||||||||||
225 | - | |||||||||||||||||||
226 | src_ns -= src_ns % SYSCALL_RESOLUTION; | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | - | |||||||||||||||||||
229 | - | |||||||||||||||||||
230 | - | |||||||||||||||||||
231 | { | - | ||||||||||||||||||
232 | time_t s = src_s & ~ (res == 2 * (1000 * 1000 * 1000) ? 1 : 0); | - | ||||||||||||||||||
233 | if (src_s < dst_s
| 0 | ||||||||||||||||||
234 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
235 | if (dst_s < s
| 0 | ||||||||||||||||||
236 | || (dst_s == s
| 0 | ||||||||||||||||||
237 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
238 | } | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | - | |||||||||||||||||||
241 | - | |||||||||||||||||||
242 | - | |||||||||||||||||||
243 | - | |||||||||||||||||||
244 | - | |||||||||||||||||||
245 | - | |||||||||||||||||||
246 | timespec[0].tv_sec = dst_a_s; | - | ||||||||||||||||||
247 | timespec[0].tv_nsec = dst_a_ns; | - | ||||||||||||||||||
248 | timespec[1].tv_sec = dst_m_s | (res == 2 * (1000 * 1000 * 1000)); | - | ||||||||||||||||||
249 | timespec[1].tv_nsec = dst_m_ns + res / 9; | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | if (utimensat (dfd, dst_name, timespec,
| 0 | ||||||||||||||||||
252 | 0x100
| 0 | ||||||||||||||||||
253 | )
| 0 | ||||||||||||||||||
254 | return never executed: -2;return -2; never executed: return -2; | 0 | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | - | |||||||||||||||||||
257 | { | - | ||||||||||||||||||
258 | int stat_result | - | ||||||||||||||||||
259 | = fstatat (dfd, dst_name, &dst_status, | - | ||||||||||||||||||
260 | 0x100 | - | ||||||||||||||||||
261 | ); | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | if (stat_result
| 0 | ||||||||||||||||||
264 | | (dst_status.
| 0 | ||||||||||||||||||
265 | st_mtim.tv_sec
| 0 | ||||||||||||||||||
266 | ^ dst_m_s)
| 0 | ||||||||||||||||||
267 | | (get_stat_mtime_ns (&dst_status) ^ dst_m_ns)
| 0 | ||||||||||||||||||
268 | { | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | - | |||||||||||||||||||
271 | timespec[1].tv_sec = dst_m_s; | - | ||||||||||||||||||
272 | timespec[1].tv_nsec = dst_m_ns; | - | ||||||||||||||||||
273 | utimensat (dfd, dst_name, timespec, | - | ||||||||||||||||||
274 | 0x100 | - | ||||||||||||||||||
275 | ); | - | ||||||||||||||||||
276 | } never executed: end of block | 0 | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | if (stat_result != 0
| 0 | ||||||||||||||||||
279 | return never executed: -2;return -2; never executed: return -2; | 0 | ||||||||||||||||||
280 | } | - | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | - | |||||||||||||||||||
283 | - | |||||||||||||||||||
284 | { | - | ||||||||||||||||||
285 | int old_res = res; | - | ||||||||||||||||||
286 | int a = ((1000 * 1000 * 1000) * (dst_status. | - | ||||||||||||||||||
287 | st_mtim.tv_sec | - | ||||||||||||||||||
288 | & 1) | - | ||||||||||||||||||
289 | + get_stat_mtime_ns (&dst_status)); | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | res = SYSCALL_RESOLUTION; | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | for (a /= res; a % 10 == 0
| 0 | ||||||||||||||||||
294 | { | - | ||||||||||||||||||
295 | if (res == (1000 * 1000 * 1000)
| 0 | ||||||||||||||||||
296 | { | - | ||||||||||||||||||
297 | res *= 2; | - | ||||||||||||||||||
298 | break; never executed: break; | 0 | ||||||||||||||||||
299 | } | - | ||||||||||||||||||
300 | res *= 10; | - | ||||||||||||||||||
301 | if (res == old_res
| 0 | ||||||||||||||||||
302 | break; never executed: break; | 0 | ||||||||||||||||||
303 | } never executed: end of block | 0 | ||||||||||||||||||
304 | } | - | ||||||||||||||||||
305 | } never executed: end of block | 0 | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | dst_res->resolution = res; | - | ||||||||||||||||||
308 | dst_res->exact = | - | ||||||||||||||||||
309 | 1 | - | ||||||||||||||||||
310 | ; | - | ||||||||||||||||||
311 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | - | |||||||||||||||||||
314 | src_s &= ~ (res == 2 * (1000 * 1000 * 1000) ? 1 : 0); | - | ||||||||||||||||||
315 | src_ns -= src_ns % res; | - | ||||||||||||||||||
316 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | - | |||||||||||||||||||
319 | return executed 12 times by 2 tests: (dst_s < src_s ? -1return (dst_s < src_s ? -1 : dst_s > src_s ? 1 : dst_ns < src_ns ? -1 : dst_ns > src_ns); Executed by:
executed 12 times by 2 tests: return (dst_s < src_s ? -1 : dst_s > src_s ? 1 : dst_ns < src_ns ? -1 : dst_ns > src_ns); Executed by:
| 12 | ||||||||||||||||||
320 | : dst_s > src_s ? 1 executed 12 times by 2 tests: return (dst_s < src_s ? -1 : dst_s > src_s ? 1 : dst_ns < src_ns ? -1 : dst_ns > src_ns); Executed by:
| 12 | ||||||||||||||||||
321 | : dst_ns < src_ns ? -1 executed 12 times by 2 tests: return (dst_s < src_s ? -1 : dst_s > src_s ? 1 : dst_ns < src_ns ? -1 : dst_ns > src_ns); Executed by:
| 12 | ||||||||||||||||||
322 | : dst_ns > src_ns); executed 12 times by 2 tests: return (dst_s < src_s ? -1 : dst_s > src_s ? 1 : dst_ns < src_ns ? -1 : dst_ns > src_ns); Executed by:
| 12 | ||||||||||||||||||
323 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |