Debian Codegraph @

m4/futimens.m4

raw
1 # serial 11
2 # See if we need to provide futimens replacement.
3
4 dnl Copyright (C) 2009-2023 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_FUTIMENS],
12 [
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
14 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 gl_CHECK_FUNCS_ANDROID([futimens], [[#include <sys/stat.h>]])
17 if test $ac_cv_func_futimens = no; then
18 HAVE_FUTIMENS=0
19 case "$gl_cv_onwards_func_futimens" in
20 future*) REPLACE_FUTIMENS=1 ;;
21 esac
22 else
23 AC_CACHE_CHECK([whether futimens works],
24 [gl_cv_func_futimens_works],
25 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
26 #include <fcntl.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <errno.h>
30 ]GL_MDA_DEFINES],
31 [[struct timespec ts[2];
32 int fd = creat ("conftest.file", 0600);
33 struct stat st;
34 if (fd < 0) return 1;
35 ts[0].tv_sec = 1;
36 ts[0].tv_nsec = UTIME_OMIT;
37 ts[1].tv_sec = 1;
38 ts[1].tv_nsec = UTIME_NOW;
39 errno = 0;
40 if (futimens (AT_FDCWD, NULL) == 0) return 2;
41 if (errno != EBADF) return 3;
42 if (futimens (fd, ts)) return 4;
43 sleep (1);
44 ts[0].tv_nsec = UTIME_NOW;
45 ts[1].tv_nsec = UTIME_OMIT;
46 if (futimens (fd, ts)) return 5;
47 if (fstat (fd, &st)) return 6;
48 if (st.st_ctime < st.st_atime) return 7;
49 ]])],
50 [gl_cv_func_futimens_works=yes],
51 [gl_cv_func_futimens_works=no],
52 [case "$host_os" in
53 # Guess no on glibc systems.
54 *-gnu* | gnu*) gl_cv_func_futimens_works="guessing no" ;;
55 # Guess no on musl systems.
56 *-musl*) gl_cv_func_futimens_works="guessing no" ;;
57 # Guess yes otherwise.
58 *) gl_cv_func_futimens_works="guessing yes" ;;
59 esac
60 ])
61 rm -f conftest.file])
62 case "$gl_cv_func_futimens_works" in
63 *yes) ;;
64 *)
65 REPLACE_FUTIMENS=1
66 ;;
67 esac
68 fi
69 ])