2 # See if we need to provide utimensat replacement.
4 dnl Copyright (C) 2009-2021 Free Software Foundation, Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
9 # Written by Eric Blake.
11 AC_DEFUN([gl_FUNC_UTIMENSAT],
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
16 AC_CHECK_FUNCS_ONCE([utimensat])
17 if test $ac_cv_func_utimensat = no; then
20 AC_CACHE_CHECK([whether utimensat works],
21 [gl_cv_func_utimensat_works],
29 const char *f = "conftest.file";
30 if (close (creat (f, 0600)))
32 /* Test whether a trailing slash is handled correctly.
33 This fails on AIX 7.2. */
35 struct timespec ts[2];
36 ts[0].tv_sec = 345183300; ts[0].tv_nsec = 0;
38 if (utimensat (AT_FDCWD, "conftest.file/", ts, 0) == 0)
41 /* Test whether the AT_SYMLINK_NOFOLLOW flag is supported. */
43 if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW))
46 /* Test whether UTIME_NOW and UTIME_OMIT work. */
48 struct timespec ts[2];
50 ts[0].tv_nsec = UTIME_OMIT;
52 ts[1].tv_nsec = UTIME_NOW;
53 if (utimensat (AT_FDCWD, f, ts, 0))
59 struct timespec ts[2];
61 ts[0].tv_nsec = UTIME_NOW;
63 ts[1].tv_nsec = UTIME_OMIT;
64 if (utimensat (AT_FDCWD, f, ts, 0))
68 else if (st.st_ctime < st.st_atime)
73 [gl_cv_func_utimensat_works=yes],
75 2) gl_cv_func_utimensat_works='nearly' ;;
76 *) gl_cv_func_utimensat_works=no ;;
80 # Guess yes on Linux or glibc systems.
81 linux-* | linux | *-gnu* | gnu*)
82 gl_cv_func_utimensat_works="guessing yes" ;;
83 # Guess 'nearly' on AIX.
85 gl_cv_func_utimensat_works="guessing nearly" ;;
86 # If we don't know, obey --enable-cross-guesses.
88 gl_cv_func_utimensat_works="$gl_cross_guess_normal" ;;
92 case "$gl_cv_func_utimensat_works" in
96 AC_DEFINE([HAVE_NEARLY_WORKING_UTIMENSAT], [1],
97 [Define to 1 if utimensat works, except for the trailing slash handling.])