Merge strftime.c changes from glibc
[gnulib.git] / m4 / utimensat.m4
blob576d1213359189313bab1ac495aa3d0d070614c4
1 # serial 6
2 # See if we need to provide utimensat replacement.
4 dnl Copyright (C) 2009-2018 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];
38                 ts[0].tv_sec = 1;
39                 ts[0].tv_nsec = UTIME_OMIT;
40                 ts[1].tv_sec = 1;
41                 ts[1].tv_nsec = UTIME_NOW;
42                 if (utimensat (AT_FDCWD, f, ts, 0))
43                   result |= 4;
44               }
45               sleep (1);
46               {
47                 struct stat st;
48                 struct timespec ts[2];
49                 ts[0].tv_sec = 1;
50                 ts[0].tv_nsec = UTIME_NOW;
51                 ts[1].tv_sec = 1;
52                 ts[1].tv_nsec = UTIME_OMIT;
53                 if (utimensat (AT_FDCWD, f, ts, 0))
54                   result |= 8;
55                 if (stat (f, &st))
56                   result |= 16;
57                 else if (st.st_ctime < st.st_atime)
58                   result |= 32;
59               }
60               return result;
61             ]])],
62          [gl_cv_func_utimensat_works=yes],
63          [gl_cv_func_utimensat_works=no],
64          [gl_cv_func_utimensat_works="guessing yes"])])
65     if test "$gl_cv_func_utimensat_works" = no; then
66       REPLACE_UTIMENSAT=1
67     fi
68   fi