1dnl Copyright (C) 2003-2020 Free Software Foundation, Inc.
2dnl This file is free software; the Free Software Foundation
3dnl gives unlimited permission to copy and/or distribute it,
4dnl with or without modifications, as long as this notice is preserved.
5
6dnl serial 10
7
8AC_DEFUN([gl_UTIMENS],
9[
10  dnl Prerequisites of lib/utimens.c.
11  AC_REQUIRE([gl_FUNC_UTIMES])
12  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
13  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14  AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat lutimes])
15
16  if test $ac_cv_func_futimens = no && test $ac_cv_func_futimesat = yes; then
17    dnl FreeBSD 8.0-rc2 mishandles futimesat(fd,NULL,time).  It is not
18    dnl standardized, but Solaris implemented it first and uses it as
19    dnl its only means to set fd time.
20    AC_CACHE_CHECK([whether futimesat handles NULL file],
21      [gl_cv_func_futimesat_works],
22      [touch conftest.file
23       AC_RUN_IFELSE([AC_LANG_PROGRAM([[
24#include <stddef.h>
25#include <sys/times.h>
26#include <fcntl.h>
27]], [[    int fd = open ("conftest.file", O_RDWR);
28          if (fd < 0) return 1;
29          if (futimesat (fd, NULL, NULL)) return 2;
30        ]])],
31        [gl_cv_func_futimesat_works=yes],
32        [gl_cv_func_futimesat_works=no],
33        [case "$host_os" in
34                            # Guess yes on Linux systems.
35           linux-* | linux) gl_cv_func_futimesat_works="guessing yes" ;;
36                            # Guess yes on glibc systems.
37           *-gnu*)          gl_cv_func_futimesat_works="guessing yes" ;;
38                            # If we don't know, obey --enable-cross-guesses.
39           *)               gl_cv_func_futimesat_works="$gl_cross_guess_normal" ;;
40         esac
41        ])
42      rm -f conftest.file])
43    case "$gl_cv_func_futimesat_works" in
44      *yes) ;;
45      *)
46        AC_DEFINE([FUTIMESAT_NULL_BUG], [1],
47          [Define to 1 if futimesat mishandles a NULL file name.])
48        ;;
49    esac
50  fi
51])
52