Home | History | Annotate | Line # | Download | only in m4
      1  1.1.1.2  christos # open-slash.m4 serial 2
      2  1.1.1.2  christos dnl Copyright (C) 2007-2022 Free Software Foundation, Inc.
      3      1.1  christos dnl This file is free software; the Free Software Foundation
      4      1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      5      1.1  christos dnl with or without modifications, as long as this notice is preserved.
      6      1.1  christos 
      7      1.1  christos dnl Tests whether open() and creat() recognize a trailing slash.
      8      1.1  christos dnl Sets gl_cv_func_open_slash.
      9      1.1  christos AC_DEFUN([gl_OPEN_TRAILING_SLASH_BUG],
     10      1.1  christos [
     11      1.1  christos   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
     12      1.1  christos   dnl open("foo/") should not create a file when the file name has a
     13      1.1  christos   dnl trailing slash.  FreeBSD only has the problem on symlinks.
     14      1.1  christos   AC_CHECK_FUNCS_ONCE([lstat])
     15      1.1  christos   AC_CACHE_CHECK([whether open recognizes a trailing slash],
     16      1.1  christos     [gl_cv_func_open_slash],
     17      1.1  christos     [# Assume that if we have lstat, we can also check symlinks.
     18      1.1  christos      if test $ac_cv_func_lstat = yes; then
     19      1.1  christos        touch conftest.tmp
     20      1.1  christos        ln -s conftest.tmp conftest.lnk
     21      1.1  christos      fi
     22      1.1  christos      AC_RUN_IFELSE(
     23      1.1  christos        [AC_LANG_SOURCE([[
     24      1.1  christos #include <fcntl.h>
     25      1.1  christos #if HAVE_UNISTD_H
     26      1.1  christos # include <unistd.h>
     27      1.1  christos #endif
     28  1.1.1.2  christos ]GL_MDA_DEFINES[
     29      1.1  christos int main ()
     30      1.1  christos {
     31      1.1  christos   int result = 0;
     32      1.1  christos #if HAVE_LSTAT
     33      1.1  christos   if (open ("conftest.lnk/", O_RDONLY) != -1)
     34      1.1  christos     result |= 1;
     35      1.1  christos #endif
     36      1.1  christos   if (open ("conftest.sl/", O_CREAT, 0600) >= 0)
     37      1.1  christos     result |= 2;
     38      1.1  christos   return result;
     39      1.1  christos }]])],
     40      1.1  christos        [gl_cv_func_open_slash=yes],
     41      1.1  christos        [gl_cv_func_open_slash=no],
     42      1.1  christos        [
     43      1.1  christos changequote(,)dnl
     44      1.1  christos         case "$host_os" in
     45      1.1  christos           freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
     46      1.1  christos             gl_cv_func_open_slash="guessing no" ;;
     47      1.1  christos           *)
     48      1.1  christos             gl_cv_func_open_slash="guessing yes" ;;
     49      1.1  christos         esac
     50      1.1  christos changequote([,])dnl
     51      1.1  christos        ])
     52      1.1  christos      rm -f conftest.sl conftest.tmp conftest.lnk
     53      1.1  christos     ])
     54      1.1  christos   case "$gl_cv_func_open_slash" in
     55      1.1  christos     *no)
     56      1.1  christos       AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
     57      1.1  christos         [Define to 1 if open() fails to recognize a trailing slash.])
     58      1.1  christos       ;;
     59      1.1  christos   esac
     60      1.1  christos ])
     61