annotate tests/test-utimens-common.h @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children 5a52ef2d4772
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Test of file timestamp modification functions.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19595
diff changeset
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
12520
e84eea643139 tests: fix license on several tests
Eric Blake <ebb9@byu.net>
parents: 12469
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18833
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* This file defines some prerequisites useful to utime-related tests. */
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #ifndef GL_TEST_UTIMENS_COMMON
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 # define GL_TEST_UTIMENS_COMMON
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
22 # include <fcntl.h>
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
23 # include <errno.h>
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
24 # include <string.h>
18833
ac6d9e820466 utime-tests: New module.
Bruno Haible <bruno@clisp.org>
parents: 18810
diff changeset
25 # include <sys/stat.h>
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
26 # include <unistd.h>
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27
12469
8b48f88c47f1 test-utimens: avoid spurious failure
Eric Blake <ebb9@byu.net>
parents: 12466
diff changeset
28 /* Gnulib modules. */
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
29 # include "stat-time.h"
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
30 # include "timespec.h"
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
31 # include "utimecmp.h"
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32
12469
8b48f88c47f1 test-utimens: avoid spurious failure
Eric Blake <ebb9@byu.net>
parents: 12466
diff changeset
33 /* Gnulib test header. */
8b48f88c47f1 test-utimens: avoid spurious failure
Eric Blake <ebb9@byu.net>
parents: 12466
diff changeset
34 # include "nap.h"
8b48f88c47f1 test-utimens: avoid spurious failure
Eric Blake <ebb9@byu.net>
parents: 12466
diff changeset
35
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 enum {
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 BILLION = 1000 * 1000 * 1000,
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 Y2K = 946684800, /* Jan 1, 2000, in seconds since epoch. */
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 /* Bogus positive and negative tv_nsec values closest to valid
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 range, but without colliding with UTIME_NOW or UTIME_OMIT. */
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 UTIME_BOGUS_POS = BILLION + ((UTIME_NOW == BILLION || UTIME_OMIT == BILLION)
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 ? (1 + (UTIME_NOW == BILLION + 1)
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 + (UTIME_OMIT == BILLION + 1))
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 : 0),
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47 UTIME_BOGUS_NEG = -1 - ((UTIME_NOW == -1 || UTIME_OMIT == -1)
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 ? (1 + (UTIME_NOW == -2) + (UTIME_OMIT == -2))
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 : 0)
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 };
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51
19595
beb2ad957aca Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
52 # if defined _WIN32 && !defined __CYGWIN__
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
53 /* Skip ctime tests on native Windows, since it is either a copy of
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
54 mtime or birth time (depending on the file system), rather than a
18810
ea0c36e7aa56 stat-time: Update comments.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
55 properly tracked change time. See
ea0c36e7aa56 stat-time: Update comments.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
56 <https://msdn.microsoft.com/en-us/library/14h5k7ff(VS.80).aspx>. */
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
57 # define check_ctime 0
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
58 # else
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
59 # define check_ctime 1
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
60 # endif
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
61
16092
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
62 /* Compare two st_ctime values. Return -1, 0 or 1, respectively
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
63 when A's st_ctime is smaller than, equal to or greater than B's. */
17095
8a7efc89bf57 utimens-tests: avoid unnecessary 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
64 static int
16092
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
65 ctime_compare (struct stat const *a, struct stat const *b)
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
66 {
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
67 if (a->st_ctime < b->st_ctime)
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
68 return -1;
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
69 else if (b->st_ctime < a->st_ctime)
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
70 return 1;
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
71 else if (get_stat_ctime_ns (a) < get_stat_ctime_ns (b))
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
72 return -1;
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
73 else if (get_stat_ctime_ns (b) < get_stat_ctime_ns (a))
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
74 return 1;
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
75 else
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
76 return 0;
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
77 }
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
78
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 #endif /* GL_TEST_UTIMENS_COMMON */