root/maint/gnulib/tests/test-utimens-common.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ctime_compare

   1 /* Test of file timestamp modification functions.
   2    Copyright (C) 2009-2021 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 <https://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 <sys/stat.h>
  26 # include <unistd.h>
  27 
  28 /* Gnulib modules.  */
  29 # include "stat-time.h"
  30 # include "timespec.h"
  31 # include "utimecmp.h"
  32 
  33 /* Gnulib test header.  */
  34 # include "nap.h"
  35 
  36 enum {
  37   BILLION = 1000 * 1000 * 1000,
  38 
  39   Y2K = 946684800, /* Jan 1, 2000, in seconds since epoch.  */
  40 
  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))
  46                                : 0),
  47   UTIME_BOGUS_NEG = -1 - ((UTIME_NOW == -1 || UTIME_OMIT == -1)
  48                           ? (1 + (UTIME_NOW == -2) + (UTIME_OMIT == -2))
  49                           : 0)
  50 };
  51 
  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
  61 # else
  62 #  define check_ctime 1
  63 # endif
  64 
  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.  */
  67 static int
  68 ctime_compare (struct stat const *a, struct stat const *b)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70   if (a->st_ctime < b->st_ctime)
  71     return -1;
  72   else if (b->st_ctime < a->st_ctime)
  73     return 1;
  74   else if (get_stat_ctime_ns (a) < get_stat_ctime_ns (b))
  75     return -1;
  76   else if (get_stat_ctime_ns (b) < get_stat_ctime_ns (a))
  77     return 1;
  78   else
  79     return 0;
  80 }
  81 
  82 #endif /* GL_TEST_UTIMENS_COMMON */

/* [previous][next][first][last][top][bottom][index][help] */