1# serial 6 2# See if we need to provide futimens replacement. 3 4dnl Copyright (C) 2009-2014 Free Software Foundation, Inc. 5dnl This file is free software; the Free Software Foundation 6dnl gives unlimited permission to copy and/or distribute it, 7dnl with or without modifications, as long as this notice is preserved. 8 9# Written by Eric Blake. 10 11AC_DEFUN([gl_FUNC_FUTIMENS], 12[ 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 17 HAVE_FUTIMENS=0 18 else 19 AC_CACHE_CHECK([whether futimens works], 20 [gl_cv_func_futimens_works], 21 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 22#include <fcntl.h> 23#include <sys/stat.h> 24#include <unistd.h> 25#include <errno.h> 26]], [[struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_NOW } }; 27 int fd = creat ("conftest.file", 0600); 28 struct stat st; 29 if (fd < 0) return 1; 30 errno = 0; 31 if (futimens (AT_FDCWD, NULL) == 0) return 2; 32 if (errno != EBADF) return 3; 33 if (futimens (fd, ts)) return 4; 34 sleep (1); 35 ts[0].tv_nsec = UTIME_NOW; 36 ts[1].tv_nsec = UTIME_OMIT; 37 if (futimens (fd, ts)) return 5; 38 if (fstat (fd, &st)) return 6; 39 if (st.st_ctime < st.st_atime) return 7; 40 ]])], 41dnl FIXME: simplify this in 2012, when file system bugs are no longer common 42 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 43#ifdef __linux__ 44/* The Linux kernel added futimens in 2.6.22, but has bugs with UTIME_OMIT 45 in several file systems as recently as 2.6.32. Always replace futimens 46 to support older kernels. */ 47choke me 48#endif 49 ]])], 50 [gl_cv_func_futimens_works=yes], 51 [gl_cv_func_futimens_works="needs runtime check"])], 52 [gl_cv_func_futimens_works=no], 53 [gl_cv_func_futimens_works="guessing no"]) 54 rm -f conftest.file]) 55 if test "$gl_cv_func_futimens_works" != yes; then 56 REPLACE_FUTIMENS=1 57 fi 58 fi 59]) 60