1# open.m4 serial 15 2dnl Copyright (C) 2007-2018 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7AC_DEFUN([gl_FUNC_OPEN], 8[ 9 AC_REQUIRE([AC_CANONICAL_HOST]) 10 AC_REQUIRE([gl_PREPROC_O_CLOEXEC]) 11 case "$host_os" in 12 mingw* | pw*) 13 REPLACE_OPEN=1 14 ;; 15 *) 16 dnl open("foo/") should not create a file when the file name has a 17 dnl trailing slash. FreeBSD only has the problem on symlinks. 18 AC_CHECK_FUNCS_ONCE([lstat]) 19 if test "$gl_cv_macro_O_CLOEXEC" != yes; then 20 REPLACE_OPEN=1 21 fi 22 AC_CACHE_CHECK([whether open recognizes a trailing slash], 23 [gl_cv_func_open_slash], 24 [# Assume that if we have lstat, we can also check symlinks. 25 if test $ac_cv_func_lstat = yes; then 26 touch conftest.tmp 27 ln -s conftest.tmp conftest.lnk 28 fi 29 AC_RUN_IFELSE( 30 [AC_LANG_SOURCE([[ 31#include <fcntl.h> 32#if HAVE_UNISTD_H 33# include <unistd.h> 34#endif 35int main () 36{ 37 int result = 0; 38#if HAVE_LSTAT 39 if (open ("conftest.lnk/", O_RDONLY) != -1) 40 result |= 1; 41#endif 42 if (open ("conftest.sl/", O_CREAT, 0600) >= 0) 43 result |= 2; 44 return result; 45}]])], 46 [gl_cv_func_open_slash=yes], 47 [gl_cv_func_open_slash=no], 48 [ 49changequote(,)dnl 50 case "$host_os" in 51 freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*) 52 gl_cv_func_open_slash="guessing no" ;; 53 *) 54 gl_cv_func_open_slash="guessing yes" ;; 55 esac 56changequote([,])dnl 57 ]) 58 rm -f conftest.sl conftest.tmp conftest.lnk 59 ]) 60 case "$gl_cv_func_open_slash" in 61 *no) 62 AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1], 63 [Define to 1 if open() fails to recognize a trailing slash.]) 64 REPLACE_OPEN=1 65 ;; 66 esac 67 ;; 68 esac 69 dnl Replace open() for supporting the gnulib-defined fchdir() function, 70 dnl to keep fchdir's bookkeeping up-to-date. 71 m4_ifdef([gl_FUNC_FCHDIR], [ 72 if test $REPLACE_OPEN = 0; then 73 gl_TEST_FCHDIR 74 if test $HAVE_FCHDIR = 0; then 75 REPLACE_OPEN=1 76 fi 77 fi 78 ]) 79 dnl Replace open() for supporting the gnulib-defined O_NONBLOCK flag. 80 m4_ifdef([gl_NONBLOCKING_IO], [ 81 if test $REPLACE_OPEN = 0; then 82 gl_NONBLOCKING_IO 83 if test $gl_cv_have_open_O_NONBLOCK != yes; then 84 REPLACE_OPEN=1 85 fi 86 fi 87 ]) 88]) 89 90# Prerequisites of lib/open.c. 91AC_DEFUN([gl_PREREQ_OPEN], 92[ 93 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T]) 94 : 95]) 96