strtod-obsolete: Fix license.
[gnulib/ericb.git] / m4 / utimensat.m4
blobb4666c096ac7c6ccdd04c58088c56bdb6dbe6c62
1 # serial 6
2 # See if we need to provide utimensat replacement.
4 dnl Copyright (C) 2009-2017 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
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          [gl_cv_func_utimensat_works=yes],
55          [gl_cv_func_utimensat_works=no],
56          [gl_cv_func_utimensat_works="guessing yes"])])
57     if test "$gl_cv_func_utimensat_works" = no; then
58       REPLACE_UTIMENSAT=1
59     fi
60   fi