diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-02-23 10:35:16 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-02-28 08:51:31 +0100 |
commit | 9f69ac2a9dead44b62842081c8357b4dcd23dcaa (patch) | |
tree | 176daa49e3a86c37baff9f3f0643d22741eaf1b8 /cpukit | |
parent | termios: Protect raw input buffer with device lock (diff) | |
download | rtems-9f69ac2a9dead44b62842081c8357b4dcd23dcaa.tar.bz2 |
termios: Ignore carriage return early if desired
In case carriage return characters should be ignored in the input
(IGNCR), then drop them early before they reach the raw input buffer.
This makes it easier to calculate the content size of the raw input
buffer.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/libcsupport/src/termios.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c index f88494f15d..c1d6cd5297 100644 --- a/cpukit/libcsupport/src/termios.c +++ b/cpukit/libcsupport/src/termios.c @@ -1295,12 +1295,11 @@ iproc (unsigned char c, struct rtems_termios_tty *tty) c = tolower (c); if (c == '\r') { - if (tty->termios.c_iflag & IGNCR) - return 0; if (tty->termios.c_iflag & ICRNL) c = '\n'; - } else if ((c == '\n') && (tty->termios.c_iflag & INLCR)) { - c = '\r'; + } else if (c == '\n') { + if (tty->termios.c_iflag & INLCR) + c = '\r'; } if ((c != '\0') && (tty->termios.c_lflag & ICANON)) { @@ -1366,6 +1365,16 @@ siproc (unsigned char c, struct rtems_termios_tty *tty) return i; } +static int +siprocPoll (unsigned char c, rtems_termios_tty *tty) +{ + if (c == '\r' && (tty->termios.c_iflag & IGNCR) != 0) { + return 0; + } + + return siproc (c, tty); +} + /* * Fill the input buffer by polling the device */ @@ -1380,7 +1389,7 @@ fillBufferPoll (struct rtems_termios_tty *tty) if (n < 0) { rtems_task_wake_after (1); } else { - if (siproc (n, tty)) + if (siprocPoll (n, tty)) break; } } @@ -1408,7 +1417,7 @@ fillBufferPoll (struct rtems_termios_tty *tty) } rtems_task_wake_after (1); } else { - siproc (n, tty); + siprocPoll (n, tty); if (tty->ccount >= tty->termios.c_cc[VMIN]) break; if (tty->termios.c_cc[VMIN] && tty->termios.c_cc[VTIME]) @@ -1637,6 +1646,10 @@ rtems_termios_enqueue_raw_characters (void *ttyp, const char *buf, int len) unsigned int oldTail; unsigned int newTail; + if (c == '\r' && (tty->termios.c_iflag & IGNCR) != 0) { + continue; + } + rtems_termios_device_lock_acquire (ctx, &lock_context); head = tty->rawInBuf.Head; |