syslog/ramlog: Remove the duplication of \n->\r\n conversion
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I5497f3ab40a55c5c08ba893e1186b93915cef03a
This commit is contained in:
parent
d8769cb4f0
commit
80157b8782
@ -87,7 +87,7 @@ static int ramlog_readnotify(FAR struct ramlog_dev_s *priv);
|
||||
#endif
|
||||
static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv,
|
||||
pollevent_t eventset);
|
||||
static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch);
|
||||
static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch);
|
||||
|
||||
/* Character driver methods */
|
||||
|
||||
@ -209,7 +209,7 @@ static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv,
|
||||
* Name: ramlog_addchar
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
|
||||
static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
|
||||
{
|
||||
irqstate_t flags;
|
||||
size_t nexthead;
|
||||
@ -218,6 +218,25 @@ static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
#ifdef CONFIG_RAMLOG_CRLF
|
||||
/* Ignore carriage returns */
|
||||
|
||||
if (ch == '\r')
|
||||
{
|
||||
leave_critical_section(flags);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Pre-pend a carriage before a linefeed */
|
||||
|
||||
if (ch == '\n')
|
||||
{
|
||||
ch = '\r';
|
||||
}
|
||||
|
||||
again:
|
||||
#endif
|
||||
|
||||
/* Calculate the write index AFTER the next byte is written */
|
||||
|
||||
nexthead = priv->rl_head + 1;
|
||||
@ -251,6 +270,15 @@ static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
|
||||
|
||||
priv->rl_buffer[priv->rl_head] = ch;
|
||||
priv->rl_head = nexthead;
|
||||
|
||||
#ifdef CONFIG_RAMLOG_CRLF
|
||||
if (ch == '\r')
|
||||
{
|
||||
ch = '\n';
|
||||
goto again;
|
||||
}
|
||||
#endif
|
||||
|
||||
leave_critical_section(flags);
|
||||
return OK;
|
||||
}
|
||||
@ -454,30 +482,6 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer,
|
||||
|
||||
ch = buffer[nwritten];
|
||||
|
||||
/* Ignore carriage returns */
|
||||
|
||||
#ifdef CONFIG_RAMLOG_CRLF
|
||||
if (ch == '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Pre-pend a carriage before a linefeed */
|
||||
|
||||
if (ch == '\n')
|
||||
{
|
||||
ret = ramlog_addchar(priv, '\r');
|
||||
if (ret < 0)
|
||||
{
|
||||
/* The buffer is full and nothing was saved. The remaining
|
||||
* data to be written is dropped on the floor.
|
||||
*/
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then output the character */
|
||||
|
||||
ret = ramlog_addchar(priv, ch);
|
||||
@ -789,28 +793,6 @@ int ramlog_putc(FAR struct syslog_channel_s *channel, int ch)
|
||||
|
||||
ramlog_initbuf();
|
||||
|
||||
#ifdef CONFIG_RAMLOG_CRLF
|
||||
/* Ignore carriage returns. But return success. */
|
||||
|
||||
if (ch == '\r')
|
||||
{
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* Pre-pend a newline with a carriage return */
|
||||
|
||||
if (ch == '\n')
|
||||
{
|
||||
ret = ramlog_addchar(priv, '\r');
|
||||
if (ret < 0)
|
||||
{
|
||||
/* The buffer is full and nothing was saved. */
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add the character to the RAMLOG */
|
||||
|
||||
ret = ramlog_addchar(priv, ch);
|
||||
|
Loading…
Reference in New Issue
Block a user