diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/System/Unix/Process.inc | 37 | ||||
-rw-r--r-- | llvm/lib/System/Win32/Process.inc | 16 |
2 files changed, 53 insertions, 0 deletions
diff --git a/llvm/lib/System/Unix/Process.inc b/llvm/lib/System/Unix/Process.inc index 8a2598bda4e..b1286b7bfcd 100644 --- a/llvm/lib/System/Unix/Process.inc +++ b/llvm/lib/System/Unix/Process.inc @@ -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); +} diff --git a/llvm/lib/System/Win32/Process.inc b/llvm/lib/System/Win32/Process.inc index 157483a07ca..e1d7a9222f7 100644 --- a/llvm/lib/System/Win32/Process.inc +++ b/llvm/lib/System/Win32/Process.inc @@ -131,4 +131,20 @@ bool Process::StandardErrIsDisplayed() { return GetFileType((HANDLE)_get_osfhandle(2)) == FILE_TYPE_CHAR; } +unsigned Process::StandardOutColumns() { + unsigned Columns = 0; + CONSOLE_SCREEN_BUFFER_INFO csbi; + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) + Columns = csbi.dwSize.X; + return Columns; +} + +unsigned Process::StandardErrColumns() { + unsigned Columns = 0; + CONSOLE_SCREEN_BUFFER_INFO csbi; + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &csbi)) + Columns = csbi.dwSize.X; + return Columns; +} + } |