[finsh] change return type of finsh_getchar from ch to int

finsh_getchar invokes getchar, who's return type is int, and return value may < 0, which means error occurred or EOF.
finsh should handle that situation properly, and inform user about the error.
This commit is contained in:
gbcwbz 2019-02-21 21:18:30 +08:00
parent 6a12704bc6
commit 860f8d954d
1 changed files with 14 additions and 4 deletions

View File

@ -134,12 +134,12 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
shell->prompt_mode = prompt_mode;
}
static char finsh_getchar(void)
static int finsh_getchar(void)
{
#ifdef RT_USING_POSIX
return getchar();
#else
char ch;
int ch;
RT_ASSERT(shell != RT_NULL);
while (rt_device_read(shell->device, -1, &ch, 1) != 1)
@ -279,7 +279,7 @@ const char *finsh_get_password(void)
static void finsh_wait_auth(void)
{
char ch;
int ch;
rt_bool_t input_finish = RT_FALSE;
char password[FINSH_PASSWORD_MAX] = { 0 };
rt_size_t cur_pos = 0;
@ -295,6 +295,11 @@ static void finsh_wait_auth(void)
{
/* read one character from device */
ch = finsh_getchar();
if (ch < 0)
{
rt_kprintf("finsh getchar error\n");
continue;
}
if (ch >= ' ' && ch <= '~' && cur_pos < FINSH_PASSWORD_MAX)
{
@ -460,7 +465,7 @@ static void shell_push_history(struct finsh_shell *shell)
void finsh_thread_entry(void *parameter)
{
char ch;
int ch;
/* normal is echo mode */
#ifndef FINSH_ECHO_DISABLE_DEFAULT
@ -503,6 +508,11 @@ void finsh_thread_entry(void *parameter)
while (1)
{
ch = finsh_getchar();
if (ch < 0)
{
rt_kprintf("finsh getchar error\n");
continue;
}
/*
* handle control key