malloc: Fix a realloc crash with heap tagging [BZ 27468]
[glibc.git] / support / support_path_support_time64.c
blob452fedcde521e29496a104d15d3098b7458676e8
1 /* Check if path supports 64-bit time interfaces.
2 Copyright (C) 2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <fcntl.h>
20 #include <support/check.h>
21 #include <support/support.h>
22 #include <sys/stat.h>
23 #ifdef __linux__
24 #include <sysdep.h>
25 #endif
27 #ifdef __linux__
28 static int
29 utimesat_call (const char *path, const struct __timespec64 tsp[2])
31 # ifndef __NR_utimensat_time64
32 # define __NR_utimensat_time64 __NR_utimensat
33 # endif
34 return syscall (__NR_utimensat_time64, AT_FDCWD, path, &tsp[0], 0);
36 #endif
38 bool
39 support_path_support_time64 (const char *path)
41 #ifdef __linux__
42 /* Obtain the original timestamps to restore at the end. */
43 struct statx ostx;
44 TEST_VERIFY_EXIT (statx (AT_FDCWD, path, 0, STATX_BASIC_STATS, &ostx) == 0);
46 const struct __timespec64 tsp[] =
48 /* 1s and 2s after y2038 limit. */
49 { 0x80000001ULL, 0 },
50 { 0x80000002ULL, 0 }
52 /* Return is kernel does not support __NR_utimensat_time64. */
53 if (utimesat_call (path, tsp) == -1)
54 return false;
56 /* Verify if the last access and last modification time match the ones
57 obtained with statx. */
58 struct statx stx;
59 TEST_VERIFY_EXIT (statx (AT_FDCWD, path, 0, STATX_BASIC_STATS, &stx) == 0);
61 bool support = stx.stx_atime.tv_sec == tsp[0].tv_sec
62 && stx.stx_mtime.tv_sec == tsp[1].tv_sec;
64 /* Reset to original timestamps. */
65 const struct __timespec64 otsp[] =
67 { ostx.stx_atime.tv_sec, ostx.stx_atime.tv_nsec },
68 { ostx.stx_mtime.tv_sec, ostx.stx_mtime.tv_nsec },
70 TEST_VERIFY_EXIT (utimesat_call (path, otsp) == 0);
72 return support;
73 #else
74 return true;
75 #endif