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.

This commit is contained in:
Gregory Nutt 2019-11-12 19:43:42 -06:00
parent 0820af5f8d
commit 14fcacaf27
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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.