nuttx/drivers/syslog/syslog_write.c
Alin Jerpelea e5b6305f4a drivers: Author Gregory Nutt: update licenses to Apache
Gregory Nutt has submitted the SGA and we can migrate the licenses
 to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-03-04 18:32:27 -08:00

131 lines
4.1 KiB
C

/****************************************************************************
* drivers/syslog/syslog_write.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include <nuttx/syslog/syslog.h>
#include "syslog.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: syslog_default_write
*
* Description:
* This provides a default write method for syslog devices that do not
* support multiple byte writes This functions simply loops, outputting
* one character at a time.
*
* Input Parameters:
* buffer - The buffer containing the data to be output
* buflen - The number of bytes in the buffer
*
* Returned Value:
* On success, the number of characters written is returned. A negated
* errno value is returned on any failure.
*
****************************************************************************/
static ssize_t syslog_default_write(FAR const char *buffer, size_t buflen)
{
size_t nwritten;
if (up_interrupt_context() || sched_idletask())
{
for (nwritten = 0; nwritten < buflen; nwritten++)
{
#ifdef CONFIG_SYSLOG_INTBUFFER
if (up_interrupt_context())
{
syslog_add_intbuffer(*buffer++);
}
else
#endif
{
DEBUGASSERT(g_syslog_channel->sc_force != NULL);
g_syslog_channel->sc_force(*buffer++);
}
}
}
#ifdef CONFIG_SYSLOG_WRITE
else if (g_syslog_channel->sc_write)
{
nwritten = g_syslog_channel->sc_write(buffer, buflen);
}
#endif
else
{
for (nwritten = 0; nwritten < buflen; nwritten++)
{
DEBUGASSERT(g_syslog_channel->sc_putc != NULL);
g_syslog_channel->sc_putc(*buffer++);
}
}
return nwritten;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: syslog_write
*
* Description:
* This is the low-level, multiple character, system logging interface.
*
* Input Parameters:
* buffer - The buffer containing the data to be output
* buflen - The number of bytes in the buffer
*
* Returned Value:
* On success, the number of characters written is returned. A negated
* errno value is returned on any failure.
*
****************************************************************************/
ssize_t syslog_write(FAR const char *buffer, size_t buflen)
{
#ifdef CONFIG_SYSLOG_INTBUFFER
if (!up_interrupt_context() && !sched_idletask())
{
/* Flush any characters that may have been added to the interrupt
* buffer.
*/
syslog_flush_intbuffer(g_syslog_channel, false);
}
#endif
return syslog_default_write(buffer, buflen);
}