Mercurial > hg > octave-shane > gnulib-hg
annotate lib/utimecmp.c @ 16201:8250f2777afc
maint: update all copyright year number ranges
Run "make update-copyright".
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sun, 01 Jan 2012 10:04:58 +0100 |
parents | 1e0bf20577a1 |
children | e542fd46ad6f |
rev | line source |
---|---|
5148 | 1 /* utimecmp.c -- compare file time stamps |
2 | |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
14642
diff
changeset
|
3 Copyright (C) 2004-2007, 2009-2012 Free Software Foundation, Inc. |
5148 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8223
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
5148 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8223
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8223
diff
changeset
|
8 (at your option) any later version. |
5148 | 9 |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8223
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5148 | 17 |
18 /* Written by Paul Eggert. */ | |
19 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
7162
diff
changeset
|
20 #include <config.h> |
5148 | 21 |
22 #include "utimecmp.h" | |
23 | |
24 #include <limits.h> | |
25 #include <stdbool.h> | |
7162
19c2e5121b2f
Add and change modules to make it easier for coreutils to use
Paul Eggert <eggert@cs.ucla.edu>
parents:
6323
diff
changeset
|
26 #include <stdint.h> |
5148 | 27 #include <stdlib.h> |
8223
ca249819379f
* lib/getdate.h (includes): Include <time.h>, not "timespec.h".
Eric Blake <ebb9@byu.net>
parents:
7406
diff
changeset
|
28 #include <time.h> |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
29 #include <unistd.h> |
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
30 |
5148 | 31 #include "hash.h" |
5691
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5148
diff
changeset
|
32 #include "intprops.h" |
6238
245950d70306
* utimecmp.c: Include stat-time.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
33 #include "stat-time.h" |
5148 | 34 #include "utimens.h" |
6323
af09cfa36fd5
* modules/exclude (Depends-on): Depend on verify.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
35 #include "verify.h" |
5148 | 36 |
37 #ifndef MAX | |
38 # define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
39 #endif | |
40 | |
12727
fd5b0bf2a8e9
utimecmp: avoid new warning from upcoming gcc-4.5.0
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
41 #define BILLION (1000 * 1000 * 1000) |
5148 | 42 |
43 /* Best possible resolution that utimens can set and stat can return, | |
44 due to system-call limitations. It must be a power of 10 that is | |
45 no greater than 1 billion. */ | |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
46 #if HAVE_UTIMENSAT |
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
47 enum { SYSCALL_RESOLUTION = 1 }; |
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
48 #elif ((HAVE_FUTIMESAT || HAVE_WORKING_UTIMES) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
49 && (defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
50 || defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
51 || defined HAVE_STRUCT_STAT_ST_ATIMENSEC \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
52 || defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
53 || defined HAVE_STRUCT_STAT_ST_SPARE1)) |
5148 | 54 enum { SYSCALL_RESOLUTION = 1000 }; |
55 #else | |
56 enum { SYSCALL_RESOLUTION = BILLION }; | |
57 #endif | |
58 | |
59 /* Describe a file system and its time stamp resolution in nanoseconds. */ | |
60 struct fs_res | |
61 { | |
62 /* Device number of file system. */ | |
63 dev_t dev; | |
64 | |
65 /* An upper bound on the time stamp resolution of this file system, | |
66 ignoring any resolution that cannot be set via utimens. It is | |
67 represented by an integer count of nanoseconds. It must be | |
68 either 2 billion, or a power of 10 that is no greater than a | |
69 billion and is no less than SYSCALL_RESOLUTION. */ | |
70 int resolution; | |
71 | |
72 /* True if RESOLUTION is known to be exact, and is not merely an | |
73 upper bound on the true resolution. */ | |
74 bool exact; | |
75 }; | |
76 | |
77 /* Hash some device info. */ | |
78 static size_t | |
79 dev_info_hash (void const *x, size_t table_size) | |
80 { | |
81 struct fs_res const *p = x; | |
82 | |
83 /* Beware signed arithmetic gotchas. */ | |
84 if (TYPE_SIGNED (dev_t) && SIZE_MAX < MAX (INT_MAX, TYPE_MAXIMUM (dev_t))) | |
85 { | |
86 uintmax_t dev = p->dev; | |
87 return dev % table_size; | |
88 } | |
89 | |
90 return p->dev % table_size; | |
91 } | |
92 | |
93 /* Compare two dev_info structs. */ | |
94 static bool | |
95 dev_info_compare (void const *x, void const *y) | |
96 { | |
97 struct fs_res const *a = x; | |
98 struct fs_res const *b = y; | |
99 return a->dev == b->dev; | |
100 } | |
101 | |
102 /* Return -1, 0, 1 based on whether the destination file (with name | |
103 DST_NAME and status DST_STAT) is older than SRC_STAT, the same age | |
104 as SRC_STAT, or newer than SRC_STAT, respectively. | |
105 | |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
106 DST_NAME may be NULL if OPTIONS is 0. |
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
107 |
5148 | 108 If OPTIONS & UTIMECMP_TRUNCATE_SOURCE, do the comparison after SRC is |
109 converted to the destination's timestamp resolution as filtered through | |
110 utimens. In this case, return -2 if the exact answer cannot be | |
111 determined; this can happen only if the time stamps are very close and | |
112 there is some trouble accessing the file system (e.g., the user does not | |
113 have permission to futz with the destination's time stamps). */ | |
114 | |
115 int | |
116 utimecmp (char const *dst_name, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
117 struct stat const *dst_stat, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
118 struct stat const *src_stat, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
119 int options) |
5148 | 120 { |
121 /* Things to watch out for: | |
122 | |
123 The code uses a static hash table internally and is not safe in the | |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
124 presence of signals, multiple threads, etc. However, memory pressure |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
125 that prevents use of the hash table is not fatal - we just fall back |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
126 to redoing the computations on every call in that case. |
5148 | 127 |
128 int and long int might be 32 bits. Many of the calculations store | |
129 numbers up to 2 billion, and multiply by 10; they have to avoid | |
130 multiplying 2 billion by 10, as this exceeds 32-bit capabilities. | |
131 | |
132 time_t might be unsigned. */ | |
133 | |
6323
af09cfa36fd5
* modules/exclude (Depends-on): Depend on verify.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
134 verify (TYPE_IS_INTEGER (time_t)); |
af09cfa36fd5
* modules/exclude (Depends-on): Depend on verify.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
135 verify (TYPE_TWOS_COMPLEMENT (int)); |
5148 | 136 |
137 /* Destination and source time stamps. */ | |
138 time_t dst_s = dst_stat->st_mtime; | |
139 time_t src_s = src_stat->st_mtime; | |
6238
245950d70306
* utimecmp.c: Include stat-time.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
140 int dst_ns = get_stat_mtime_ns (dst_stat); |
245950d70306
* utimecmp.c: Include stat-time.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
141 int src_ns = get_stat_mtime_ns (src_stat); |
5148 | 142 |
143 if (options & UTIMECMP_TRUNCATE_SOURCE) | |
144 { | |
145 /* Look up the time stamp resolution for the destination device. */ | |
146 | |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
147 /* Hash table for caching information learned about devices. */ |
5148 | 148 static Hash_table *ht; |
149 | |
150 /* Information about the destination file system. */ | |
151 static struct fs_res *new_dst_res; | |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
152 struct fs_res *dst_res = NULL; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
153 struct fs_res tmp_dst_res; |
5148 | 154 |
155 /* Time stamp resolution in nanoseconds. */ | |
156 int res; | |
157 | |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
158 /* Quick exit, if possible. Since the worst resolution is 2 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
159 seconds, anything that differs by more than that does not |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
160 needs source truncation. */ |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
161 if (dst_s == src_s && dst_ns == src_ns) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
162 return 0; |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
163 if (dst_s <= src_s - 2) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
164 return -1; |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
165 if (src_s <= dst_s - 2) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
166 return 1; |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
167 |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
168 /* Try to do a hash lookup, but fall back to stack variables and |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
169 recomputation on low memory situations. */ |
5148 | 170 if (! ht) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
171 ht = hash_initialize (16, NULL, dev_info_hash, dev_info_compare, free); |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
172 if (ht) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
173 { |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
174 if (! new_dst_res) |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
175 { |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
176 new_dst_res = malloc (sizeof *new_dst_res); |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
177 if (!new_dst_res) |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
178 goto low_memory; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
179 new_dst_res->resolution = 2 * BILLION; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
180 new_dst_res->exact = false; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
181 } |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
182 new_dst_res->dev = dst_stat->st_dev; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
183 dst_res = hash_insert (ht, new_dst_res); |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
184 if (! dst_res) |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
185 goto low_memory; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
186 |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
187 if (dst_res == new_dst_res) |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
188 { |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
189 /* NEW_DST_RES is now in use in the hash table, so allocate a |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
190 new entry next time. */ |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
191 new_dst_res = NULL; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
192 } |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
193 } |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
194 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
195 { |
14642
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
196 low_memory: |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
197 if (ht) |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
198 { |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
199 tmp_dst_res.dev = dst_stat->st_dev; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
200 dst_res = hash_lookup (ht, &tmp_dst_res); |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
201 } |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
202 if (!dst_res) |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
203 { |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
204 dst_res = &tmp_dst_res; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
205 dst_res->resolution = 2 * BILLION; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
206 dst_res->exact = false; |
1e0bf20577a1
utimecmp: drop dependency on xmalloc
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
207 } |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
208 } |
5148 | 209 |
210 res = dst_res->resolution; | |
211 | |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
212 #ifdef _PC_TIMESTAMP_RESOLUTION |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
213 /* If the system will tell us the resolution, we're set! */ |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
214 if (! dst_res->exact) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
215 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
216 res = pathconf (dst_name, _PC_TIMESTAMP_RESOLUTION); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
217 if (0 < res) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
218 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
219 dst_res->resolution = res; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
220 dst_res->exact = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
221 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
222 } |
12159
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
223 #endif |
0ae159ba1adf
utimecmp: support symlink timestamps
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
224 |
5148 | 225 if (! dst_res->exact) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
226 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
227 /* This file system's resolution is not known exactly. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
228 Deduce it, and store the result in the hash table. */ |
5148 | 229 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
230 time_t dst_a_s = dst_stat->st_atime; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
231 time_t dst_c_s = dst_stat->st_ctime; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
232 time_t dst_m_s = dst_s; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
233 int dst_a_ns = get_stat_atime_ns (dst_stat); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
234 int dst_c_ns = get_stat_ctime_ns (dst_stat); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
235 int dst_m_ns = dst_ns; |
5148 | 236 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
237 /* Set RES to an upper bound on the file system resolution |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
238 (after truncation due to SYSCALL_RESOLUTION) by inspecting |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
239 the atime, ctime and mtime of the existing destination. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
240 We don't know of any file system that stores atime or |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
241 ctime with a higher precision than mtime, so it's valid to |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
242 look at them too. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
243 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
244 bool odd_second = (dst_a_s | dst_c_s | dst_m_s) & 1; |
5148 | 245 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
246 if (SYSCALL_RESOLUTION == BILLION) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
247 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
248 if (odd_second | dst_a_ns | dst_c_ns | dst_m_ns) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
249 res = BILLION; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
250 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
251 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
252 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
253 int a = dst_a_ns; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
254 int c = dst_c_ns; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
255 int m = dst_m_ns; |
5148 | 256 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
257 /* Write it this way to avoid mistaken GCC warning |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
258 about integer overflow in constant expression. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
259 int SR10 = SYSCALL_RESOLUTION; SR10 *= 10; |
5148 | 260 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
261 if ((a % SR10 | c % SR10 | m % SR10) != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
262 res = SYSCALL_RESOLUTION; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
263 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
264 for (res = SR10, a /= SR10, c /= SR10, m /= SR10; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
265 (res < dst_res->resolution |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
266 && (a % 10 | c % 10 | m % 10) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
267 res *= 10, a /= 10, c /= 10, m /= 10) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
268 if (res == BILLION) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
269 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
270 if (! odd_second) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
271 res *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
272 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
273 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
274 } |
5148 | 275 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
276 dst_res->resolution = res; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
277 } |
5148 | 278 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
279 if (SYSCALL_RESOLUTION < res) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
280 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
281 struct timespec timespec[2]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
282 struct stat dst_status; |
5148 | 283 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
284 /* Ignore source time stamp information that must necessarily |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
285 be lost when filtered through utimens. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
286 src_ns -= src_ns % SYSCALL_RESOLUTION; |
5148 | 287 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
288 /* If the time stamps disagree widely enough, there's no need |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
289 to interrogate the file system to deduce the exact time |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
290 stamp resolution; return the answer directly. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
291 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
292 time_t s = src_s & ~ (res == 2 * BILLION); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
293 if (src_s < dst_s || (src_s == dst_s && src_ns <= dst_ns)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
294 return 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
295 if (dst_s < s |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
296 || (dst_s == s && dst_ns < src_ns - src_ns % res)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
297 return -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
298 } |
5148 | 299 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
300 /* Determine the actual time stamp resolution for the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
301 destination file system (after truncation due to |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
302 SYSCALL_RESOLUTION) by setting the access time stamp of the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
303 destination to the existing access time, except with |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
304 trailing nonzero digits. */ |
5148 | 305 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
306 timespec[0].tv_sec = dst_a_s; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
307 timespec[0].tv_nsec = dst_a_ns; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
308 timespec[1].tv_sec = dst_m_s | (res == 2 * BILLION); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
309 timespec[1].tv_nsec = dst_m_ns + res / 9; |
5148 | 310 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
311 /* Set the modification time. But don't try to set the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
312 modification time of symbolic links; on many hosts this sets |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
313 the time of the pointed-to file. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
314 if ((S_ISLNK (dst_stat->st_mode) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
315 ? lutimens (dst_name, timespec) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
316 : utimens (dst_name, timespec)) != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
317 return -2; |
5148 | 318 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
319 /* Read the modification time that was set. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
320 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
321 int stat_result = (S_ISLNK (dst_stat->st_mode) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
322 ? lstat (dst_name, &dst_status) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
323 : stat (dst_name, &dst_status)); |
5148 | 324 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
325 if (stat_result |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
326 | (dst_status.st_mtime ^ dst_m_s) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
327 | (get_stat_mtime_ns (&dst_status) ^ dst_m_ns)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
328 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
329 /* The modification time changed, or we can't tell whether |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
330 it changed. Change it back as best we can. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
331 timespec[1].tv_sec = dst_m_s; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
332 timespec[1].tv_nsec = dst_m_ns; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
333 if (S_ISLNK (dst_stat->st_mode)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
334 lutimens (dst_name, timespec); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
335 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
336 utimens (dst_name, timespec); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
337 } |
5148 | 338 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
339 if (stat_result != 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
340 return -2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
341 } |
5148 | 342 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
343 /* Determine the exact resolution from the modification time |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
344 that was read back. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
345 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
346 int old_res = res; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
347 int a = (BILLION * (dst_status.st_mtime & 1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
348 + get_stat_mtime_ns (&dst_status)); |
5148 | 349 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
350 res = SYSCALL_RESOLUTION; |
5148 | 351 |
13914
cc15a32c0446
utimecmp: fine-grained src to nearby coarse-grained dest
Paul Eggert <eggert@cs.ucla.edu>
parents:
12727
diff
changeset
|
352 for (a /= res; a % 10 == 0; a /= 10) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
353 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
354 if (res == BILLION) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
355 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
356 res *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
357 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
358 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
359 res *= 10; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
360 if (res == old_res) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
361 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
362 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
363 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
364 } |
5148 | 365 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
366 dst_res->resolution = res; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
367 dst_res->exact = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
368 } |
5148 | 369 |
370 /* Truncate the source's time stamp according to the resolution. */ | |
371 src_s &= ~ (res == 2 * BILLION); | |
372 src_ns -= src_ns % res; | |
373 } | |
374 | |
375 /* Compare the time stamps and return -1, 0, 1 accordingly. */ | |
376 return (dst_s < src_s ? -1 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
377 : dst_s > src_s ? 1 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
378 : dst_ns < src_ns ? -1 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12159
diff
changeset
|
379 : dst_ns > src_ns); |
5148 | 380 } |