wangchdo commented on code in PR #17267: URL: https://github.com/apache/nuttx/pull/17267#discussion_r2478444856
########## drivers/syslog/syslog_early.c: ########## @@ -0,0 +1,182 @@ +/**************************************************************************** + * drivers/syslog/syslog_early.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <stdio.h> +#include <syslog.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/init.h> +#include <nuttx/clock.h> +#include <nuttx/streams.h> +#include <nuttx/syslog/syslog.h> + +#include "syslog.h" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct early_syslograwstream_s +{ + struct lib_outstream_s common; + int last_ch; +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void early_syslog_putc(FAR struct lib_outstream_s *self, int ch) +{ + FAR struct early_syslograwstream_s *stream = (FAR void *)self; + + DEBUGASSERT(stream != NULL); + + stream->last_ch = ch; + if (ch == '\n') + { + up_putc('\r'); + } + + up_putc(ch); + + self->nput++; +} + +/**************************************************************************** + * Name: early_syslog_puts + ****************************************************************************/ + +static ssize_t early_syslog_puts(FAR struct lib_outstream_s *self, + FAR const void *buff, size_t len) +{ + FAR struct early_syslograwstream_s *stream = (FAR void *)self; + ssize_t nput = 0; + + DEBUGASSERT(stream != NULL); + + if (len <= 0) + { + return 0; + } + + stream->last_ch = ((FAR const char *)buff)[len - 1]; + + while (len-- > 0) + { + up_putc(((FAR const char *)buff)[nput++]); Review Comment: up_nputs() does't not have return value, also I found different platform implement up_nputs() differently, so we are not sure how many chars are put. Also I found up_nputs() is not related to CONFIG_ARCH_LOWPUTC, so I think up_putc is better here ########## drivers/syslog/syslog_early.c: ########## @@ -0,0 +1,182 @@ +/**************************************************************************** + * drivers/syslog/syslog_early.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <stdio.h> +#include <syslog.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/init.h> +#include <nuttx/clock.h> Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
