File tree Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -19,20 +19,23 @@ if (ANDROID OR CYGWIN OR CMAKE_SYSTEM_NAME MATCHES "AIX|DragonFly|FreeBSD|Haiku|
1919 set (HAVE_SYS_MMAN_H 1)
2020 set (HAVE_SYSEXITS_H 1)
2121 set (HAVE_UNISTD_H 1)
22+ set (HAVE_SYS_IOCTL_H 1)
2223elseif (APPLE )
2324 set (HAVE_MACH_MACH_H 1)
2425 set (HAVE_MALLOC_MALLOC_H 1)
2526 set (HAVE_PTHREAD_H 1)
2627 set (HAVE_SYS_MMAN_H 1)
2728 set (HAVE_SYSEXITS_H 1)
2829 set (HAVE_UNISTD_H 1)
30+ set (HAVE_SYS_IOCTL_H 1)
2931elseif (WIN32 )
3032 set (HAVE_MACH_MACH_H 0)
3133 set (HAVE_MALLOC_MALLOC_H 0)
3234 set (HAVE_PTHREAD_H 0)
3335 set (HAVE_SYS_MMAN_H 0)
3436 set (HAVE_SYSEXITS_H 0)
3537 set (HAVE_UNISTD_H 0)
38+ set (HAVE_SYS_IOCTL_H 0)
3639elseif (ZOS)
3740 # Confirmed in
3841 # https://github.com/llvm/llvm-project/pull/104706#issuecomment-2297109613
@@ -42,6 +45,7 @@ elseif (ZOS)
4245 set (HAVE_SYS_MMAN_H 1)
4346 set (HAVE_SYSEXITS_H 0)
4447 set (HAVE_UNISTD_H 1)
48+ set (HAVE_SYS_IOCTL_H 1)
4549else ()
4650 # Other platforms that we don't promise support for.
4751 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
5054 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
5155 check_include_file(sysexits.h HAVE_SYSEXITS_H)
5256 check_include_file(unistd.h HAVE_UNISTD_H)
57+ check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
5358endif ()
5459
5560if ( UNIX AND NOT (APPLE OR BEOS OR HAIKU) )
Original file line number Diff line number Diff line change 164164/* Define to 1 if you have the <sys/mman.h> header file. */
165165#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H}
166166
167+ /* Define to 1 if you have the <sys/ioctl.h> header file. */
168+ #cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H}
169+
167170/* Define to 1 if stat struct has st_mtimespec member .*/
168171#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC}
169172
Original file line number Diff line number Diff line change 3434#ifdef HAVE_GETAUXVAL
3535#include < sys/auxv.h>
3636#endif
37+ #ifdef HAVE_SYS_IOCTL_H
38+ #include < sys/ioctl.h>
39+ #endif
3740
3841// ===----------------------------------------------------------------------===//
3942// === WARNING: Implementation here must contain only generic UNIX code that
@@ -304,31 +307,40 @@ bool Process::FileDescriptorIsDisplayed(int fd) {
304307#endif
305308}
306309
307- static unsigned getColumns () {
310+ static unsigned getColumns (int FileID ) {
308311 // If COLUMNS is defined in the environment, wrap to that many columns.
312+ // This matches GCC.
309313 if (const char *ColumnsStr = std::getenv (" COLUMNS" )) {
310314 int Columns = std::atoi (ColumnsStr);
311315 if (Columns > 0 )
312316 return Columns;
313317 }
314318
315- // We used to call ioctl TIOCGWINSZ to determine the width. It is considered
316- // unuseful.
317- return 0 ;
319+ // Some shells do not export COLUMNS; query the column count via ioctl()
320+ // instead if it isn't available.
321+ unsigned Columns = 0 ;
322+
323+ #ifdef HAVE_SYS_IOCTL_H
324+ struct winsize ws;
325+ if (ioctl (FileID, TIOCGWINSZ, &ws) == 0 )
326+ Columns = ws.ws_col ;
327+ #endif
328+
329+ return Columns;
318330}
319331
320332unsigned Process::StandardOutColumns () {
321333 if (!StandardOutIsDisplayed ())
322334 return 0 ;
323335
324- return getColumns ();
336+ return getColumns (0 );
325337}
326338
327339unsigned Process::StandardErrColumns () {
328340 if (!StandardErrIsDisplayed ())
329341 return 0 ;
330342
331- return getColumns ();
343+ return getColumns (1 );
332344}
333345
334346static bool terminalHasColors () {
You can’t perform that action at this time.
0 commit comments