1dnl Copyright (C) 2003-2014 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 7
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([gl_CHECK_TYPE_STRUCT_UTIMBUF])
14  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15  AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat lutimes])
16
17  if test $ac_cv_func_futimens = no && test $ac_cv_func_futimesat = yes; then
18    dnl FreeBSD 8.0-rc2 mishandles futimesat(fd,NULL,time).  It is not
19    dnl standardized, but Solaris implemented it first and uses it as
20    dnl its only means to set fd time.
21    AC_CACHE_CHECK([whether futimesat handles NULL file],
22      [gl_cv_func_futimesat_works],
23      [touch conftest.file
24       AC_RUN_IFELSE([AC_LANG_PROGRAM([[
25#include <stddef.h>
26#include <sys/times.h>
27#include <fcntl.h>
28]], [[    int fd = open ("conftest.file", O_RDWR);
29          if (fd < 0) return 1;
30          if (futimesat (fd, NULL, NULL)) return 2;
31        ]])],
32        [gl_cv_func_futimesat_works=yes],
33        [gl_cv_func_futimesat_works=no],
34        [case "$host_os" in
35                   # Guess yes on glibc systems.
36           *-gnu*) gl_cv_func_futimesat_works="guessing yes" ;;
37                   # If we don't know, assume the worst.
38           *)      gl_cv_func_futimesat_works="guessing no" ;;
39         esac
40        ])
41      rm -f conftest.file])
42    case "$gl_cv_func_futimesat_works" in
43      *yes) ;;
44      *)
45        AC_DEFINE([FUTIMESAT_NULL_BUG], [1],
46          [Define to 1 if futimesat mishandles a NULL file name.])
47        ;;
48    esac
49  fi
50])
51