Blame m4/open.m4

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