re-mark 1.29b-2 as not yet uploaded (merge madness!)
[debian/tar] / m4 / utimensat.m4
1 # serial 5
2 # See if we need to provide utimensat replacement.
3
4 dnl Copyright (C) 2009-2015 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   else
19     AC_CACHE_CHECK([whether utimensat works],
20       [gl_cv_func_utimensat_works],
21       [AC_RUN_IFELSE(
22          [AC_LANG_PROGRAM([[
23 #include <fcntl.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 ]],         [[int result = 0;
27               const char *f = "conftest.file";
28               if (close (creat (f, 0600)))
29                 return 1;
30               /* Test whether the AT_SYMLINK_NOFOLLOW flag is supported.  */
31               {
32                 if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW))
33                   result |= 2;
34               }
35               /* Test whether UTIME_NOW and UTIME_OMIT work.  */
36               {
37                 struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_NOW } };
38                 if (utimensat (AT_FDCWD, f, ts, 0))
39                   result |= 4;
40               }
41               sleep (1);
42               {
43                 struct timespec ts[2] = { { 1, UTIME_NOW }, { 1, UTIME_OMIT } };
44                 struct stat st;
45                 if (utimensat (AT_FDCWD, f, ts, 0))
46                   result |= 8;
47                 if (stat (f, &st))
48                   result |= 16;
49                 else if (st.st_ctime < st.st_atime)
50                   result |= 32;
51               }
52               return result;
53             ]])],
54 dnl FIXME: simplify this in 2012, when file system bugs are no longer common
55          [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
56 #ifdef __linux__
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.  */
60 choke me
61 #endif
62       ]])],
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
68       REPLACE_UTIMENSAT=1
69     fi
70   fi
71 ])