diff --git a/sys/kern/kern_cons.c b/sys/kern/kern_cons.c index b5df465bebde..01254e376f67 100644 --- a/sys/kern/kern_cons.c +++ b/sys/kern/kern_cons.c @@ -407,6 +407,55 @@ cncheckc(void) return (-1); } +void +cngets(char *cp, size_t size, int visible) +{ + char *lp, *end; + int c; + + cngrab(); + + lp = cp; + end = cp + size - 1; + for (;;) { + c = cngetc() & 0177; + switch (c) { + case '\n': + case '\r': + cnputc(c); + *lp = '\0'; + cnungrab(); + return; + case '\b': + case '\177': + if (lp > cp) { + if (visible) { + cnputc(c); + cnputs(" \b"); + } + lp--; + } + continue; + case '\0': + continue; + default: + if (lp < end) { + switch (visible) { + case GETS_NOECHO: + break; + case GETS_ECHOPASS: + cnputc('*'); + break; + default: + cnputc(c); + break; + } + *lp++ = c; + } + } + } +} + void cnputc(int c) { diff --git a/sys/sys/cons.h b/sys/sys/cons.h index bd599c095092..79e2574895fc 100644 --- a/sys/sys/cons.h +++ b/sys/sys/cons.h @@ -121,6 +121,7 @@ void cngrab(void); void cnungrab(void); int cncheckc(void); int cngetc(void); +void cngets(char *, size_t, int); void cnputc(int); void cnputs(char *); int cnunavailable(void);