Skip to content

Commit d573815

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 d573815

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
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: 5 additions & 5 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
}
@@ -372,13 +372,13 @@ static void cle_setcursor(FAR struct cle_s *priv, int16_t column)
372372
int len;
373373
int off;
374374

375-
/* Sub prompt offset from real postion to get correct offset to execute */
375+
/* Sub prompt offset from real position to get correct offset to execute */
376376

377377
off = column - (priv->realpos - priv->coloffs);
378378

379379
cleinfo("column=%d offset=%d\n", column, off);
380380

381-
/* If cursor not move, retrun directly */
381+
/* If cursor not move, return directly */
382382

383383
if (off == 0)
384384
{
@@ -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)