src/filesystem/ops-common.c uses S_ISSOCK unconditionally without checking that it is available
As result compile fails for DJGPP when S_ISREG is available but S_ISSOCK is not. Included patch add configure check for S_ISSOCK
Andris ChangeLog entry: 2017-11-07 Andris Pavenis<andris.pavenis.iki.fi> * acinclude.m4 (GLIBCXX_CHECK_S_ISSOCK): Define * configure.ac: Check presence of S_ISSOCK * src/filesystem/ops-common.h: Only use S_ISSOCK if defined for target * config.h.in: Regenerate * configure: Regenerate
>From 5ab88b80a8cbbf4eee324510e5fae6fc6a9a1627 Mon Sep 17 00:00:00 2001 From: Andris Pavenis <andris.pave...@iki.fi> Date: Sun, 29 Oct 2017 13:08:24 +0200 Subject: [PATCH] 2017-11-07 Andris Pavenis<andris.pavenis.iki.fi> * acinclude.m4 (GLIBCXX_CHECK_S_ISSOCK): Define * configure.ac: Check presence of S_ISSOCK * src/filesystem/ops-common.h: Only use S_ISSOCK if defined for target * config.h.in: Regenerate * configure: Regenerate --- libstdc++-v3/acinclude.m4 | 32 ++++++++++++ libstdc++-v3/config.h.in | 3 ++ libstdc++-v3/configure | 84 ++++++++++++++++++++++++++++++++ libstdc++-v3/configure.ac | 1 + libstdc++-v3/src/filesystem/ops-common.h | 2 + 5 files changed, 122 insertions(+) diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 599308f587a..71db7cff283 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -410,6 +410,38 @@ AC_DEFUN([GLIBCXX_CHECK_S_ISREG_OR_S_IFREG], [ AC_LANG_RESTORE ]) +dnl +dnl Check whether S_ISSOCK (Posix) is available in <sys/stat.h>. +dnl Define HAVE_S_ISSOCK appropriately. +dnl +AC_DEFUN([GLIBCXX_CHECK_S_ISSOCK], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + AC_MSG_CHECKING([for S_ISSOCK]) + AC_CACHE_VAL(glibcxx_cv_S_ISSOCK, [ + GCC_TRY_COMPILE_OR_LINK( + [#include <sys/stat.h>], + [struct stat buffer; + fstat(0, &buffer); + S_ISSOCK(buffer.st_mode);], + [glibcxx_cv_S_ISSOCK=yes], + [glibcxx_cv_S_ISSOCK=no]) + ]) + res=no + if test $glibcxx_cv_S_ISSOCK = yes; then + AC_DEFINE(HAVE_S_ISSOCK, 1, + [Define if S_ISSOCK is available in <sys/stat.h>.]) + res=S_ISSOCK + fi + AC_MSG_RESULT($res) + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) dnl dnl Check whether poll is available in <poll.h>, and define HAVE_POLL. diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index e31e054c024..d2d9bfcf854 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -460,6 +460,9 @@ /* Define if S_ISREG is available in <sys/stat.h>. */ #undef HAVE_S_ISREG +/* Define if S_ISSOCK is available in <sys/stat.h>. */ +#undef HAVE_S_ISSOCK + /* Define to 1 if you have the `tanf' function. */ #undef HAVE_TANF diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 836a6d5a8f1..73b61213ed7 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -19606,6 +19606,90 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for S_ISSOCK" >&5 +$as_echo_n "checking for S_ISSOCK... " >&6; } + if test "${glibcxx_cv_S_ISSOCK+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + + if test x$gcc_no_link = xyes; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <sys/stat.h> +int +main () +{ +struct stat buffer; + fstat(0, &buffer); + S_ISSOCK(buffer.st_mode); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + glibcxx_cv_S_ISSOCK=yes +else + glibcxx_cv_S_ISSOCK=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + if test x$gcc_no_link = xyes; then + as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <sys/stat.h> +int +main () +{ +struct stat buffer; + fstat(0, &buffer); + S_ISSOCK(buffer.st_mode); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + glibcxx_cv_S_ISSOCK=yes +else + glibcxx_cv_S_ISSOCK=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + +fi + + res=no + if test $glibcxx_cv_S_ISSOCK = yes; then + +$as_echo "#define HAVE_S_ISSOCK 1" >>confdefs.h + + res=S_ISSOCK + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $res" >&5 +$as_echo "$res" >&6; } + + CXXFLAGS="$ac_save_CXXFLAGS" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + # For xsputn_2(). for ac_header in sys/uio.h do : diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 270dcbaf723..7d1ad2d8558 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -194,6 +194,7 @@ GLIBCXX_CHECK_LFS AC_CHECK_HEADERS(sys/ioctl.h sys/filio.h) GLIBCXX_CHECK_POLL GLIBCXX_CHECK_S_ISREG_OR_S_IFREG +GLIBCXX_CHECK_S_ISSOCK # For xsputn_2(). AC_CHECK_HEADERS(sys/uio.h) diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h index 12c12b08f8c..36be2723405 100644 --- a/libstdc++-v3/src/filesystem/ops-common.h +++ b/libstdc++-v3/src/filesystem/ops-common.h @@ -113,8 +113,10 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM return file_type::fifo; else if (S_ISLNK(st.st_mode)) return file_type::symlink; +#ifdef _GLIBCXX_HAVE_S_ISSOCK else if (S_ISSOCK(st.st_mode)) return file_type::socket; +#endif #endif return file_type::unknown; } -- 2.15.0