From 14fcacaf27451ab30d00c6d0722644a9636e3a1a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 12 Nov 2019 19:43:42 -0600 Subject: [PATCH] libs/libc/stdio/lib_libfgets.c: Because of how the function is defined, getline() canot be used on platforms that require CR-LF line terminations. --- libs/libc/stdio/lib_getdelim.c | 22 +++++++++++++++++++++- libs/libc/stdio/lib_libfgets.c | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libs/libc/stdio/lib_getdelim.c b/libs/libc/stdio/lib_getdelim.c index c01dc22a170..976049dce45 100644 --- a/libs/libc/stdio/lib_getdelim.c +++ b/libs/libc/stdio/lib_getdelim.c @@ -43,6 +43,24 @@ #include "libc.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Some environments may return CR as end-of-line, others LF, and others + * both. Because of the definition of the getline() function, it can handle + * only single character line terminators. + */ + +#undef HAVE_GETLINE +#if defined(CONFIG_EOL_IS_CR) +# define HAVE_GETLINE 1 +# define EOLCH '/r' +#elif defined(CONFIG_EOL_IS_LF) +# define HAVE_GETLINE 1 +# define EOLCH '/n' +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -184,7 +202,9 @@ errout: * ****************************************************************************/ +#ifdef HAVE_GETLINE ssize_t getline(FAR char **lineptr, size_t *n, FAR FILE *stream) { - return getdelim(lineptr, n, '\n', stream); + return getdelim(lineptr, n, EOLCH, stream); } +#endif diff --git a/libs/libc/stdio/lib_libfgets.c b/libs/libc/stdio/lib_libfgets.c index 4126d807382..4762aed3343 100644 --- a/libs/libc/stdio/lib_libfgets.c +++ b/libs/libc/stdio/lib_libfgets.c @@ -52,6 +52,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Some environments may return CR as end-of-line, others LF, and others * both. If not specified, the logic here assumes either (but not both) as * the default.