utimensat: new module
[gnulib.git] / m4 / utimensat.m4
1 # serial 1
2 # See if we need to provide utimensat replacement.
3
4 dnl Copyright (C) 2009 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_CHECK_FUNCS_ONCE([utimensat])
16   if test $ac_cv_func_utimensat = no; then
17     HAVE_UTIMENSAT=0
18     AC_LIBOBJ([utimensat])
19   else
20     AC_CACHE_CHECK([whether utimensat works],
21       [gl_cv_func_utimensat_works],
22       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
23 #include <fcntl.h>
24 #include <sys/stat.h>
25 #ifdef __linux__
26 /* The Linux kernel added utimensat in 2.6.22, but it had bugs until 2.6.26.
27    Always replace utimensat to support older kernels.  */
28 choke me
29 #endif
30 ]], [[struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_OMIT } };
31       return utimensat (AT_FDCWD, ".", NULL, AT_SYMLINK_NOFOLLOW);]])],
32          [gl_cv_func_utimensat_works=yes],
33          [gl_cv_func_utimensat_works="needs runtime check"],
34          [gl_cv_func_utimensat_works="guessing no"])])
35     if test "$gl_cv_func_utimensat_works" != yes; then
36       REPLACE_UTIMENSAT=1
37       AC_LIBOBJ([utimensat])
38     fi
39   fi
40 ])