From: Alexandre Oliva <oliva@adacore.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: gcc Patches <gcc-patches@gcc.gnu.org>,
"libstdc++" <libstdc++@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++-v3: check for openat
Date: Thu, 23 Jun 2022 08:08:17 -0300 [thread overview]
Message-ID: <orwnd74oym.fsf@lxoliva.fsfla.org> (raw)
In-Reply-To: <CACb0b4=1zk4Ls1Y0b9yEb0TxScnx_odzonU3-ovE=UdeAdR-5w@mail.gmail.com> (Jonathan Wakely's message of "Wed, 22 Jun 2022 11:36:17 +0100")
On Jun 22, 2022, Jonathan Wakely <jwakely@redhat.com> wrote:
> There are other interactions between AT_CDCWD and ::openat not covered
> by this patch. I this this also needs to check HAVE_OPENAT:
Here's an updated version, tested with this additional change.
libstdc++: check for openat
From: Alexandre Oliva <oliva@adacore.com>
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.
* aclocal.m4, 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.
---
libstdc++-v3/acinclude.m4 | 12 +++++++
libstdc++-v3/config.h.in | 3 ++
libstdc++-v3/configure | 55 ++++++++++++++++++++++++++++++
libstdc++-v3/src/filesystem/dir-common.h | 2 +
libstdc++-v3/src/filesystem/dir.cc | 2 +
5 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 138bd58d86cb9..e3cc3a8e867d3 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4772,6 +4772,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
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index f30a8c51c458c..2a3972eef5412 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -292,6 +292,9 @@
/* 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
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 9b94fd71e4248..eac6039212168 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -77177,6 +77177,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; }
diff --git a/libstdc++-v3/src/filesystem/dir-common.h b/libstdc++-v3/src/filesystem/dir-common.h
index 365fd527f4d68..669780ea23fe5 100644
--- a/libstdc++-v3/src/filesystem/dir-common.h
+++ b/libstdc++-v3/src/filesystem/dir-common.h
@@ -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
diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
index b451902c4a1b1..e64489162e5ff 100644
--- a/libstdc++-v3/src/filesystem/dir.cc
+++ b/libstdc++-v3/src/filesystem/dir.cc
@@ -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()};
--
Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
Free Software Activist GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts. Ask me about <https://stallmansupport.org>
next prev parent reply other threads:[~2022-06-23 11:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-22 6:41 Alexandre Oliva
2022-06-22 10:36 ` Jonathan Wakely
2022-06-23 4:41 ` Alexandre Oliva
2022-06-23 9:29 ` Jonathan Wakely
2022-06-23 11:08 ` Alexandre Oliva [this message]
2022-06-23 11:37 ` Jonathan Wakely
2022-06-23 14:05 ` Alexandre Oliva
2022-06-23 17:47 ` Jonathan Wakely
2022-06-27 12:00 ` Alexandre Oliva
2022-06-27 13:05 ` Alexandre Oliva
2022-06-27 13:32 ` Jonathan Wakely
2022-06-27 14:00 ` Jonathan Wakely
2022-06-27 15:56 ` Jonathan Wakely
2022-06-27 22:03 ` Alexandre Oliva
2022-06-28 8:36 ` Jonathan Wakely
2022-06-28 12:04 ` Alexandre Oliva
2022-06-28 13:12 ` Jonathan Wakely
2022-06-24 11:03 ` Jonathan Wakely
2022-06-27 9:49 ` Alexandre Oliva
2022-06-27 9:52 ` Jonathan Wakely
2022-06-24 2:34 ` Alexandre Oliva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=orwnd74oym.fsf@lxoliva.fsfla.org \
--to=oliva@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely@redhat.com \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).