You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2023/02/24 02:39:56 UTC
[nuttx] 02/02: stdio: lib_fgets convert \r\n to \n
This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 68ff73c5fb365f9780c1f28fd004d9e662f13044
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Feb 23 02:25:20 2023 +0800
stdio: lib_fgets convert \r\n to \n
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/stdio/lib_libfgets.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/libs/libc/stdio/lib_libfgets.c b/libs/libc/stdio/lib_libfgets.c
index 9e95b6884e..d3088f9fbc 100644
--- a/libs/libc/stdio/lib_libfgets.c
+++ b/libs/libc/stdio/lib_libfgets.c
@@ -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 */