getty.c: Handle Ctrl-U properly, erase line to beginning

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-08-30 17:19:43 +02:00
1 parent 907595d9ed
commit 2fe257b7af
1 file changed
+9
+9
View File
@@ -40,6 +40,7 @@
#define _PATH_LOGIN "/bin/login"
#endif
#define CTL(x) ((x) ^ 0100)
#define print(s) (void)write(STDOUT_FILENO, s, strlen(s))
@@ -203,6 +204,14 @@ static void do_getty(char *tty, char *name, size_t len)
np = name;
while ((ch = readch(tty)) != '\n') {
if (ch == CTL('U')) {
while (np > name) {
(void)write(1, "\b \b", 3);
np--;
}
continue;
}
if (np < name + len)
*np++ = ch;
}