Changeset 68836 in vbox
- Timestamp:
- Sep 22, 2017 4:37:46 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r68818 r68836 1933 1933 # define RTStrmFlush RT_MANGLER(RTStrmFlush) 1934 1934 # define RTStrmGetCh RT_MANGLER(RTStrmGetCh) 1935 # define RTStrmInputGetEchoChars RT_MANGLER(RTStrmInputGetEchoChars)1936 1935 # define RTStrmGetLine RT_MANGLER(RTStrmGetLine) 1937 1936 # define RTStrmOpen RT_MANGLER(RTStrmOpen) … … 1945 1944 # define RTStrmReadEx RT_MANGLER(RTStrmReadEx) 1946 1945 # define RTStrmRewind RT_MANGLER(RTStrmRewind) 1947 # define RTStrmInputSetEchoChars RT_MANGLER(RTStrmInputSetEchoChars)1948 1946 # define RTStrmSetMode RT_MANGLER(RTStrmSetMode) 1949 1947 # define RTStrmWriteEx RT_MANGLER(RTStrmWriteEx) 1948 # define RTStrmIsTerminal RT_MANGLER(RTStrmIsTerminal) 1949 # define RTStrmInputGetEchoChars RT_MANGLER(RTStrmInputGetEchoChars) 1950 # define RTStrmInputSetEchoChars RT_MANGLER(RTStrmInputSetEchoChars) 1951 # define RTStrmQueryTerminalWidth RT_MANGLER(RTStrmQueryTerminalWidth) 1950 1952 # define RTStrNCmp RT_MANGLER(RTStrNCmp) 1951 1953 # define RTStrNICmp RT_MANGLER(RTStrNICmp) -
trunk/include/iprt/stream.h
r62473 r68836 148 148 149 149 /** 150 * Checks if this is a terminal (TTY) or not. 151 * 152 * @returns true if it is, false if it isn't or the stream isn't valid. 153 * @param pStream The stream. 154 */ 155 RTR3DECL(bool) RTStrmIsTerminal(PRTSTREAM pStream); 156 157 /** 158 * Gets the width of the terminal the stream is associated with. 159 * 160 * @returns IPRT status code. 161 * @retval VERR_INVALID_FUNCTION if not connected to a terminal. 162 * @param pStream The stream. 163 * @param pcchWidth Where to return the width. This will never be zero 164 * and always be set, even on error. 165 */ 166 RTR3DECL(int) RTStrmQueryTerminalWidth(PRTSTREAM pStream, uint32_t *pcchWidth); 167 168 /** 150 169 * Rewinds the stream. 151 170 * -
trunk/src/VBox/Runtime/r3/stream.cpp
r62592 r68836 60 60 #ifdef RT_OS_WINDOWS 61 61 # include <iprt/win/windows.h> 62 #endif 63 #ifndef RT_OS_WINDOWS 62 #else 64 63 # include <termios.h> 65 64 # include <unistd.h> … … 553 552 return rc; 554 553 } 554 555 556 RTR3DECL(bool) RTStrmIsTerminal(PRTSTREAM pStream) 557 { 558 AssertPtrReturn(pStream, false); 559 AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, false); 560 561 if (pStream->pFile) 562 { 563 int fh = fileno(pStream->pFile); 564 if (isatty(fh)) 565 { 566 #ifdef RT_OS_WINDOWS 567 DWORD dwMode; 568 HANDLE hCon = (HANDLE)_get_osfhandle(fh); 569 if (GetConsoleMode(hCon, &dwMode)) 570 return true; 571 #else 572 return true; 573 #endif 574 } 575 } 576 return false; 577 } 578 579 580 RTR3DECL(int) RTStrmQueryTerminalWidth(PRTSTREAM pStream, uint32_t *pcchWidth) 581 { 582 AssertPtrReturn(pcchWidth, VERR_INVALID_HANDLE); 583 *pcchWidth = 80; 584 585 AssertPtrReturn(pStream, VERR_INVALID_HANDLE); 586 AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_HANDLE); 587 588 if (pStream->pFile) 589 { 590 int fh = fileno(pStream->pFile); 591 if (isatty(fh)) 592 { 593 #ifdef RT_OS_WINDOWS 594 CONSOLE_SCREEN_BUFFER_INFO Info; 595 HANDLE hCon = (HANDLE)_get_osfhandle(fh); 596 RT_ZERO(Info); 597 if (GetConsoleScreenBufferInfo(hCon, &Info)) 598 { 599 *pcchWidth = Info.dwSize.X ? Info.dwSize.X : 80; 600 return VINF_SUCCESS; 601 } 602 return RTErrConvertFromWin32(GetLastError()); 603 #else 604 struct winsize Info; 605 RT_ZERO(Info); 606 int rc = ioctl(fh, TIOCGWINSZ, &Info); 607 if (rc >= 0) 608 { 609 *pcchWidth = Info.ws_row ? Info.ws_row : 80; 610 return VINF_SUCCESS; 611 } 612 return RTErrConvertFromErrno(errno); 613 #endif 614 } 615 } 616 return VERR_INVALID_FUNCTION; 617 } 618 555 619 556 620
Note:
See TracChangeset
for help on using the changeset viewer.