diff options
Diffstat (limited to 'gl/m4/fcntl-o.m4')
| -rw-r--r-- | gl/m4/fcntl-o.m4 | 97 |
1 files changed, 64 insertions, 33 deletions
diff --git a/gl/m4/fcntl-o.m4 b/gl/m4/fcntl-o.m4 index 43aa1325..8020c481 100644 --- a/gl/m4/fcntl-o.m4 +++ b/gl/m4/fcntl-o.m4 | |||
| @@ -1,15 +1,17 @@ | |||
| 1 | # fcntl-o.m4 | 1 | # fcntl-o.m4 |
| 2 | # serial 8 | 2 | # serial 12 |
| 3 | dnl Copyright (C) 2006, 2009-2024 Free Software Foundation, Inc. | 3 | dnl Copyright (C) 2006, 2009-2025 Free Software Foundation, Inc. |
| 4 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
| 5 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
| 6 | dnl with or without modifications, as long as this notice is preserved. | 6 | dnl with or without modifications, as long as this notice is preserved. |
| 7 | dnl This file is offered as-is, without any warranty. | ||
| 7 | 8 | ||
| 8 | dnl Written by Paul Eggert. | 9 | dnl Written by Paul Eggert. |
| 9 | 10 | ||
| 10 | AC_PREREQ([2.60]) | 11 | AC_PREREQ([2.60]) |
| 11 | 12 | ||
| 12 | # Test whether the flags O_NOATIME and O_NOFOLLOW actually work. | 13 | # Test whether the flags O_DIRECTORY, O_NOATIME and O_NOFOLLOW actually work. |
| 14 | # Define HAVE_WORKING_O_DIRECTORY to 1 if O_DIRECTORY works, or to 0 otherwise. | ||
| 13 | # Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise. | 15 | # Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise. |
| 14 | # Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise. | 16 | # Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise. |
| 15 | AC_DEFUN([gl_FCNTL_O_FLAGS], | 17 | AC_DEFUN([gl_FCNTL_O_FLAGS], |
| @@ -30,16 +32,23 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], | |||
| 30 | #else /* on Windows with MSVC */ | 32 | #else /* on Windows with MSVC */ |
| 31 | # include <io.h> | 33 | # include <io.h> |
| 32 | # include <stdlib.h> | 34 | # include <stdlib.h> |
| 33 | # defined sleep(n) _sleep ((n) * 1000) | 35 | # define sleep(n) _sleep ((n) * 1000) |
| 34 | #endif | 36 | #endif |
| 37 | #include <errno.h> | ||
| 35 | #include <fcntl.h> | 38 | #include <fcntl.h> |
| 36 | ]GL_MDA_DEFINES[ | 39 | ]GL_MDA_DEFINES[ |
| 40 | #ifndef O_DIRECTORY | ||
| 41 | #define O_DIRECTORY 0 | ||
| 42 | #endif | ||
| 37 | #ifndef O_NOATIME | 43 | #ifndef O_NOATIME |
| 38 | #define O_NOATIME 0 | 44 | #define O_NOATIME 0 |
| 39 | #endif | 45 | #endif |
| 40 | #ifndef O_NOFOLLOW | 46 | #ifndef O_NOFOLLOW |
| 41 | #define O_NOFOLLOW 0 | 47 | #define O_NOFOLLOW 0 |
| 42 | #endif | 48 | #endif |
| 49 | #ifndef O_SEARCH | ||
| 50 | #define O_SEARCH O_RDONLY | ||
| 51 | #endif | ||
| 43 | static int const constants[] = | 52 | static int const constants[] = |
| 44 | { | 53 | { |
| 45 | O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, | 54 | O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, |
| @@ -52,31 +61,38 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], | |||
| 52 | { | 61 | { |
| 53 | static char const sym[] = "conftest.sym"; | 62 | static char const sym[] = "conftest.sym"; |
| 54 | if (symlink ("/dev/null", sym) != 0) | 63 | if (symlink ("/dev/null", sym) != 0) |
| 55 | result |= 2; | 64 | result |= 1; |
| 56 | else | 65 | else |
| 57 | { | 66 | { |
| 58 | int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0); | 67 | int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0); |
| 59 | if (fd >= 0) | 68 | if (fd >= 0) |
| 60 | { | 69 | { |
| 61 | close (fd); | 70 | close (fd); |
| 62 | result |= 4; | 71 | result |= 3; |
| 63 | } | 72 | } |
| 64 | } | 73 | } |
| 65 | if (unlink (sym) != 0 || symlink (".", sym) != 0) | 74 | if (unlink (sym) != 0 || symlink (".", sym) != 0) |
| 66 | result |= 2; | 75 | result |= 1; |
| 67 | else | 76 | else |
| 68 | { | 77 | { |
| 69 | int fd = open (sym, O_RDONLY | O_NOFOLLOW); | 78 | int fd = open (sym, O_RDONLY | O_NOFOLLOW); |
| 70 | if (fd >= 0) | 79 | if (fd >= 0) |
| 71 | { | 80 | { |
| 72 | close (fd); | 81 | close (fd); |
| 73 | result |= 4; | 82 | result |= 3; |
| 74 | } | 83 | } |
| 75 | } | 84 | } |
| 76 | unlink (sym); | 85 | unlink (sym); |
| 77 | } | 86 | } |
| 78 | #endif | 87 | #endif |
| 79 | { | 88 | { |
| 89 | int fd = open ("confdefs.h", O_SEARCH | O_DIRECTORY); | ||
| 90 | if (!(fd < 0 && errno == ENOTDIR)) | ||
| 91 | result |= 4; | ||
| 92 | if (0 <= fd) | ||
| 93 | close (fd); | ||
| 94 | } | ||
| 95 | { | ||
| 80 | static char const file[] = "confdefs.h"; | 96 | static char const file[] = "confdefs.h"; |
| 81 | int fd = open (file, O_RDONLY | O_NOATIME); | 97 | int fd = open (file, O_RDONLY | O_NOATIME); |
| 82 | if (fd < 0) | 98 | if (fd < 0) |
| @@ -111,31 +127,46 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], | |||
| 111 | } | 127 | } |
| 112 | return result;]])], | 128 | return result;]])], |
| 113 | [gl_cv_header_working_fcntl_h=yes], | 129 | [gl_cv_header_working_fcntl_h=yes], |
| 114 | [case $? in #( | 130 | [AS_CASE([$?], |
| 115 | 4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( | 131 | dnl We cannot catch exit code 1 or 2 here, because |
| 116 | 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( | 132 | dnl - exit code 1 can occur through a compilation error on mingw (e.g. |
| 117 | 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( | 133 | dnl when O_NOCTTY, O_NONBLOCK, O_SYNC are not defined) or when |
| 118 | *) gl_cv_header_working_fcntl_h='no';; | 134 | dnl result = 1, whereas |
| 119 | esac], | 135 | dnl - exit code 2 can occur through a compilation error on MSVC (e.g. |
| 120 | [case "$host_os" in | 136 | dnl again when O_NOCTTY, O_NONBLOCK, O_SYNC are not defined) or when |
| 121 | # Guess 'no' on native Windows. | 137 | dnl result = 2. |
| 122 | mingw* | windows*) gl_cv_header_working_fcntl_h='no' ;; | 138 | [ 3], [gl_cv_header_working_fcntl_h="no (bad O_NOFOLLOW)"], |
| 123 | *) gl_cv_header_working_fcntl_h=cross-compiling ;; | 139 | [ 4], [gl_cv_header_working_fcntl_h="no (bad O_DIRECTORY)"], |
| 124 | esac | 140 | [ 7], [gl_cv_header_working_fcntl_h="no (bad O_NOFOLLOW, O_DIRECTORY)"], |
| 125 | ]) | 141 | [64], [gl_cv_header_working_fcntl_h="no (bad O_NOATIME)"], |
| 126 | ]) | 142 | [67], [gl_cv_header_working_fcntl_h="no (bad O_NOFOLLOW, O_NOATIME)"], |
| 143 | [68], [gl_cv_header_working_fcntl_h="no (bad O_DIRECTORY, O_NOATIME)"], | ||
| 144 | [71], [gl_cv_header_working_fcntl_h="no (bad O_NOFOLLOW, O_DIRECTORY, O_NOATIME)"], | ||
| 145 | [gl_cv_header_working_fcntl_h="no"])], | ||
| 146 | [AS_CASE([$host_os,$gl_cross_guess_normal], | ||
| 147 | # The O_DIRECTORY test is known to fail on Mac OS X 10.4.11 (2007) | ||
| 148 | # (see <https://bugs.gnu.org/78509#95>) | ||
| 149 | # and to succeed on Mac OS X 10.5.8 [darwin9.8.0] (2009). | ||
| 150 | # Guess it fails on Mac OS X 10.4.x and earlier. | ||
| 151 | [darwin[[0-8]].*yes], | ||
| 152 | [gl_cv_header_working_fcntl_h="guessing no (bad O_DIRECTORY)"], | ||
| 153 | # Known to be "no" on native MS-Windows. | ||
| 154 | [mingw* | windows*], | ||
| 155 | [gl_cv_header_working_fcntl_h=no], | ||
| 156 | [gl_cv_header_working_fcntl_h=$gl_cross_guess_normal])])]) | ||
| 157 | |||
| 158 | AS_CASE([$gl_cv_header_working_fcntl_h], | ||
| 159 | [*O_DIRECTORY* | *no], [gl_val=0], [gl_val=1]) | ||
| 160 | AC_DEFINE_UNQUOTED([HAVE_WORKING_O_DIRECTORY], [$gl_val], | ||
| 161 | [Define to 1 if O_DIRECTORY works, 0 otherwise.]) | ||
| 127 | 162 | ||
| 128 | case $gl_cv_header_working_fcntl_h in #( | 163 | AS_CASE([$gl_cv_header_working_fcntl_h], |
| 129 | *O_NOATIME* | no | cross-compiling) ac_val=0;; #( | 164 | [*O_NOATIME* | *no], [gl_val=0], [gl_val=1]) |
| 130 | *) ac_val=1;; | 165 | AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$gl_val], |
| 131 | esac | 166 | [Define to 1 if O_NOATIME works, 0 otherwise.]) |
| 132 | AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val], | ||
| 133 | [Define to 1 if O_NOATIME works.]) | ||
| 134 | 167 | ||
| 135 | case $gl_cv_header_working_fcntl_h in #( | 168 | AS_CASE([$gl_cv_header_working_fcntl_h], |
| 136 | *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #( | 169 | [*O_NOFOLLOW* | *no], [gl_val=0], [gl_val=1]) |
| 137 | *) ac_val=1;; | 170 | AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$gl_val], |
| 138 | esac | 171 | [Define to 1 if O_NOFOLLOW works, 0 otherwise.]) |
| 139 | AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val], | ||
| 140 | [Define to 1 if O_NOFOLLOW works.]) | ||
| 141 | ]) | 172 | ]) |
