]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: check for openat
authorAlexandre Oliva <oliva@adacore.com>
Fri, 24 Jun 2022 02:20:53 +0000 (23:20 -0300)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 4 Oct 2023 11:10:05 +0000 (12:10 +0100)
rtems6.0 has fdopendir, and fcntl.h defines AT_FDCWD and declares
openat, but there's no openat in libc.  Adjust dir-common.h to not
assume ::openat just because of AT_FDCWD.

for  libstdc++-v3/ChangeLog

* acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for
openat.
* configure, config.h.in: Rebuilt.
* src/filesystem/dir-common.h (openat): Use ::openat if
_GLIBCXX_HAVE_OPENAT.
* src/filesystem/dir.cc (dir_and_pathname): Use dirfd if
_GLIBCXX_HAVE_OPENAT.

(cherry picked from commit 93070671eae44f24ba822383e17571a39257c637)

libstdc++-v3/acinclude.m4
libstdc++-v3/config.h.in
libstdc++-v3/configure
libstdc++-v3/src/filesystem/dir-common.h
libstdc++-v3/src/filesystem/dir.cc

index 61ab7885f4d93ff1dc1f01806127ebad847937c4..696756a6df6ad4742100198beb6890094923d5f0 100644 (file)
@@ -4849,6 +4849,18 @@ dnl
   if test $glibcxx_cv_dirfd = yes; then
     AC_DEFINE(HAVE_DIRFD, 1, [Define if dirfd is available in <dirent.h>.])
   fi
+dnl
+  AC_CACHE_CHECK([for openat],
+    glibcxx_cv_openat, [dnl
+    GCC_TRY_COMPILE_OR_LINK(
+      [#include <fcntl.h>],
+      [int fd = ::openat(AT_FDCWD, "", 0);],
+      [glibcxx_cv_openat=yes],
+      [glibcxx_cv_openat=no])
+  ])
+  if test $glibcxx_cv_openat = yes; then
+    AC_DEFINE(HAVE_OPENAT, 1, [Define if openat is available in <fcntl.h>.])
+  fi
 dnl
   AC_CACHE_CHECK([for unlinkat],
     glibcxx_cv_unlinkat, [dnl
index 2c270f9c7a35e25d21700d9cac5059972ef4b98b..f8f8e6bd557bcb477567c00811f4f518d4e442f0 100644 (file)
 /* Define if <math.h> defines obsolete isnan function. */
 #undef HAVE_OBSOLETE_ISNAN
 
+/* Define if openat is available in <fcntl.h>. */
+#undef HAVE_OPENAT
+
 /* Define if poll is available in <poll.h>. */
 #undef HAVE_POLL
 
index ec0d37840c966fd8aa199a9081a766505edbb7c4..8633b8a6dabac53d61cb46bb58836b03150dd8b5 100755 (executable)
@@ -76894,6 +76894,61 @@ $as_echo "$glibcxx_cv_dirfd" >&6; }
 
 $as_echo "#define HAVE_DIRFD 1" >>confdefs.h
 
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openat" >&5
+$as_echo_n "checking for openat... " >&6; }
+if ${glibcxx_cv_openat+:} false; 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 <fcntl.h>
+int
+main ()
+{
+int fd = ::openat(AT_FDCWD, "", 0);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  glibcxx_cv_openat=yes
+else
+  glibcxx_cv_openat=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 <fcntl.h>
+int
+main ()
+{
+int fd = ::openat(AT_FDCWD, "", 0);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  glibcxx_cv_openat=yes
+else
+  glibcxx_cv_openat=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_openat" >&5
+$as_echo "$glibcxx_cv_openat" >&6; }
+  if test $glibcxx_cv_openat = yes; then
+
+$as_echo "#define HAVE_OPENAT 1" >>confdefs.h
+
   fi
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for unlinkat" >&5
 $as_echo_n "checking for unlinkat... " >&6; }
index 9c088a22c24ec6be26ef7ce5520c5b22cffe7fe0..f6b9cc8779d11b365686b7e3b5c52716fd35a0c4 100644 (file)
@@ -199,7 +199,7 @@ struct _Dir_base
 #endif
 
 
-#ifdef AT_FDCWD
+#if _GLIBCXX_HAVE_OPENAT && defined AT_FDCWD
     fd = ::openat(fd, pathname, flags);
 #else
     // If we cannot use openat, there's no benefit to using posix::open unless
index 85003eb170badbdad516474fcef0376313cfbe2c..2fedca36a06e38555bc72deba753420e2b3a7071 100644 (file)
@@ -120,7 +120,7 @@ struct fs::_Dir : std::filesystem::_Dir_base
   dir_and_pathname() const noexcept
   {
     const fs::path& p = entry.path();
-#if _GLIBCXX_HAVE_DIRFD
+#if _GLIBCXX_HAVE_DIRFD && _GLIBCXX_HAVE_OPENAT
     return {::dirfd(this->dirp), std::prev(p.end())->c_str()};
 #endif
     return {this->fdcwd(), p.c_str()};