diff options
Diffstat (limited to 'gl/m4/open-slash.m4')
| -rw-r--r-- | gl/m4/open-slash.m4 | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gl/m4/open-slash.m4 b/gl/m4/open-slash.m4 new file mode 100644 index 00000000..1f731f8a --- /dev/null +++ b/gl/m4/open-slash.m4 | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | # open-slash.m4 serial 2 | ||
| 2 | dnl Copyright (C) 2007-2023 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. | ||
| 6 | |||
| 7 | dnl Tests whether open() and creat() recognize a trailing slash. | ||
| 8 | dnl Sets gl_cv_func_open_slash. | ||
| 9 | AC_DEFUN([gl_OPEN_TRAILING_SLASH_BUG], | ||
| 10 | [ | ||
| 11 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 12 | dnl open("foo/") should not create a file when the file name has a | ||
| 13 | dnl trailing slash. FreeBSD only has the problem on symlinks. | ||
| 14 | AC_CHECK_FUNCS_ONCE([lstat]) | ||
| 15 | AC_CACHE_CHECK([whether open recognizes a trailing slash], | ||
| 16 | [gl_cv_func_open_slash], | ||
| 17 | [# Assume that if we have lstat, we can also check symlinks. | ||
| 18 | if test $ac_cv_func_lstat = yes; then | ||
| 19 | touch conftest.tmp | ||
| 20 | ln -s conftest.tmp conftest.lnk | ||
| 21 | fi | ||
| 22 | AC_RUN_IFELSE( | ||
| 23 | [AC_LANG_SOURCE([[ | ||
| 24 | #include <fcntl.h> | ||
| 25 | #if HAVE_UNISTD_H | ||
| 26 | # include <unistd.h> | ||
| 27 | #endif | ||
| 28 | ]GL_MDA_DEFINES[ | ||
| 29 | int main () | ||
| 30 | { | ||
| 31 | int result = 0; | ||
| 32 | #if HAVE_LSTAT | ||
| 33 | if (open ("conftest.lnk/", O_RDONLY) != -1) | ||
| 34 | result |= 1; | ||
| 35 | #endif | ||
| 36 | if (open ("conftest.sl/", O_CREAT, 0600) >= 0) | ||
| 37 | result |= 2; | ||
| 38 | return result; | ||
| 39 | }]])], | ||
| 40 | [gl_cv_func_open_slash=yes], | ||
| 41 | [gl_cv_func_open_slash=no], | ||
| 42 | [ | ||
| 43 | changequote(,)dnl | ||
| 44 | case "$host_os" in | ||
| 45 | freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*) | ||
| 46 | gl_cv_func_open_slash="guessing no" ;; | ||
| 47 | *) | ||
| 48 | gl_cv_func_open_slash="guessing yes" ;; | ||
| 49 | esac | ||
| 50 | changequote([,])dnl | ||
| 51 | ]) | ||
| 52 | rm -f conftest.sl conftest.tmp conftest.lnk | ||
| 53 | ]) | ||
| 54 | case "$gl_cv_func_open_slash" in | ||
| 55 | *no) | ||
| 56 | AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1], | ||
| 57 | [Define to 1 if open() fails to recognize a trailing slash.]) | ||
| 58 | ;; | ||
| 59 | esac | ||
| 60 | ]) | ||
