diff options
author | Kevin Krakauer <krakauer@google.com> | 2018-05-11 17:18:56 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-11 17:19:46 -0700 |
commit | 08879266fef3a67fac1a77f1ea133c3ac75759dd (patch) | |
tree | fc5abd338ca53845e2b0d55f129586bd5d333c42 /pkg/abi | |
parent | 987f7841a6ad8b77fe6a41cb70323517a5d2ccd1 (diff) |
sentry: Adds canonical mode support.
PiperOrigin-RevId: 196331627
Change-Id: Ifef4485f8202c52481af317cedd52d2ef48cea6a
Diffstat (limited to 'pkg/abi')
-rw-r--r-- | pkg/abi/linux/tty.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/abi/linux/tty.go b/pkg/abi/linux/tty.go index f9e641af9..84b6ccc87 100644 --- a/pkg/abi/linux/tty.go +++ b/pkg/abi/linux/tty.go @@ -14,9 +14,16 @@ package linux +import ( + "unicode/utf8" +) + const ( // NumControlCharacters is the number of control characters in Termios. NumControlCharacters = 19 + // disabledChar is used to indicate that a control character is + // disabled. + disabledChar = 0 ) // Termios is struct termios, defined in uapi/asm-generic/termbits.h. @@ -86,6 +93,27 @@ func (t *KernelTermios) FromTermios(term Termios) { t.ControlCharacters = term.ControlCharacters } +// IsTerminating returns whether c is a line terminating character. +func (t *KernelTermios) IsTerminating(c rune) bool { + if t.IsEOF(c) { + return true + } + switch byte(c) { + case disabledChar: + return false + case '\n', t.ControlCharacters[VEOL]: + return true + case t.ControlCharacters[VEOL2]: + return t.LEnabled(IEXTEN) + } + return false +} + +// IsEOF returns whether c is the EOF character. +func (t *KernelTermios) IsEOF(c rune) bool { + return utf8.RuneLen(c) == 1 && byte(c) == t.ControlCharacters[VEOF] && t.ControlCharacters[VEOF] != disabledChar +} + // Input flags. const ( IGNBRK = 0000001 |