Debian Codegraph @

m4/open-slash.m4

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