2 dnl Copyright (C) 2006, 2009-2018 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Written by Paul Eggert.
9 # Test whether the flags O_NOATIME and O_NOFOLLOW actually work.
10 # Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise.
11 # Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise.
12 AC_DEFUN([gl_FCNTL_O_FLAGS],
14 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
15 dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
17 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
18 [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
19 [AC_REQUIRE([AC_GNU_SOURCE])])
21 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
22 AC_CHECK_HEADERS_ONCE([unistd.h])
23 AC_CHECK_FUNCS_ONCE([symlink])
24 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
27 [[#include <sys/types.h>
31 #else /* on Windows with MSVC */
34 # defined sleep(n) _sleep ((n) * 1000)
43 static int const constants[] =
45 O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
46 O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
50 int result = !constants;
53 static char const sym[] = "conftest.sym";
54 if (symlink ("/dev/null", sym) != 0)
58 int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0);
65 if (unlink (sym) != 0 || symlink (".", sym) != 0)
69 int fd = open (sym, O_RDONLY | O_NOFOLLOW);
80 static char const file[] = "confdefs.h";
81 int fd = open (file, O_RDONLY | O_NOATIME);
87 if (fstat (fd, &st0) != 0)
93 if (read (fd, &c, 1) != 1)
102 if (stat (file, &st1) != 0)
105 if (st0.st_atime != st1.st_atime)
113 [gl_cv_header_working_fcntl_h=yes],
115 4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
116 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
117 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
118 *) gl_cv_header_working_fcntl_h='no';;
121 # Guess 'no' on native Windows.
122 mingw*) gl_cv_header_working_fcntl_h='no' ;;
123 *) gl_cv_header_working_fcntl_h=cross-compiling ;;
128 case $gl_cv_header_working_fcntl_h in #(
129 *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
132 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
133 [Define to 1 if O_NOATIME works.])
135 case $gl_cv_header_working_fcntl_h in #(
136 *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
139 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
140 [Define to 1 if O_NOFOLLOW works.])