This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 9f545e76c util/stream: Allow NULL to be used for read
9f545e76c is described below
commit 9f545e76cd00f45b4c50b2d1c1520fe132eaee25
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Feb 20 10:41:44 2024 +0100
util/stream: Allow NULL to be used for read
This modification allow reads that drop data.
Can be used to seek forward in the stream and
makes flush of in stream much simpler.
This modifies mem_istream_read implementation
accordingly.
---
util/stream/src/stream.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/util/stream/src/stream.c b/util/stream/src/stream.c
index 7fb9abeaa..e0ce166fe 100644
--- a/util/stream/src/stream.c
+++ b/util/stream/src/stream.c
@@ -24,29 +24,14 @@
int
istream_flush(struct in_stream *istream)
{
- uint8_t buf[12];
- int rc = 1;
- int count = 0;
+ int rc;
if (istream->vft->flush) {
rc = istream->vft->flush(istream);
} else {
- while (rc > 0) {
- rc = istream_available(istream);
- if (rc < 0) {
- break;
- } else if (rc == 0) {
- rc = count;
- break;
- } else {
- rc = istream_read(istream, buf, sizeof(buf));
- if (rc > 0) {
- count += rc;
- } else if (rc == 0) {
- rc = count;
- break;
- }
- }
+ rc = istream_available(istream);
+ if (rc > 0) {
+ rc = istream_read(istream, NULL, rc);
}
}
@@ -68,7 +53,9 @@ mem_istream_read(struct in_stream *istream, uint8_t *buf,
uint32_t count)
if (count > mem->size - mem->read_ptr) {
count = mem->size - mem->read_ptr;
}
- memcpy(buf, mem->buf + mem->read_ptr, count);
+ if (buf) {
+ memcpy(buf, mem->buf + mem->read_ptr, count);
+ }
mem->read_ptr += count;
return count;