Changeset 54724 in vbox
- Timestamp:
- Mar 11, 2015 8:37:08 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
include/iprt/mangling.h (modified) (2 diffs)
-
include/iprt/stream.h (modified) (1 diff)
-
src/VBox/Runtime/r3/stream.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r54415 r54724 1475 1475 # define RTStrmFlush RT_MANGLER(RTStrmFlush) 1476 1476 # define RTStrmGetCh RT_MANGLER(RTStrmGetCh) 1477 # define RTStrmInputGetEchoChars RT_MANGLER(RTStrmInputGetEchoChars) 1477 1478 # define RTStrmGetLine RT_MANGLER(RTStrmGetLine) 1478 1479 # define RTStrmOpen RT_MANGLER(RTStrmOpen) … … 1486 1487 # define RTStrmReadEx RT_MANGLER(RTStrmReadEx) 1487 1488 # define RTStrmRewind RT_MANGLER(RTStrmRewind) 1489 # define RTStrmInputSetEchoChars RT_MANGLER(RTStrmInputSetEchoChars) 1488 1490 # define RTStrmSetMode RT_MANGLER(RTStrmSetMode) 1489 1491 # define RTStrmWriteEx RT_MANGLER(RTStrmWriteEx) -
trunk/include/iprt/stream.h
r51770 r54724 127 127 128 128 /** 129 * Returns the current echo mode. 130 * This works only for standard input streams. 131 * 132 * @returns iprt status code. 133 * @param pStream The stream. 134 * @param pfEchoChars Where to store the flag whether typed characters are echoed. 135 */ 136 RTR3DECL(int) RTStrmInputGetEchoChars(PRTSTREAM pStream, bool *pfEchoChars); 137 138 /** 139 * Changes the behavior for echoing inpit characters on the command line. 140 * This works only for standard input streams. 141 * 142 * @returns iprt status code. 143 * @param pStream The stream. 144 * @param fEchoChars Flag whether echoing typed characters is wanted. 145 */ 146 RTR3DECL(int) RTStrmInputSetEchoChars(PRTSTREAM pStream, bool fEchoChars); 147 148 /** 129 149 * Rewinds the stream. 130 150 * -
trunk/src/VBox/Runtime/r3/stream.cpp
r51770 r54724 59 59 #ifdef RT_OS_WINDOWS 60 60 # include <Windows.h> 61 #endif 62 #ifndef RT_OS_WINDOWS 63 # include <termios.h> 64 # include <unistd.h> 61 65 #endif 62 66 … … 462 466 463 467 return VINF_SUCCESS; 468 } 469 470 471 RTR3DECL(int) RTStrmInputGetEchoChars(PRTSTREAM pStream, bool *pfEchoChars) 472 { 473 int rc; 474 475 AssertPtrReturn(pStream, VERR_INVALID_HANDLE); 476 AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_HANDLE); 477 AssertPtrReturn(pfEchoChars, VERR_INVALID_POINTER); 478 479 int fh = fileno(pStream->pFile); 480 if (isatty(fh)) 481 { 482 #ifdef RT_OS_WINDOWS 483 DWORD dwMode; 484 HANDLE hCon = (HANDLE)_get_osfhandle(fh); 485 if (GetConsoleMode(hCon, &dwMode)) 486 *pfEchoChars = RT_BOOL(dwMode & ENABLE_ECHO_INPUT); 487 else 488 rc = RTErrConvertFromWin32(GetLastError()); 489 #else 490 struct termios Termios; 491 492 int rcPosix = tcgetattr(fh, &Termios); 493 if (!rcPosix) 494 *pfEchoChars = RT_BOOL(Termios.c_lflag & ECHO); 495 else 496 rc = RTErrConvertFromErrno(errno); 497 #endif 498 } 499 else 500 rc = VERR_INVALID_HANDLE; 501 502 return rc; 503 } 504 505 506 RTR3DECL(int) RTStrmInputSetEchoChars(PRTSTREAM pStream, bool fEchoChars) 507 { 508 int rc; 509 510 AssertPtrReturn(pStream, VERR_INVALID_HANDLE); 511 AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_HANDLE); 512 513 int fh = fileno(pStream->pFile); 514 if (isatty(fh)) 515 { 516 #ifdef RT_OS_WINDOWS 517 DWORD dwMode; 518 HANDLE hCon = (HANDLE)_get_osfhandle(fh); 519 if (GetConsoleMode(hCon, &dwMode)) 520 { 521 if (fEchoChars) 522 dwMode |= ENABLE_ECHO_INPUT; 523 else 524 dwMode &= ~ENABLE_ECHO_INPUT; 525 if (!SetConsoleMode(hCon, dwMode)) 526 rc = RTErrConvertFromWin32(GetLastError()); 527 } 528 else 529 rc = RTErrConvertFromWin32(GetLastError()); 530 #else 531 struct termios Termios; 532 533 int rcPosix = tcgetattr(fh, &Termios); 534 if (!rcPosix) 535 { 536 if (fEchoChars) 537 Termios.c_lflag |= ECHO; 538 else 539 Termios.c_lflag &= ~ECHO; 540 541 rcPosix = tcsetattr(fh, TCSAFLUSH, &Termios); 542 if (rcPosix != 0) 543 rc = RTErrConvertFromErrno(errno); 544 } 545 else 546 rc = RTErrConvertFromErrno(errno); 547 #endif 548 } 549 else 550 rc = VERR_INVALID_HANDLE; 551 552 return rc; 464 553 } 465 554
Note:
See TracChangeset
for help on using the changeset viewer.

