| 1 |
# serial 11 |
| 2 |
# See if we need to provide utimensat replacement. |
| 3 |
|
| 4 |
dnl Copyright (C) 2009-2023 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. |
| 8 |
|
| 9 |
# Written by Eric Blake. |
| 10 |
|
| 11 |
AC_DEFUN([gl_FUNC_UTIMENSAT], |
| 12 |
[ |
| 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 |
gl_CHECK_FUNCS_ANDROID([utimensat], [[#include <sys/stat.h>]]) |
| 17 |
if test $ac_cv_func_utimensat = no; then |
| 18 |
HAVE_UTIMENSAT=0 |
| 19 |
case "$gl_cv_onwards_func_utimensat" in |
| 20 |
future*) REPLACE_UTIMENSAT=1 ;; |
| 21 |
esac |
| 22 |
else |
| 23 |
AC_CACHE_CHECK([whether utimensat works], |
| 24 |
[gl_cv_func_utimensat_works], |
| 25 |
[AC_RUN_IFELSE( |
| 26 |
[AC_LANG_PROGRAM([[ |
| 27 |
#include <fcntl.h> |
| 28 |
#include <sys/stat.h> |
| 29 |
#include <unistd.h> |
| 30 |
]GL_MDA_DEFINES], |
| 31 |
[[int result = 0; |
| 32 |
const char *f = "conftest.file"; |
| 33 |
if (close (creat (f, 0600))) |
| 34 |
return 1; |
| 35 |
/* Test whether a trailing slash is handled correctly. |
| 36 |
This fails on AIX 7.2. */ |
| 37 |
{ |
| 38 |
struct timespec ts[2]; |
| 39 |
ts[0].tv_sec = 345183300; ts[0].tv_nsec = 0; |
| 40 |
ts[1] = ts[0]; |
| 41 |
if (utimensat (AT_FDCWD, "conftest.file/", ts, 0) == 0) |
| 42 |
result |= 2; |
| 43 |
} |
| 44 |
/* Test whether the AT_SYMLINK_NOFOLLOW flag is supported. */ |
| 45 |
{ |
| 46 |
if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW)) |
| 47 |
result |= 4; |
| 48 |
} |
| 49 |
/* Test whether UTIME_NOW and UTIME_OMIT work. */ |
| 50 |
{ |
| 51 |
struct timespec ts[2]; |
| 52 |
ts[0].tv_sec = 1; |
| 53 |
ts[0].tv_nsec = UTIME_OMIT; |
| 54 |
ts[1].tv_sec = 1; |
| 55 |
ts[1].tv_nsec = UTIME_NOW; |
| 56 |
if (utimensat (AT_FDCWD, f, ts, 0)) |
| 57 |
result |= 8; |
| 58 |
} |
| 59 |
sleep (1); |
| 60 |
{ |
| 61 |
struct stat st; |
| 62 |
struct timespec ts[2]; |
| 63 |
ts[0].tv_sec = 1; |
| 64 |
ts[0].tv_nsec = UTIME_NOW; |
| 65 |
ts[1].tv_sec = 1; |
| 66 |
ts[1].tv_nsec = UTIME_OMIT; |
| 67 |
if (utimensat (AT_FDCWD, f, ts, 0)) |
| 68 |
result |= 16; |
| 69 |
if (stat (f, &st)) |
| 70 |
result |= 32; |
| 71 |
else if (st.st_ctime < st.st_atime) |
| 72 |
result |= 64; |
| 73 |
} |
| 74 |
return result; |
| 75 |
]])], |
| 76 |
[gl_cv_func_utimensat_works=yes], |
| 77 |
[case $? in |
| 78 |
2) gl_cv_func_utimensat_works='nearly' ;; |
| 79 |
*) gl_cv_func_utimensat_works=no ;; |
| 80 |
esac |
| 81 |
], |
| 82 |
[case "$host_os" in |
| 83 |
# Guess yes on Linux or glibc systems. |
| 84 |
linux-* | linux | *-gnu* | gnu*) |
| 85 |
gl_cv_func_utimensat_works="guessing yes" ;; |
| 86 |
# Guess 'nearly' on AIX. |
| 87 |
aix*) |
| 88 |
gl_cv_func_utimensat_works="guessing nearly" ;; |
| 89 |
# If we don't know, obey --enable-cross-guesses. |
| 90 |
*) |
| 91 |
gl_cv_func_utimensat_works="$gl_cross_guess_normal" ;; |
| 92 |
esac |
| 93 |
]) |
| 94 |
]) |
| 95 |
case "$gl_cv_func_utimensat_works" in |
| 96 |
*yes) |
| 97 |
;; |
| 98 |
*nearly) |
| 99 |
AC_DEFINE([HAVE_NEARLY_WORKING_UTIMENSAT], [1], |
| 100 |
[Define to 1 if utimensat works, except for the trailing slash handling.]) |
| 101 |
REPLACE_UTIMENSAT=1 |
| 102 |
;; |
| 103 |
*) |
| 104 |
REPLACE_UTIMENSAT=1 |
| 105 |
;; |
| 106 |
esac |
| 107 |
fi |
| 108 |
]) |