Blame m4/open.m4

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