Debian Codegraph @

m4/futimens.m4

raw
1 # futimens.m4
2 # serial 11
3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 # See if we need to provide futimens replacement.
10
11 # Written by Eric Blake.
12
13 AC_DEFUN([gl_FUNC_FUTIMENS],
14 [
15 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
16 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
17 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
18 gl_CHECK_FUNCS_ANDROID([futimens], [[#include <sys/stat.h>]])
19 if test $ac_cv_func_futimens = no; then
20 HAVE_FUTIMENS=0
21 case "$gl_cv_onwards_func_futimens" in
22 future*) REPLACE_FUTIMENS=1 ;;
23 esac
24 else
25 AC_CACHE_CHECK([whether futimens works],
26 [gl_cv_func_futimens_works],
27 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
28 #include <fcntl.h>
29 #include <sys/stat.h>
30 #include <unistd.h>
31 #include <errno.h>
32 ]GL_MDA_DEFINES],
33 [[struct timespec ts[2];
34 int fd = creat ("conftest.file", 0600);
35 struct stat st;
36 if (fd < 0) return 1;
37 ts[0].tv_sec = 1;
38 ts[0].tv_nsec = UTIME_OMIT;
39 ts[1].tv_sec = 1;
40 ts[1].tv_nsec = UTIME_NOW;
41 errno = 0;
42 if (futimens (AT_FDCWD, NULL) == 0) return 2;
43 if (errno != EBADF) return 3;
44 if (futimens (fd, ts)) return 4;
45 sleep (1);
46 ts[0].tv_nsec = UTIME_NOW;
47 ts[1].tv_nsec = UTIME_OMIT;
48 if (futimens (fd, ts)) return 5;
49 if (fstat (fd, &st)) return 6;
50 if (st.st_ctime < st.st_atime) return 7;
51 ]])],
52 [gl_cv_func_futimens_works=yes],
53 [gl_cv_func_futimens_works=no],
54 [case "$host_os" in
55 # Guess no on glibc systems.
56 *-gnu* | gnu*) gl_cv_func_futimens_works="guessing no" ;;
57 # Guess no on musl systems.
58 *-musl*) gl_cv_func_futimens_works="guessing no" ;;
59 # Guess yes otherwise.
60 *) gl_cv_func_futimens_works="guessing yes" ;;
61 esac
62 ])
63 rm -f conftest.file])
64 case "$gl_cv_func_futimens_works" in
65 *yes) ;;
66 *)
67 REPLACE_FUTIMENS=1
68 ;;
69 esac
70 fi
71 ])