maint: update copyright
[gnulib.git] / tests / test-utimens-common.h
1 /* Test of file timestamp modification functions.
2    Copyright (C) 2009-2014 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>.  */
16
17 /* This file defines some prerequisites useful to utime-related tests.  */
18
19 #ifndef GL_TEST_UTIMENS_COMMON
20 # define GL_TEST_UTIMENS_COMMON
21
22 # include <fcntl.h>
23 # include <errno.h>
24 # include <string.h>
25 # include <unistd.h>
26
27 /* Gnulib modules.  */
28 # include "stat-time.h"
29 # include "timespec.h"
30 # include "utimecmp.h"
31
32 /* Gnulib test header.  */
33 # include "nap.h"
34
35 enum {
36   BILLION = 1000 * 1000 * 1000,
37
38   Y2K = 946684800, /* Jan 1, 2000, in seconds since epoch.  */
39
40   /* Bogus positive and negative tv_nsec values closest to valid
41      range, but without colliding with UTIME_NOW or UTIME_OMIT.  */
42   UTIME_BOGUS_POS = BILLION + ((UTIME_NOW == BILLION || UTIME_OMIT == BILLION)
43                                ? (1 + (UTIME_NOW == BILLION + 1)
44                                   + (UTIME_OMIT == BILLION + 1))
45                                : 0),
46   UTIME_BOGUS_NEG = -1 - ((UTIME_NOW == -1 || UTIME_OMIT == -1)
47                           ? (1 + (UTIME_NOW == -2) + (UTIME_OMIT == -2))
48                           : 0)
49 };
50
51 # if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
52 /* Skip ctime tests on native Windows, since it is either a copy of
53    mtime or birth time (depending on the file system), rather than a
54    properly tracked change time.  */
55 #  define check_ctime 0
56 # else
57 #  define check_ctime 1
58 # endif
59
60 /* Compare two st_ctime values.  Return -1, 0 or 1, respectively
61    when A's st_ctime is smaller than, equal to or greater than B's.  */
62 static int
63 ctime_compare (struct stat const *a, struct stat const *b)
64 {
65   if (a->st_ctime < b->st_ctime)
66     return -1;
67   else if (b->st_ctime < a->st_ctime)
68     return 1;
69   else if (get_stat_ctime_ns (a) < get_stat_ctime_ns (b))
70     return -1;
71   else if (get_stat_ctime_ns (b) < get_stat_ctime_ns (a))
72     return 1;
73   else
74     return 0;
75 }
76
77 #endif /* GL_TEST_UTIMENS_COMMON */