diff mbox series

[committed] libstdc++: Do not use isatty on avr [PR115482]

Message ID 20240723094629.3664516-1-jwakely@redhat.com
State New
Headers show
Series [committed] libstdc++: Do not use isatty on avr [PR115482] | expand

Commit Message

Jonathan Wakely July 23, 2024, 9:38 a.m. UTC
I'm pushing this workaround from Detlef.

I incorrectly assumed that <unistd.h> is enough to ensure isatty is
present, but that isn't true for avr-libc.

It might be cleaner to add a proper autoconf check for isatty and dup,
but we don't have any reports of it failing for other targets. This
simple workaround solves the immediate problem in time for the 14.2
release.

Apart from using __write_to_terminal in the 27_io/print/2.cc test, the
functions in this file are not actually used for non-Windows targets. As
long as they compile and don't break the build, that's good enough.

Tested x86_64-linux, built on avr and mingw-w64.

Pushed to trunk, gcc-14 backport when testing finishes.

-- >8 --

avrlibc has an incomplete unistd.h that doesn't have isatty.
So building libstdc++ fails when compiling c++23/print.cc.
As a workaround I added a check for AVR.

libstdc++-v3/ChangeLog:

	PR libstdc++/115482
	* src/c++23/print.cc (__open_terminal) [__AVR__]: Do not use
	isatty.
---
 libstdc++-v3/src/c++23/print.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index 99a19cd4500..558dc149d12 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -75,7 +75,7 @@  namespace
 #ifdef _WIN32
 	if (int fd = ::_fileno(f); fd >= 0)
 	  return check_for_console((void*)_get_osfhandle(fd));
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
 	if (int fd = (::fileno)(f); fd >= 0 && ::isatty(fd))
 	  return f;
 #endif
@@ -100,7 +100,7 @@  namespace
 #ifdef _WIN32
     if (auto fb = dynamic_cast<filebuf*>(sb))
       return check_for_console(fb->native_handle());
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
     if (auto fb = dynamic_cast<filebuf*>(sb))
       if (int fd = fb->native_handle(); fd >= 0 && ::isatty(fd))
 	return ::fdopen(::dup(fd), "w"); // Caller must call fclose.