2 # See if we need to provide futimens 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_FUTIMENS],
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_FUNCS_ONCE([futimens])
16 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([[
27 ]], [[struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_NOW } };
28 int fd = creat ("conftest.file", 0600);
32 if (futimens (AT_FDCWD, NULL) == 0) return 2;
33 if (errno != EBADF) return 3;
34 if (futimens (fd, ts)) return 4;
36 ts[0].tv_nsec = UTIME_NOW;
37 ts[1].tv_nsec = UTIME_OMIT;
38 if (futimens (fd, ts)) return 5;
39 if (fstat (fd, &st)) return 6;
40 if (st.st_ctime < st.st_atime) return 7;
42 dnl FIXME: simplify this in 2012, when file system bugs are no longer common
43 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
45 /* The Linux kernel added futimens in 2.6.22, but has bugs with UTIME_OMIT
46 in several file systems as recently as 2.6.32. Always replace futimens
47 to support older kernels. */
51 [gl_cv_func_futimens_works=yes],
52 [gl_cv_func_futimens_works="needs runtime check"])],
53 [gl_cv_func_futimens_works=no],
54 [gl_cv_func_futimens_works="guessing no"])
56 if test "$gl_cv_func_futimens_works" != yes; then