2 # See if we need to provide utimensat replacement.
4 dnl Copyright (C) 2009-2011 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_UTIMENSAT],
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
19 AC_CACHE_CHECK([whether utimensat works],
20 [gl_cv_func_utimensat_works],
27 const char *f = "conftest.file";
28 if (close (creat (f, 0600)))
30 /* Test whether the AT_SYMLINK_NOFOLLOW flag is supported. */
32 if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW))
35 /* Test whether UTIME_NOW and UTIME_OMIT work. */
37 struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_NOW } };
38 if (utimensat (AT_FDCWD, f, ts, 0))
43 struct timespec ts[2] = { { 1, UTIME_NOW }, { 1, UTIME_OMIT } };
45 if (utimensat (AT_FDCWD, f, ts, 0))
49 else if (st.st_ctime < st.st_atime)
54 dnl FIXME: simplify this in 2012, when file system bugs are no longer common
55 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
57 /* The Linux kernel added utimensat in 2.6.22, but has bugs with UTIME_OMIT
58 in several file systems as recently as 2.6.32. Always replace utimensat
59 to support older kernels. */
63 [gl_cv_func_utimensat_works=yes],
64 [gl_cv_func_utimensat_works="needs runtime check"])],
65 [gl_cv_func_utimensat_works=no],
66 [gl_cv_func_utimensat_works="guessing no"])])
67 if test "$gl_cv_func_utimensat_works" != yes; then