1 /* Test of file timestamp modification functions.
2 Copyright (C) 2009-2021 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* This file defines some prerequisites useful to utime-related tests. */
19 #ifndef GL_TEST_UTIMENS_COMMON
20 # define GL_TEST_UTIMENS_COMMON
25 # include <sys/stat.h>
29 # include "stat-time.h"
30 # include "timespec.h"
31 # include "utimecmp.h"
33 /* Gnulib test header. */
37 BILLION
= 1000 * 1000 * 1000,
39 Y2K
= 946684800, /* Jan 1, 2000, in seconds since epoch. */
41 /* Bogus positive and negative tv_nsec values closest to valid
42 range, but without colliding with UTIME_NOW or UTIME_OMIT. */
43 UTIME_BOGUS_POS
= BILLION
+ ((UTIME_NOW
== BILLION
|| UTIME_OMIT
== BILLION
)
44 ? (1 + (UTIME_NOW
== BILLION
+ 1)
45 + (UTIME_OMIT
== BILLION
+ 1))
47 UTIME_BOGUS_NEG
= -1 - ((UTIME_NOW
== -1 || UTIME_OMIT
== -1)
48 ? (1 + (UTIME_NOW
== -2) + (UTIME_OMIT
== -2))
52 # if defined _WIN32 && !defined __CYGWIN__
53 /* Skip ctime tests on native Windows, since it is either a copy of
54 mtime or birth time (depending on the file system), rather than a
55 properly tracked change time. See
56 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions>. */
57 # define check_ctime 0
58 # elif defined __APPLE__ && defined __MACH__
59 /* On macOS, the ctime is not updated when only the st_atime changes. */
60 # define check_ctime -1
62 # define check_ctime 1
65 /* Compare two st_ctime values. Return -1, 0 or 1, respectively
66 when A's st_ctime is smaller than, equal to or greater than B's. */
68 ctime_compare (struct stat
const *a
, struct stat
const *b
)
70 if (a
->st_ctime
< b
->st_ctime
)
72 else if (b
->st_ctime
< a
->st_ctime
)
74 else if (get_stat_ctime_ns (a
) < get_stat_ctime_ns (b
))
76 else if (get_stat_ctime_ns (b
) < get_stat_ctime_ns (a
))
82 #endif /* GL_TEST_UTIMENS_COMMON */