diff options
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r-- | libbb/xfuncs.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 45650edba..98d3531d6 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -311,6 +311,43 @@ int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) | |||
311 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); | 311 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); |
312 | } | 312 | } |
313 | 313 | ||
314 | int FAST_FUNC set_termios_to_raw(int fd, struct termios *oldterm, int flags) | ||
315 | { | ||
316 | //TODO: lineedit, microcom and less might be adapted to use this too: | ||
317 | // grep for "tcsetattr" | ||
318 | |||
319 | struct termios newterm; | ||
320 | |||
321 | tcgetattr(fd, oldterm); | ||
322 | newterm = *oldterm; | ||
323 | |||
324 | /* Turn off buffered input (ICANON) | ||
325 | * Turn off echoing (ECHO) | ||
326 | * and separate echoing of newline (ECHONL, normally off anyway) | ||
327 | */ | ||
328 | newterm.c_lflag &= ~(ICANON | ECHO | ECHONL); | ||
329 | if (flags & TERMIOS_CLEAR_ISIG) { | ||
330 | /* dont recognize INT/QUIT/SUSP chars */ | ||
331 | newterm.c_lflag &= ~ISIG; | ||
332 | } | ||
333 | /* reads will block only if < 1 char is available */ | ||
334 | newterm.c_cc[VMIN] = 1; | ||
335 | /* no timeout (reads block forever) */ | ||
336 | newterm.c_cc[VTIME] = 0; | ||
337 | if (flags & TERMIOS_RAW_CRNL) { | ||
338 | /* dont convert CR to NL on input */ | ||
339 | newterm.c_iflag &= ~(IXON | ICRNL); | ||
340 | /* dont convert NL to CR on output */ | ||
341 | newterm.c_oflag &= ~(ONLCR); | ||
342 | } | ||
343 | if (flags & TERMIOS_RAW_INPUT) { | ||
344 | /* dont convert anything on input */ | ||
345 | newterm.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL); | ||
346 | } | ||
347 | |||
348 | return tcsetattr(fd, TCSANOW, &newterm); | ||
349 | } | ||
350 | |||
314 | pid_t FAST_FUNC safe_waitpid(pid_t pid, int *wstat, int options) | 351 | pid_t FAST_FUNC safe_waitpid(pid_t pid, int *wstat, int options) |
315 | { | 352 | { |
316 | pid_t r; | 353 | pid_t r; |