Skip to content

Commit a3058d5

Browse files
authored
[libc++] Guard fileno() and isatty() usage correctly for Newlib. (#166668)
Including unistd.h does not expose fileno() on Newlib.
1 parent ca72e8d commit a3058d5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

libcxx/src/print.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
# include <windows.h>
2323
#elif __has_include(<unistd.h>)
2424
# include <unistd.h>
25+
# if defined(_NEWLIB_VERSION)
26+
# if defined(_POSIX_C_SOURCE) && __has_include(<stdio.h>)
27+
# include <stdio.h>
28+
# define HAS_FILENO_AND_ISATTY
29+
# endif
30+
# else
31+
# define HAS_FILENO_AND_ISATTY
32+
# endif
2533
#endif
2634

2735
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -56,7 +64,7 @@ __write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wst
5664
}
5765
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
5866

59-
#elif __has_include(<unistd.h>) // !_LIBCPP_WIN32API
67+
#elif defined(HAS_FILENO_AND_ISATTY) // !_LIBCPP_WIN32API
6068

6169
_LIBCPP_EXPORTED_FROM_ABI bool __is_posix_terminal(FILE* __stream) { return isatty(fileno(__stream)); }
6270
#endif

0 commit comments

Comments
 (0)