1 /* Test of file timestamp modification functions.
2 Copyright (C) 2009 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 2 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 <http://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
27 #include "stat-time.h"
32 BILLION = 1000 * 1000 * 1000,
34 Y2K = 946684800, /* Jan 1, 2000, in seconds since epoch. */
36 /* Bogus positive and negative tv_nsec values closest to valid
37 range, but without colliding with UTIME_NOW or UTIME_OMIT. */
38 UTIME_BOGUS_POS = BILLION + ((UTIME_NOW == BILLION || UTIME_OMIT == BILLION)
39 ? (1 + (UTIME_NOW == BILLION + 1)
40 + (UTIME_OMIT == BILLION + 1))
42 UTIME_BOGUS_NEG = -1 - ((UTIME_NOW == -1 || UTIME_OMIT == -1)
43 ? (1 + (UTIME_NOW == -2) + (UTIME_OMIT == -2))
47 /* Sleep long enough to cross a timestamp quantization boundary on
48 most known systems with subsecond timestamp resolution. For
49 example, ext4 has a quantization of 10 milliseconds, but a
50 resolution of 1 nanosecond. Likewise, NTFS has a quantization as
51 slow as 15.25 milliseconds, but a resolution of 100 nanoseconds.
52 This is necessary on systems where creat or utimens with NULL
53 rounds down to the quantization boundary, but where gettime and
54 hence utimensat can inject timestamps between quantization
55 boundaries. By ensuring we cross a boundary, we are less likely to
56 confuse utimecmp for two times that would round to the same
57 quantization boundary but are distinct based on resolution. */
61 /* Systems that lack usleep also lack subsecond timestamps, and have
62 a quantization boundary equal to the resolution. Our usage of
63 utimecmp allows equality, so no need to waste 980 milliseconds
64 if the replacement usleep rounds to 1 second. */
66 usleep (20 * 1000); /* 20 milliseconds. */
70 #endif /* GL_TEST_UTIMENS_COMMON */