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|
19
19
set (HAVE_SYS_MMAN_H 1 )
20
20
set (HAVE_SYSEXITS_H 1 )
21
21
set (HAVE_UNISTD_H 1 )
22
+ set (HAVE_SYS_IOCTL_H 1 )
22
23
elseif (APPLE )
23
24
set (HAVE_MACH_MACH_H 1 )
24
25
set (HAVE_MALLOC_MALLOC_H 1 )
25
26
set (HAVE_PTHREAD_H 1 )
26
27
set (HAVE_SYS_MMAN_H 1 )
27
28
set (HAVE_SYSEXITS_H 1 )
28
29
set (HAVE_UNISTD_H 1 )
30
+ set (HAVE_SYS_IOCTL_H 1 )
29
31
elseif (WIN32 )
30
32
set (HAVE_MACH_MACH_H 0 )
31
33
set (HAVE_MALLOC_MALLOC_H 0 )
32
34
set (HAVE_PTHREAD_H 0 )
33
35
set (HAVE_SYS_MMAN_H 0 )
34
36
set (HAVE_SYSEXITS_H 0 )
35
37
set (HAVE_UNISTD_H 0 )
38
+ set (HAVE_SYS_IOCTL_H 0 )
36
39
elseif (ZOS )
37
40
# Confirmed in
38
41
# https://github.com/llvm/llvm-project/pull/104706#issuecomment-2297109613
@@ -42,6 +45,7 @@ elseif (ZOS)
42
45
set (HAVE_SYS_MMAN_H 1 )
43
46
set (HAVE_SYSEXITS_H 0 )
44
47
set (HAVE_UNISTD_H 1 )
48
+ set (HAVE_SYS_IOCTL_H 1 )
45
49
else ()
46
50
# Other platforms that we don't promise support for.
47
51
check_include_file (mach/mach.h HAVE_MACH_MACH_H )
50
54
check_include_file (sys/mman.h HAVE_SYS_MMAN_H )
51
55
check_include_file (sysexits.h HAVE_SYSEXITS_H )
52
56
check_include_file (unistd.h HAVE_UNISTD_H )
57
+ check_include_file (sys/ioctl.h HAVE_SYS_IOCTL_H )
53
58
endif ()
54
59
55
60
if ( UNIX AND NOT (APPLE OR BEOS OR HAIKU ) )
Original file line number Diff line number Diff line change 164
164
/* Define to 1 if you have the <sys/mman.h> header file . */
165
165
#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H}
166
166
167
+ /* Define to 1 if you have the <sys/ioctl.h> header file . */
168
+ #cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H}
169
+
167
170
/* Define to 1 if stat struct has st_mtimespec member .*/
168
171
#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC}
169
172
Original file line number Diff line number Diff line change 34
34
#ifdef HAVE_GETAUXVAL
35
35
#include < sys/auxv.h>
36
36
#endif
37
+ #ifdef HAVE_SYS_IOCTL_H
38
+ #include < sys/ioctl.h>
39
+ #endif
37
40
38
41
// ===----------------------------------------------------------------------===//
39
42
// === WARNING: Implementation here must contain only generic UNIX code that
@@ -304,31 +307,40 @@ bool Process::FileDescriptorIsDisplayed(int fd) {
304
307
#endif
305
308
}
306
309
307
- static unsigned getColumns () {
310
+ static unsigned getColumns (int FileID ) {
308
311
// If COLUMNS is defined in the environment, wrap to that many columns.
312
+ // This matches GCC.
309
313
if (const char *ColumnsStr = std::getenv (" COLUMNS" )) {
310
314
int Columns = std::atoi (ColumnsStr);
311
315
if (Columns > 0 )
312
316
return Columns;
313
317
}
314
318
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;
318
330
}
319
331
320
332
unsigned Process::StandardOutColumns () {
321
333
if (!StandardOutIsDisplayed ())
322
334
return 0 ;
323
335
324
- return getColumns ();
336
+ return getColumns (0 );
325
337
}
326
338
327
339
unsigned Process::StandardErrColumns () {
328
340
if (!StandardErrIsDisplayed ())
329
341
return 0 ;
330
342
331
- return getColumns ();
343
+ return getColumns (1 );
332
344
}
333
345
334
346
static bool terminalHasColors () {
You can’t perform that action at this time.
0 commit comments