libc/hex2bin: Handle the line ending(\r, \n and \r\n) dynamically

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-11-17 03:02:36 +08:00 committed by Alan Carvalho de Assis
parent 3b69d09c80
commit c1cb429a98
2 changed files with 0 additions and 55 deletions

View File

@ -36,34 +36,6 @@
* 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.
*/
#if defined(CONFIG_EOL_IS_CR)
# undef CONFIG_EOL_IS_LF
# undef CONFIG_EOL_IS_BOTH_CRLF
# undef CONFIG_EOL_IS_EITHER_CRLF
#elif defined(CONFIG_EOL_IS_LF)
# undef CONFIG_EOL_IS_CR
# undef CONFIG_EOL_IS_BOTH_CRLF
# undef CONFIG_EOL_IS_EITHER_CRLF
#elif defined(CONFIG_EOL_IS_BOTH_CRLF)
# undef CONFIG_EOL_IS_CR
# undef CONFIG_EOL_IS_LF
# undef CONFIG_EOL_IS_EITHER_CRLF
#elif defined(CONFIG_EOL_IS_EITHER_CRLF)
# undef CONFIG_EOL_IS_CR
# undef CONFIG_EOL_IS_LF
# undef CONFIG_EOL_IS_BOTH_CRLF
#else
# undef CONFIG_EOL_IS_CR
# undef CONFIG_EOL_IS_LF
# undef CONFIG_EOL_IS_BOTH_CRLF
# define CONFIG_EOL_IS_EITHER_CRLF 1
#endif
/****************************************************************************
* Public Types
****************************************************************************/

View File

@ -264,38 +264,11 @@ static int readstream(FAR struct lib_instream_s *instream,
while (ch != EOF && nbytes < (MAXRECORD_ASCSIZE - 1))
{
#if defined(CONFIG_EOL_IS_LF)
if (ch == '\n')
{
*line = '\0';
return nbytes;
}
#elif defined(CONFIG_EOL_IS_BOTH_CRLF)
if (ch == '\r')
{
continue;
}
else if (ch == '\n')
{
*line = '\0';
return nbytes;
}
#elif defined(CONFIG_EOL_IS_CR)
if (ch == '\r')
{
*line = '\0';
return nbytes;
}
#elif defined(CONFIG_EOL_IS_EITHER_CRLF)
if (ch == '\n' || ch == '\r')
{
*line = '\0';
return nbytes;
}
#endif
/* Only hex data goes into the line buffer */