stdio: lib_fgets convert \r\n to \n

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-02-23 02:25:20 +08:00 committed by archer
parent cd74a1df22
commit 68ff73c5fb

View File

@ -142,6 +142,13 @@ FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream,
if (ch == '\n')
{
/* Convert \r\n to \n */
if (nch > 0 && buf[nch - 1] == '\r')
{
--nch;
}
if (keepnl)
{
/* Store newline is stored in the buffer */
@ -161,7 +168,7 @@ FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream,
{
/* End of file with no data? */
if (!nch)
if (nch == 0)
{
/* Yes.. return NULL as the end of file mark */