warnings: fix compilation with old autoconf
[gnulib/ericb.git] / m4 / futimens.m4
blobd68bff3a7d798a5a06de35831a9b22b2804a0047
1 # serial 7
2 # See if we need to provide futimens 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_FUTIMENS],
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];
27       int fd = creat ("conftest.file", 0600);
28       struct stat st;
29       if (fd < 0) return 1;
30       ts[0].tv_sec = 1;
31       ts[0].tv_nsec = UTIME_OMIT;
32       ts[1].tv_sec = 1;
33       ts[1].tv_nsec = UTIME_NOW;
34       errno = 0;
35       if (futimens (AT_FDCWD, NULL) == 0) return 2;
36       if (errno != EBADF) return 3;
37       if (futimens (fd, ts)) return 4;
38       sleep (1);
39       ts[0].tv_nsec = UTIME_NOW;
40       ts[1].tv_nsec = UTIME_OMIT;
41       if (futimens (fd, ts)) return 5;
42       if (fstat (fd, &st)) return 6;
43       if (st.st_ctime < st.st_atime) return 7;
44       ]])],
45          [gl_cv_func_futimens_works=yes],
46          [gl_cv_func_futimens_works=no],
47          [gl_cv_func_futimens_works="guessing yes"])
48       rm -f conftest.file])
49     if test "$gl_cv_func_futimens_works" = no; then
50       REPLACE_FUTIMENS=1
51     fi
52   fi