2 # See if we need to provide futimens replacement.
4 dnl Copyright (C) 2009-2020 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_FUTIMENS],
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
14 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 AC_CHECK_FUNCS_ONCE([futimens])
17 if test $ac_cv_func_futimens = no; then
20 AC_CACHE_CHECK([whether futimens works],
21 [gl_cv_func_futimens_works],
22 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
28 [[struct timespec ts[2];
29 int fd = creat ("conftest.file", 0600);
33 ts[0].tv_nsec = UTIME_OMIT;
35 ts[1].tv_nsec = UTIME_NOW;
37 if (futimens (AT_FDCWD, NULL) == 0) return 2;
38 if (errno != EBADF) return 3;
39 if (futimens (fd, ts)) return 4;
41 ts[0].tv_nsec = UTIME_NOW;
42 ts[1].tv_nsec = UTIME_OMIT;
43 if (futimens (fd, ts)) return 5;
44 if (fstat (fd, &st)) return 6;
45 if (st.st_ctime < st.st_atime) return 7;
47 [gl_cv_func_futimens_works=yes],
48 [gl_cv_func_futimens_works=no],
50 # Guess no on glibc systems.
51 *-gnu* | gnu*) gl_cv_func_futimens_works="guessing no" ;;
52 # Guess no on musl systems.
53 *-musl*) gl_cv_func_futimens_works="guessing no" ;;
54 # Guess yes otherwise.
55 *) gl_cv_func_futimens_works="guessing yes" ;;
59 case "$gl_cv_func_futimens_works" in