mirror of
https://github.com/apache/nuttx.git
synced 2026-06-03 22:20:31 +08:00
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:
committed by
Alan Carvalho de Assis
parent
3b69d09c80
commit
c1cb429a98
@@ -36,34 +36,6 @@
|
|||||||
* Pre-processor Definitions
|
* 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
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
@@ -264,38 +264,11 @@ static int readstream(FAR struct lib_instream_s *instream,
|
|||||||
|
|
||||||
while (ch != EOF && nbytes < (MAXRECORD_ASCSIZE - 1))
|
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')
|
if (ch == '\n' || ch == '\r')
|
||||||
{
|
{
|
||||||
*line = '\0';
|
*line = '\0';
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Only hex data goes into the line buffer */
|
/* Only hex data goes into the line buffer */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user