Skip to content

Commit 0d9e574

Browse files
committed
nsh: return EOF when nread is 0
If enable CONFIG NSH_CLE. When sh reads data and detects that nread is 0, return EOF and exit. Signed-off-by: yangsong8 <[email protected]>
1 parent caed82b commit 0d9e574

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

nshlib/nsh_session.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ int nsh_session(FAR struct console_stdio_s *pstate,
211211

212212
ret = cle_fd(pstate->cn_line, nsh_prompt(), LINE_MAX,
213213
INFD(pstate), OUTFD(pstate));
214-
if (ret < 0)
214+
if (ret == EOF)
215215
{
216216
dprintf(ERRFD(pstate), g_fmtcmdfailed, "nsh_session",
217217
"cle", NSH_ERRNO_OF(-ret));
218-
continue;
218+
ret = EXIT_SUCCESS;
219+
break;
219220
}
220221
#else
221222
/* Display the prompt string */

system/cle/cle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static int cle_getch(FAR struct cle_s *priv)
316316
if (nread == 0 || errcode != EINTR)
317317
{
318318
cledbg("ERROR: read from stdin failed: %d\n", errcode);
319-
return -EIO;
319+
return EOF;
320320
}
321321
}
322322
}
@@ -703,9 +703,9 @@ static int cle_editloop(FAR struct cle_s *priv)
703703
for (; ; )
704704
{
705705
ch = cle_getch(priv);
706-
if (ch < 0)
706+
if (ch == EOF)
707707
{
708-
return -EIO;
708+
return EOF;
709709
}
710710
else if (state != 0)
711711
{

0 commit comments

Comments
 (0)