xiaoxiang781216 commented on a change in pull request #5039: URL: https://github.com/apache/incubator-nuttx/pull/5039#discussion_r772355857
########## File path: libs/libc/stream/lib_lzfcompress.c ########## @@ -0,0 +1,143 @@ +/**************************************************************************** + * libs/libc/stream/lib_lzfcompress.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 <unistd.h> +#include <nuttx/streams.h> + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lzfoutstream_flush + ****************************************************************************/ + +static int lzfoutstream_flush(FAR struct lib_outstream_s *this) +{ + FAR struct lib_lzfoutstream_s *stream = + (FAR struct lib_lzfoutstream_s *)this; + FAR struct lzf_header_s *header; + size_t outlen; + + if (stream->offset > 0) + { + outlen = lzf_compress(stream->in, stream->offset, + &stream->out[LZF_MAX_HDR_SIZE], + stream->offset, stream->state, &header); + if (outlen > 0) + { + stream->backend->puts(stream->backend, header, outlen); + } + + stream->offset = 0; + } + + return stream->backend->flush(stream->backend); +} + +/**************************************************************************** + * Name: lzfoutstream_puts + ****************************************************************************/ + +static int lzfoutstream_puts(FAR struct lib_outstream_s *this, + FAR const void *buf, int len) +{ + FAR struct lib_lzfoutstream_s *stream = + (FAR struct lib_lzfoutstream_s *)this; + FAR struct lzf_header_s *header; + FAR const char *ptr = buf; + size_t total = len; + size_t copyin; + size_t outlen; + int ret; + + while (total > 0) + { + copyin = stream->offset + total > CONFIG_STREAM_LZF_BLOG ? Review comment: it's better to define STREAM_LZF_SIZE equals (1 << CONFIG_STREAM_LZF_BLOG) -- 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]
