diff --git a/sys/include/shell.h b/sys/include/shell.h index 513ab64e6b..d33eb9fe18 100644 --- a/sys/include/shell.h +++ b/sys/include/shell.h @@ -270,6 +270,31 @@ int shell_handle_input_line(const shell_command_t *commands, char *line); int shell_parse_file(const shell_command_t *commands, const char *filename, unsigned *line_nr); +/** + * @brief Read a single line from standard input into a buffer. + * + * In addition to copying characters, this routine echoes the line back to + * stdout and also supports primitive line editing. + * + * If the input line is too long, the input will still be consumed until the end + * to prevent the next line from containing garbage. + * + * We allow Unix (`\n`), DOS (`\r\n`), and Mac linebreaks (`\r`). + * QEMU transmits only a single `\r` == 13 on hitting enter ("-serial stdio"). + * DOS newlines are handled like hitting enter twice. + * + * @param buf Buffer where the input will be placed. + * @param size Size of the buffer. The maximum line length will be one less + * than size, to accommodate for the null terminator. + * The minimum buffer size is 1. + * + * @return length of the read line, excluding the terminator, if reading was + * successful. + * @return EOF, if the end of the input stream was reached. + * @return -ENOBUFS if the buffer size was exceeded. + */ +int readline(char *buf, size_t size); + #ifndef __cplusplus /** * @brief Define shell command diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 5b89a7fd00..621322aca2 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -439,30 +439,7 @@ static inline void new_line(void) } } -/** - * @brief Read a single line from standard input into a buffer. - * - * In addition to copying characters, this routine echoes the line back to - * stdout and also supports primitive line editing. - * - * If the input line is too long, the input will still be consumed until the end - * to prevent the next line from containing garbage. - * - * We allow Unix (\n), DOS (\r\n), and Mac linebreaks (\r). - * QEMU transmits only a single '\r' == 13 on hitting enter ("-serial stdio"). - * DOS newlines are handled like hitting enter twice. - * - * @param buf Buffer where the input will be placed. - * @param size Size of the buffer. The maximum line length will be one less - * than size, to accommodate for the null terminator. - * The minimum buffer size is 1. - * - * @return length of the read line, excluding the terminator, if reading was - * successful. - * @return EOF, if the end of the input stream was reached. - * @return -ENOBUFS if the buffer size was exceeded. - */ -int readline(char *buf, size_t size) /* needed externally by module shell_lock */ +int readline(char *buf, size_t size) { int curr_pos = 0; bool length_exceeded = false; diff --git a/sys/shell_lock/shell_lock.c b/sys/shell_lock/shell_lock.c index 8624671066..36bee52f7f 100644 --- a/sys/shell_lock/shell_lock.c +++ b/sys/shell_lock/shell_lock.c @@ -52,9 +52,6 @@ static bool _shell_is_locked = true; static ztimer_t _shell_auto_lock_ztimer; #endif -/* defined in shell.c */ -extern int readline(char *buf, size_t size); - static int _lock_handler(int argc, char **argv) { (void) argc;