diff options
| author | guo <[email protected]> | 2021-10-14 12:01:39 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-14 12:01:39 +0800 |
| commit | 163b4648fc3f829e291805d5e5f681625ec95d2d (patch) | |
| tree | e5c7dd5b0991d361aa98bf73c8415c9078a06413 /components | |
| parent | 78db48ba78a1cc3f85f26b31f084887cd9698ee3 (diff) | |
| parent | 9fce0e5659af2210dffef48f83531fe3f46963cf (diff) | |
Merge pull request #5172 from mysterywolf/finsh
[shell] improve finsh_getchar
Diffstat (limited to 'components')
| -rw-r--r-- | components/finsh/shell.c | 12 | ||||
| -rw-r--r-- | components/finsh/shell.h | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 7b577db6b6..20f1bdef0f 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -142,20 +142,24 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode) shell->prompt_mode = prompt_mode; } -char finsh_getchar(void) +int finsh_getchar(void) { #ifdef RT_USING_DEVICE #ifdef RT_USING_POSIX return getchar(); #else char ch = 0; + rt_device_t device; RT_ASSERT(shell != RT_NULL); - if (shell->device == RT_NULL) + + device = shell->device; + if (device == RT_NULL) { - return -RT_ERROR; + return -1; /* EOF */ } - while (rt_device_read(shell->device, -1, &ch, 1) != 1) + + while (rt_device_read(device, -1, &ch, 1) != 1) rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER); return ch; diff --git a/components/finsh/shell.h b/components/finsh/shell.h index b671db0849..985d3b3fbd 100644 --- a/components/finsh/shell.h +++ b/components/finsh/shell.h @@ -93,7 +93,7 @@ rt_uint32_t finsh_get_echo(void); int finsh_system_init(void); void finsh_set_device(const char *device_name); const char *finsh_get_device(void); -char finsh_getchar(void); +int finsh_getchar(void); rt_uint32_t finsh_get_prompt_mode(void); void finsh_set_prompt_mode(rt_uint32_t prompt_mode); |
