mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Add terminal width detection to llvm::sys::Process. This is needed to
fix Clang PRs 4148 and 4183. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71448 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -24,6 +24,9 @@
|
||||
#ifdef HAVE_MALLOC_MALLOC_H
|
||||
#include <malloc/malloc.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//=== WARNING: Implementation here must contain only generic UNIX code that
|
||||
@@ -190,3 +193,37 @@ bool Process::StandardErrIsDisplayed() {
|
||||
// If we don't have isatty, just return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
static unsigned getColumns(int FileID) {
|
||||
// If COLUMNS is defined in the environment, wrap to that many columns.
|
||||
if (const char *ColumnsStr = std::getenv("COLUMNS")) {
|
||||
int Columns = std::atoi(ColumnsStr);
|
||||
if (Columns > 0)
|
||||
return Columns;
|
||||
}
|
||||
|
||||
unsigned Columns = 0;
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
// Try to determine the width of the terminal.
|
||||
struct winsize ws;
|
||||
if (ioctl(FileID, TIOCGWINSZ, &ws) == 0)
|
||||
Columns = ws.ws_col;
|
||||
#endif
|
||||
|
||||
return Columns;
|
||||
}
|
||||
|
||||
unsigned Process::StandardOutColumns() {
|
||||
if (!StandardOutIsDisplayed())
|
||||
return 0;
|
||||
|
||||
return getColumns(1);
|
||||
}
|
||||
|
||||
unsigned Process::StandardErrColumns() {
|
||||
if (!StandardErrIsDisplayed())
|
||||
return 0;
|
||||
|
||||
return getColumns(2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user