Mercurial > hg > octave-shane > gnulib-hg
comparison lib/utimecmp.c @ 6238:245950d70306
* utimecmp.c: Include stat-time.h.
(SYSCALL_RESOLUTION): Depend on whether various struct stat
members exist, not on the obsolescent ST_MTIM_NSEC.
(utimecmp): Use the new stat-time functions rater than TIMESPEC_NS.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 16 Sep 2005 07:16:21 +0000 |
parents | a48fb0e98c8c |
children | 96c32553b4c6 |
comparison
equal
deleted
inserted
replaced
6237:d81a8251a9b0 | 6238:245950d70306 |
---|---|
34 #include <limits.h> | 34 #include <limits.h> |
35 #include <stdbool.h> | 35 #include <stdbool.h> |
36 #include <stdlib.h> | 36 #include <stdlib.h> |
37 #include "hash.h" | 37 #include "hash.h" |
38 #include "intprops.h" | 38 #include "intprops.h" |
39 #include "stat-time.h" | |
39 #include "timespec.h" | 40 #include "timespec.h" |
40 #include "utimens.h" | 41 #include "utimens.h" |
41 #include "xalloc.h" | 42 #include "xalloc.h" |
42 | 43 |
43 /* Verify a requirement at compile-time (unlike assert, which is runtime). */ | 44 /* Verify a requirement at compile-time (unlike assert, which is runtime). */ |
54 enum { BILLION = 1000 * 1000 * 1000 }; | 55 enum { BILLION = 1000 * 1000 * 1000 }; |
55 | 56 |
56 /* Best possible resolution that utimens can set and stat can return, | 57 /* Best possible resolution that utimens can set and stat can return, |
57 due to system-call limitations. It must be a power of 10 that is | 58 due to system-call limitations. It must be a power of 10 that is |
58 no greater than 1 billion. */ | 59 no greater than 1 billion. */ |
59 #if HAVE_WORKING_UTIMES && defined ST_MTIM_NSEC | 60 #if (HAVE_WORKING_UTIMES \ |
61 && (defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC \ | |
62 || defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC \ | |
63 || defined HAVE_STRUCT_STAT_ST_ATIMENSEC \ | |
64 || defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC \ | |
65 || defined HAVE_STRUCT_STAT_ST_SPARE1)) | |
60 enum { SYSCALL_RESOLUTION = 1000 }; | 66 enum { SYSCALL_RESOLUTION = 1000 }; |
61 #else | 67 #else |
62 enum { SYSCALL_RESOLUTION = BILLION }; | 68 enum { SYSCALL_RESOLUTION = BILLION }; |
63 #endif | 69 #endif |
64 | 70 |
137 verify (twos_complement_arithmetic, TYPE_TWOS_COMPLEMENT (int)); | 143 verify (twos_complement_arithmetic, TYPE_TWOS_COMPLEMENT (int)); |
138 | 144 |
139 /* Destination and source time stamps. */ | 145 /* Destination and source time stamps. */ |
140 time_t dst_s = dst_stat->st_mtime; | 146 time_t dst_s = dst_stat->st_mtime; |
141 time_t src_s = src_stat->st_mtime; | 147 time_t src_s = src_stat->st_mtime; |
142 int dst_ns = TIMESPEC_NS (dst_stat->st_mtim); | 148 int dst_ns = get_stat_mtime_ns (dst_stat); |
143 int src_ns = TIMESPEC_NS (src_stat->st_mtim); | 149 int src_ns = get_stat_mtime_ns (src_stat); |
144 | 150 |
145 if (options & UTIMECMP_TRUNCATE_SOURCE) | 151 if (options & UTIMECMP_TRUNCATE_SOURCE) |
146 { | 152 { |
147 /* Look up the time stamp resolution for the destination device. */ | 153 /* Look up the time stamp resolution for the destination device. */ |
148 | 154 |
184 Deduce it, and store the result in the hash table. */ | 190 Deduce it, and store the result in the hash table. */ |
185 | 191 |
186 time_t dst_a_s = dst_stat->st_atime; | 192 time_t dst_a_s = dst_stat->st_atime; |
187 time_t dst_c_s = dst_stat->st_ctime; | 193 time_t dst_c_s = dst_stat->st_ctime; |
188 time_t dst_m_s = dst_s; | 194 time_t dst_m_s = dst_s; |
189 int dst_a_ns = TIMESPEC_NS (dst_stat->st_atim); | 195 int dst_a_ns = get_stat_atime_ns (dst_stat); |
190 int dst_c_ns = TIMESPEC_NS (dst_stat->st_ctim); | 196 int dst_c_ns = get_stat_ctime_ns (dst_stat); |
191 int dst_m_ns = dst_ns; | 197 int dst_m_ns = dst_ns; |
192 | 198 |
193 /* Set RES to an upper bound on the file system resolution | 199 /* Set RES to an upper bound on the file system resolution |
194 (after truncation due to SYSCALL_RESOLUTION) by inspecting | 200 (after truncation due to SYSCALL_RESOLUTION) by inspecting |
195 the atime, ctime and mtime of the existing destination. | 201 the atime, ctime and mtime of the existing destination. |
278 { | 284 { |
279 int stat_result = stat (dst_name, &dst_status); | 285 int stat_result = stat (dst_name, &dst_status); |
280 | 286 |
281 if (stat_result | 287 if (stat_result |
282 | (dst_status.st_mtime ^ dst_m_s) | 288 | (dst_status.st_mtime ^ dst_m_s) |
283 | (TIMESPEC_NS (dst_status.st_mtim) ^ dst_m_ns)) | 289 | (get_stat_mtime_ns (&dst_status) ^ dst_m_ns)) |
284 { | 290 { |
285 /* The modification time changed, or we can't tell whether | 291 /* The modification time changed, or we can't tell whether |
286 it changed. Change it back as best we can. */ | 292 it changed. Change it back as best we can. */ |
287 timespec[1].tv_sec = dst_m_s; | 293 timespec[1].tv_sec = dst_m_s; |
288 timespec[1].tv_nsec = dst_m_ns; | 294 timespec[1].tv_nsec = dst_m_ns; |
296 /* Determine the exact resolution from the modification time | 302 /* Determine the exact resolution from the modification time |
297 that was read back. */ | 303 that was read back. */ |
298 { | 304 { |
299 int old_res = res; | 305 int old_res = res; |
300 int a = (BILLION * (dst_status.st_mtime & 1) | 306 int a = (BILLION * (dst_status.st_mtime & 1) |
301 + TIMESPEC_NS (dst_status.st_mtim)); | 307 + get_stat_mtime_ns (&dst_status)); |
302 | 308 |
303 res = SYSCALL_RESOLUTION; | 309 res = SYSCALL_RESOLUTION; |
304 | 310 |
305 for (a /= res; a % 10 != 0; a /= 10) | 311 for (a /= res; a % 10 != 0; a /= 10) |
306 { | 312 { |