summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2012-12-18 20:33:17 +1100
committerChris Johns <chrisj@rtems.org>2012-12-18 20:33:17 +1100
commit16de1256c028588c7e2159801d3c70a9a0e432b2 (patch)
treec86f2cbec8dc683ccef0fd90ad3cc1344b826548
parent39993d58eaf41159ee18110542a2c5f88e0df82c (diff)
Update the output buffer pointer when looping.
Fix a bug where the output buffer pointer is not updated when looping. Add read stats for the trace code.
-rw-r--r--rtl-obj-comp.c13
-rw-r--r--rtl-obj-comp.h9
2 files changed, 20 insertions, 2 deletions
diff --git a/rtl-obj-comp.c b/rtl-obj-comp.c
index 90cbda7..51f2df3 100644
--- a/rtl-obj-comp.c
+++ b/rtl-obj-comp.c
@@ -46,6 +46,7 @@ rtems_rtl_obj_comp_open (rtems_rtl_obj_comp_t* comp,
rtems_rtl_set_error (ENOMEM, "no memory for compressor buffer");
return false;
}
+ comp->read = 0;
return true;
}
@@ -59,6 +60,7 @@ rtems_rtl_obj_comp_close (rtems_rtl_obj_comp_t* comp)
comp->level = 0;
comp->size = 0;
comp->offset = 0;
+ comp->read = 0;
}
void
@@ -73,6 +75,7 @@ rtems_rtl_obj_comp_set (rtems_rtl_obj_comp_t* comp,
comp->compression = compression;
comp->offset = offset;
comp->level = 0;
+ comp->read = 0;
}
bool
@@ -80,6 +83,8 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp_t* comp,
void* buffer,
size_t length)
{
+ uint8_t* bin = buffer;
+
if (!comp->cache)
{
rtems_rtl_set_error (EINVAL, "not open");
@@ -99,7 +104,7 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp_t* comp,
if (buffer_level)
{
- memcpy (buffer, comp->buffer, buffer_level);
+ memcpy (bin, comp->buffer, buffer_level);
if ((comp->level - buffer_level) != 0)
{
@@ -108,8 +113,10 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp_t* comp,
comp->level - buffer_level);
}
+ bin += buffer_level;
length -= buffer_level;
comp->level -= buffer_level;
+ comp->read += buffer_level;
}
if (length)
@@ -135,7 +142,8 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp_t* comp,
if (in_length != block_size)
{
- rtems_rtl_set_error (EIO, "compressed read failed");
+ rtems_rtl_set_error (EIO, "compressed read failed: bs=%u in=%u",
+ block_size, in_length);
return false;
}
@@ -155,6 +163,7 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp_t* comp,
return false;
}
break;
+
default:
rtems_rtl_set_error (EINVAL, "bad compression type");
return false;
diff --git a/rtl-obj-comp.h b/rtl-obj-comp.h
index eb4ba55..6034602 100644
--- a/rtl-obj-comp.h
+++ b/rtl-obj-comp.h
@@ -53,9 +53,18 @@ typedef struct rtems_rtl_obj_cpmp_s
size_t size; /**< The size of the output buffer. */
size_t level; /**< The amount of data in the buffer. */
uint8_t* buffer; /**< The buffer */
+ uint32_t read; /**< The amount of data read. */
} rtems_rtl_obj_comp_t;
/**
+ * Return the input level.
+ */
+static inline uint32_t rtems_rtl_obj_comp_input (rtems_rtl_obj_comp_t* comp)
+{
+ return comp->read;
+}
+
+/**
* Open a compressor allocating the output buffer.
*
* @param comp The compressor to initialise.