Blame m4/open.m4

Packit 8f70b4
# open.m4 serial 15
Packit 8f70b4
dnl Copyright (C) 2007-2018 Free Software Foundation, Inc.
Packit 8f70b4
dnl This file is free software; the Free Software Foundation
Packit 8f70b4
dnl gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
dnl with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_FUNC_OPEN],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 8f70b4
  AC_REQUIRE([gl_PREPROC_O_CLOEXEC])
Packit 8f70b4
  case "$host_os" in
Packit 8f70b4
    mingw* | pw*)
Packit 8f70b4
      REPLACE_OPEN=1
Packit 8f70b4
      ;;
Packit 8f70b4
    *)
Packit 8f70b4
      dnl open("foo/") should not create a file when the file name has a
Packit 8f70b4
      dnl trailing slash.  FreeBSD only has the problem on symlinks.
Packit 8f70b4
      AC_CHECK_FUNCS_ONCE([lstat])
Packit 8f70b4
      if test "$gl_cv_macro_O_CLOEXEC" != yes; then
Packit 8f70b4
        REPLACE_OPEN=1
Packit 8f70b4
      fi
Packit 8f70b4
      AC_CACHE_CHECK([whether open recognizes a trailing slash],
Packit 8f70b4
        [gl_cv_func_open_slash],
Packit 8f70b4
        [# Assume that if we have lstat, we can also check symlinks.
Packit 8f70b4
          if test $ac_cv_func_lstat = yes; then
Packit 8f70b4
            touch conftest.tmp
Packit 8f70b4
            ln -s conftest.tmp conftest.lnk
Packit 8f70b4
          fi
Packit 8f70b4
          AC_RUN_IFELSE(
Packit 8f70b4
            [AC_LANG_SOURCE([[
Packit 8f70b4
#include <fcntl.h>
Packit 8f70b4
#if HAVE_UNISTD_H
Packit 8f70b4
# include <unistd.h>
Packit 8f70b4
#endif
Packit 8f70b4
int main ()
Packit 8f70b4
{
Packit 8f70b4
  int result = 0;
Packit 8f70b4
#if HAVE_LSTAT
Packit 8f70b4
  if (open ("conftest.lnk/", O_RDONLY) != -1)
Packit 8f70b4
    result |= 1;
Packit 8f70b4
#endif
Packit 8f70b4
  if (open ("conftest.sl/", O_CREAT, 0600) >= 0)
Packit 8f70b4
    result |= 2;
Packit 8f70b4
  return result;
Packit 8f70b4
}]])],
Packit 8f70b4
            [gl_cv_func_open_slash=yes],
Packit 8f70b4
            [gl_cv_func_open_slash=no],
Packit 8f70b4
            [
Packit 8f70b4
changequote(,)dnl
Packit 8f70b4
             case "$host_os" in
Packit 8f70b4
               freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
Packit 8f70b4
                 gl_cv_func_open_slash="guessing no" ;;
Packit 8f70b4
               *)
Packit 8f70b4
                 gl_cv_func_open_slash="guessing yes" ;;
Packit 8f70b4
             esac
Packit 8f70b4
changequote([,])dnl
Packit 8f70b4
            ])
Packit 8f70b4
          rm -f conftest.sl conftest.tmp conftest.lnk
Packit 8f70b4
        ])
Packit 8f70b4
      case "$gl_cv_func_open_slash" in
Packit 8f70b4
        *no)
Packit 8f70b4
          AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
Packit 8f70b4
            [Define to 1 if open() fails to recognize a trailing slash.])
Packit 8f70b4
          REPLACE_OPEN=1
Packit 8f70b4
          ;;
Packit 8f70b4
      esac
Packit 8f70b4
      ;;
Packit 8f70b4
  esac
Packit 8f70b4
  dnl Replace open() for supporting the gnulib-defined fchdir() function,
Packit 8f70b4
  dnl to keep fchdir's bookkeeping up-to-date.
Packit 8f70b4
  m4_ifdef([gl_FUNC_FCHDIR], [
Packit 8f70b4
    if test $REPLACE_OPEN = 0; then
Packit 8f70b4
      gl_TEST_FCHDIR
Packit 8f70b4
      if test $HAVE_FCHDIR = 0; then
Packit 8f70b4
        REPLACE_OPEN=1
Packit 8f70b4
      fi
Packit 8f70b4
    fi
Packit 8f70b4
  ])
Packit 8f70b4
  dnl Replace open() for supporting the gnulib-defined O_NONBLOCK flag.
Packit 8f70b4
  m4_ifdef([gl_NONBLOCKING_IO], [
Packit 8f70b4
    if test $REPLACE_OPEN = 0; then
Packit 8f70b4
      gl_NONBLOCKING_IO
Packit 8f70b4
      if test $gl_cv_have_open_O_NONBLOCK != yes; then
Packit 8f70b4
        REPLACE_OPEN=1
Packit 8f70b4
      fi
Packit 8f70b4
    fi
Packit 8f70b4
  ])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Prerequisites of lib/open.c.
Packit 8f70b4
AC_DEFUN([gl_PREREQ_OPEN],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
Packit 8f70b4
  :
Packit 8f70b4
])