Allows getting pointer to an offset at a specific index within the circlebuf data. Useful for iterating through circlebuf data.
@@ -254,6 +254,20 @@ static inline void circlebuf_pop_back(struct circlebuf *cb, void *data,
cb->end_pos -= size;
}
+static inline void *circlebuf_data(struct circlebuf *cb, size_t idx)
+{
+ uint8_t *ptr = cb->data;
+ size_t offset = cb->start_pos + idx;
+
+ if (idx > cb->size)
+ return NULL;
+ if (offset >= cb->capacity)
+ offset -= cb->capacity;
+ return ptr + offset;
+}
#ifdef __cplusplus
#endif