Blame m4/open-slash.m4

Packit Service 991b93
# open-slash.m4 serial 1
Packit Service 991b93
dnl Copyright (C) 2007-2020 Free Software Foundation, Inc.
Packit Service 991b93
dnl This file is free software; the Free Software Foundation
Packit Service 991b93
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 991b93
dnl with or without modifications, as long as this notice is preserved.
Packit Service 991b93
Packit Service 991b93
dnl Tests whether open() and creat() recognize a trailing slash.
Packit Service 991b93
dnl Sets gl_cv_func_open_slash.
Packit Service 991b93
AC_DEFUN([gl_OPEN_TRAILING_SLASH_BUG],
Packit Service 991b93
[
Packit Service 991b93
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service 991b93
  dnl open("foo/") should not create a file when the file name has a
Packit Service 991b93
  dnl trailing slash.  FreeBSD only has the problem on symlinks.
Packit Service 991b93
  AC_CHECK_FUNCS_ONCE([lstat])
Packit Service 991b93
  AC_CACHE_CHECK([whether open recognizes a trailing slash],
Packit Service 991b93
    [gl_cv_func_open_slash],
Packit Service 991b93
    [# Assume that if we have lstat, we can also check symlinks.
Packit Service 991b93
     if test $ac_cv_func_lstat = yes; then
Packit Service 991b93
       touch conftest.tmp
Packit Service 991b93
       ln -s conftest.tmp conftest.lnk
Packit Service 991b93
     fi
Packit Service 991b93
     AC_RUN_IFELSE(
Packit Service 991b93
       [AC_LANG_SOURCE([[
Packit Service 991b93
#include <fcntl.h>
Packit Service 991b93
#if HAVE_UNISTD_H
Packit Service 991b93
# include <unistd.h>
Packit Service 991b93
#endif
Packit Service 991b93
int main ()
Packit Service 991b93
{
Packit Service 991b93
  int result = 0;
Packit Service 991b93
#if HAVE_LSTAT
Packit Service 991b93
  if (open ("conftest.lnk/", O_RDONLY) != -1)
Packit Service 991b93
    result |= 1;
Packit Service 991b93
#endif
Packit Service 991b93
  if (open ("conftest.sl/", O_CREAT, 0600) >= 0)
Packit Service 991b93
    result |= 2;
Packit Service 991b93
  return result;
Packit Service 991b93
}]])],
Packit Service 991b93
       [gl_cv_func_open_slash=yes],
Packit Service 991b93
       [gl_cv_func_open_slash=no],
Packit Service 991b93
       [
Packit Service 991b93
changequote(,)dnl
Packit Service 991b93
        case "$host_os" in
Packit Service 991b93
          freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
Packit Service 991b93
            gl_cv_func_open_slash="guessing no" ;;
Packit Service 991b93
          *)
Packit Service 991b93
            gl_cv_func_open_slash="guessing yes" ;;
Packit Service 991b93
        esac
Packit Service 991b93
changequote([,])dnl
Packit Service 991b93
       ])
Packit Service 991b93
     rm -f conftest.sl conftest.tmp conftest.lnk
Packit Service 991b93
    ])
Packit Service 991b93
  case "$gl_cv_func_open_slash" in
Packit Service 991b93
    *no)
Packit Service 991b93
      AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
Packit Service 991b93
        [Define to 1 if open() fails to recognize a trailing slash.])
Packit Service 991b93
      ;;
Packit Service 991b93
  esac
Packit Service 991b93
])