]> git.cworth.org Git - tar/blob - m4/utimensat.m4
Imported Upstream version 1.24
[tar] / m4 / utimensat.m4
1 # serial 3
2 # See if we need to provide utimensat replacement.
3
4 dnl Copyright (C) 2009, 2010 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 #include <unistd.h>
26 ]], [[struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_NOW } };
27       struct stat st;
28       const char *f = "conftest.file";
29       if (close (creat (f, 0600))) return 1;
30       if (utimensat (AT_FDCWD, f, NULL, AT_SYMLINK_NOFOLLOW)) return 2;
31       if (utimensat (AT_FDCWD, f, ts, 0)) return 3;
32       sleep (1);
33       ts[0].tv_nsec = UTIME_NOW;
34       ts[1].tv_nsec = UTIME_OMIT;
35       if (utimensat (AT_FDCWD, f, ts, 0)) return 4;
36       if (stat (f, &st)) return 5;
37       if (st.st_ctime < st.st_atime) return 6;]])],
38 dnl FIXME: simplify this in 2012, when file system bugs are no longer common
39          [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
40 #ifdef __linux__
41 /* The Linux kernel added utimensat in 2.6.22, but has bugs with UTIME_OMIT
42    in several file systems as recently as 2.6.32.  Always replace utimensat
43    to support older kernels.  */
44 choke me
45 #endif
46       ]])],
47            [gl_cv_func_utimensat_works=yes],
48            [gl_cv_func_utimensat_works="needs runtime check"])],
49          [gl_cv_func_utimensat_works=no],
50          [gl_cv_func_utimensat_works="guessing no"])])
51     if test "$gl_cv_func_utimensat_works" != yes; then
52       REPLACE_UTIMENSAT=1
53       AC_LIBOBJ([utimensat])
54     fi
55   fi
56 ])