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