readline: Check the fd before echo

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi 2023-02-13 20:07:53 +08:00 committed by Xiang Xiao
parent a38c23f557
commit 1207977447

View File

@ -117,6 +117,13 @@ static void readline_putc(FAR struct rl_common_s *vtbl, int ch)
DEBUGASSERT(priv);
/* If outfd is a invalid fd, return directly. */
if (priv->outfd < 0)
{
return;
}
/* Loop until we successfully write a character (or until an unexpected
* error occurs).
*/
@ -149,6 +156,13 @@ static void readline_write(FAR struct rl_common_s *vtbl,
FAR struct readline_s *priv = (FAR struct readline_s *)vtbl;
DEBUGASSERT(priv && buffer && buflen > 0);
/* If outfd is a invalid fd, return directly. */
if (priv->outfd < 0)
{
return;
}
write(priv->outfd, buffer, buflen);
}
#endif