Skip to content

Commit 9fce0e5

Browse files
committed
[shell] improve finsh_getchar
1 parent 33263d7 commit 9fce0e5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

components/finsh/shell.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,24 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
142142
shell->prompt_mode = prompt_mode;
143143
}
144144

145-
char finsh_getchar(void)
145+
int finsh_getchar(void)
146146
{
147147
#ifdef RT_USING_DEVICE
148148
#ifdef RT_USING_POSIX
149149
return getchar();
150150
#else
151151
char ch = 0;
152+
rt_device_t device;
152153

153154
RT_ASSERT(shell != RT_NULL);
154-
if (shell->device == RT_NULL)
155+
156+
device = shell->device;
157+
if (device == RT_NULL)
155158
{
156-
return -RT_ERROR;
159+
return -1; /* EOF */
157160
}
158-
while (rt_device_read(shell->device, -1, &ch, 1) != 1)
161+
162+
while (rt_device_read(device, -1, &ch, 1) != 1)
159163
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
160164

161165
return ch;

components/finsh/shell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ rt_uint32_t finsh_get_echo(void);
9393
int finsh_system_init(void);
9494
void finsh_set_device(const char *device_name);
9595
const char *finsh_get_device(void);
96-
char finsh_getchar(void);
96+
int finsh_getchar(void);
9797

9898
rt_uint32_t finsh_get_prompt_mode(void);
9999
void finsh_set_prompt_mode(rt_uint32_t prompt_mode);

0 commit comments

Comments
 (0)