3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # See if we need to provide utimensat replacement.
10 # Written by Eric Blake.
12 AC_DEFUN([gl_FUNC_UTIMENSAT],
14 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
17 gl_CHECK_FUNCS_ANDROID([utimensat], [[#include <sys/stat.h>]])
18 if test $ac_cv_func_utimensat = no; then
20 case "$gl_cv_onwards_func_utimensat" in
21 future*) REPLACE_UTIMENSAT=1 ;;
24 AC_CACHE_CHECK([whether utimensat works],
25 [gl_cv_func_utimensat_works],
33 const char *f = "conftest.file";
34 if (close (creat (f, 0600)))
36 /* Test whether a trailing slash is handled correctly.
37 This fails on AIX 7.2. */
39 struct timespec ts[2];
40 ts[0].tv_sec = 345183300; ts[0].tv_nsec = 0;
42 if (utimensat (AT_FDCWD, "conftest.file/", ts, 0) == 0)
45 /* Test whether the AT_SYMLINK_NOFOLLOW flag is supported. */
47 if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW))
50 /* Test whether UTIME_NOW and UTIME_OMIT work. */
52 struct timespec ts[2];
54 ts[0].tv_nsec = UTIME_OMIT;
56 ts[1].tv_nsec = UTIME_NOW;
57 if (utimensat (AT_FDCWD, f, ts, 0))
63 struct timespec ts[2];
65 ts[0].tv_nsec = UTIME_NOW;
67 ts[1].tv_nsec = UTIME_OMIT;
68 if (utimensat (AT_FDCWD, f, ts, 0))
72 else if (st.st_ctime < st.st_atime)
77 [gl_cv_func_utimensat_works=yes],
79 2) gl_cv_func_utimensat_works='nearly' ;;
80 *) gl_cv_func_utimensat_works=no ;;
84 # Guess yes on Linux or glibc systems.
85 linux-* | linux | *-gnu* | gnu*)
86 gl_cv_func_utimensat_works="guessing yes" ;;
87 # Guess yes on systems that emulate the Linux system calls.
89 gl_cv_func_utimensat_works="guessing yes" ;;
90 # Guess 'nearly' on AIX.
92 gl_cv_func_utimensat_works="guessing nearly" ;;
93 # If we don't know, obey --enable-cross-guesses.
95 gl_cv_func_utimensat_works="$gl_cross_guess_normal" ;;
99 case "$gl_cv_func_utimensat_works" in
103 AC_DEFINE([HAVE_NEARLY_WORKING_UTIMENSAT], [1],
104 [Define to 1 if utimensat works, except for the trailing slash handling.])