Debian Codegraph @

m4/fcntl-o.m4

raw
1 # fcntl-o.m4
2 # serial 8
3 dnl Copyright (C) 2006, 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 dnl Written by Paul Eggert.
10
11 AC_PREREQ([2.60])
12
13 # Test whether the flags O_NOATIME and O_NOFOLLOW actually work.
14 # Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise.
15 # Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise.
16 AC_DEFUN([gl_FCNTL_O_FLAGS],
17 [
18 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
19 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
20
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],
25 [AC_RUN_IFELSE(
26 [AC_LANG_PROGRAM(
27 [[#include <sys/types.h>
28 #include <sys/stat.h>
29 #if HAVE_UNISTD_H
30 # include <unistd.h>
31 #else /* on Windows with MSVC */
32 # include <io.h>
33 # include <stdlib.h>
34 # defined sleep(n) _sleep ((n) * 1000)
35 #endif
36 #include <fcntl.h>
37 ]GL_MDA_DEFINES[
38 #ifndef O_NOATIME
39 #define O_NOATIME 0
40 #endif
41 #ifndef O_NOFOLLOW
42 #define O_NOFOLLOW 0
43 #endif
44 static int const constants[] =
45 {
46 O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
47 O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
48 };
49 ]],
50 [[
51 int result = !constants;
52 #if HAVE_SYMLINK
53 {
54 static char const sym[] = "conftest.sym";
55 if (symlink ("/dev/null", sym) != 0)
56 result |= 2;
57 else
58 {
59 int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0);
60 if (fd >= 0)
61 {
62 close (fd);
63 result |= 4;
64 }
65 }
66 if (unlink (sym) != 0 || symlink (".", sym) != 0)
67 result |= 2;
68 else
69 {
70 int fd = open (sym, O_RDONLY | O_NOFOLLOW);
71 if (fd >= 0)
72 {
73 close (fd);
74 result |= 4;
75 }
76 }
77 unlink (sym);
78 }
79 #endif
80 {
81 static char const file[] = "confdefs.h";
82 int fd = open (file, O_RDONLY | O_NOATIME);
83 if (fd < 0)
84 result |= 8;
85 else
86 {
87 struct stat st0;
88 if (fstat (fd, &st0) != 0)
89 result |= 16;
90 else
91 {
92 char c;
93 sleep (1);
94 if (read (fd, &c, 1) != 1)
95 result |= 24;
96 else
97 {
98 if (close (fd) != 0)
99 result |= 32;
100 else
101 {
102 struct stat st1;
103 if (stat (file, &st1) != 0)
104 result |= 40;
105 else
106 if (st0.st_atime != st1.st_atime)
107 result |= 64;
108 }
109 }
110 }
111 }
112 }
113 return result;]])],
114 [gl_cv_header_working_fcntl_h=yes],
115 [case $? in #(
116 4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
117 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
118 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
119 *) gl_cv_header_working_fcntl_h='no';;
120 esac],
121 [case "$host_os" in
122 # Guess 'no' on native Windows.
123 mingw* | windows*) gl_cv_header_working_fcntl_h='no' ;;
124 *) gl_cv_header_working_fcntl_h=cross-compiling ;;
125 esac
126 ])
127 ])
128
129 case $gl_cv_header_working_fcntl_h in #(
130 *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
131 *) ac_val=1;;
132 esac
133 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
134 [Define to 1 if O_NOATIME works.])
135
136 case $gl_cv_header_working_fcntl_h in #(
137 *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
138 *) ac_val=1;;
139 esac
140 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
141 [Define to 1 if O_NOFOLLOW works.])
142 ])