Skip to content

Commit 9307067

Browse files
Alexandre OlivaAlexandre Oliva
authored andcommitted
libstdc++: check for openat
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.
1 parent 5d8a5f0 commit 9307067

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

libstdc++-v3/acinclude.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,6 +4772,18 @@ dnl
47724772
if test $glibcxx_cv_dirfd = yes; then
47734773
AC_DEFINE(HAVE_DIRFD, 1, [Define if dirfd is available in <dirent.h>.])
47744774
fi
4775+
dnl
4776+
AC_CACHE_CHECK([for openat],
4777+
glibcxx_cv_openat, [dnl
4778+
GCC_TRY_COMPILE_OR_LINK(
4779+
[#include <fcntl.h>],
4780+
[int fd = ::openat(AT_FDCWD, "", 0);],
4781+
[glibcxx_cv_openat=yes],
4782+
[glibcxx_cv_openat=no])
4783+
])
4784+
if test $glibcxx_cv_openat = yes; then
4785+
AC_DEFINE(HAVE_OPENAT, 1, [Define if openat is available in <fcntl.h>.])
4786+
fi
47754787
dnl
47764788
AC_CACHE_CHECK([for unlinkat],
47774789
glibcxx_cv_unlinkat, [dnl

libstdc++-v3/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@
292292
/* Define if <math.h> defines obsolete isnan function. */
293293
#undef HAVE_OBSOLETE_ISNAN
294294

295+
/* Define if openat is available in <fcntl.h>. */
296+
#undef HAVE_OPENAT
297+
295298
/* Define if poll is available in <poll.h>. */
296299
#undef HAVE_POLL
297300

libstdc++-v3/configure

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77177,6 +77177,61 @@ $as_echo "$glibcxx_cv_dirfd" >&6; }
7717777177

7717877178
$as_echo "#define HAVE_DIRFD 1" >>confdefs.h
7717977179

77180+
fi
77181+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for openat" >&5
77182+
$as_echo_n "checking for openat... " >&6; }
77183+
if ${glibcxx_cv_openat+:} false; then :
77184+
$as_echo_n "(cached) " >&6
77185+
else
77186+
if test x$gcc_no_link = xyes; then
77187+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
77188+
/* end confdefs.h. */
77189+
#include <fcntl.h>
77190+
int
77191+
main ()
77192+
{
77193+
int fd = ::openat(AT_FDCWD, "", 0);
77194+
;
77195+
return 0;
77196+
}
77197+
_ACEOF
77198+
if ac_fn_cxx_try_compile "$LINENO"; then :
77199+
glibcxx_cv_openat=yes
77200+
else
77201+
glibcxx_cv_openat=no
77202+
fi
77203+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
77204+
else
77205+
if test x$gcc_no_link = xyes; then
77206+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
77207+
fi
77208+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
77209+
/* end confdefs.h. */
77210+
#include <fcntl.h>
77211+
int
77212+
main ()
77213+
{
77214+
int fd = ::openat(AT_FDCWD, "", 0);
77215+
;
77216+
return 0;
77217+
}
77218+
_ACEOF
77219+
if ac_fn_cxx_try_link "$LINENO"; then :
77220+
glibcxx_cv_openat=yes
77221+
else
77222+
glibcxx_cv_openat=no
77223+
fi
77224+
rm -f core conftest.err conftest.$ac_objext \
77225+
conftest$ac_exeext conftest.$ac_ext
77226+
fi
77227+
77228+
fi
77229+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_openat" >&5
77230+
$as_echo "$glibcxx_cv_openat" >&6; }
77231+
if test $glibcxx_cv_openat = yes; then
77232+
77233+
$as_echo "#define HAVE_OPENAT 1" >>confdefs.h
77234+
7718077235
fi
7718177236
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for unlinkat" >&5
7718277237
$as_echo_n "checking for unlinkat... " >&6; }

libstdc++-v3/src/filesystem/dir-common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ struct _Dir_base
199199
#endif
200200

201201

202-
#ifdef AT_FDCWD
202+
#if _GLIBCXX_HAVE_OPENAT && defined AT_FDCWD
203203
fd = ::openat(fd, pathname, flags);
204204
#else
205205
// If we cannot use openat, there's no benefit to using posix::open unless

libstdc++-v3/src/filesystem/dir.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct fs::_Dir : std::filesystem::_Dir_base
120120
dir_and_pathname() const noexcept
121121
{
122122
const fs::path& p = entry.path();
123-
#if _GLIBCXX_HAVE_DIRFD
123+
#if _GLIBCXX_HAVE_DIRFD && _GLIBCXX_HAVE_OPENAT
124124
return {::dirfd(this->dirp), std::prev(p.end())->c_str()};
125125
#endif
126126
return {this->fdcwd(), p.c_str()};

0 commit comments

Comments
 (0)