From: Jérémie Galarneau Date: Tue, 17 Oct 2017 21:18:14 +0000 (-0400) Subject: Add a util to create a buffer view from a raw buffer X-Git-Url: https://git.efficios.com/?a=commitdiff_plain;h=b35aac846ef0c3109e964f5babd59cdbabe373cc;p=deliverable%2Flttng-tools.git Add a util to create a buffer view from a raw buffer Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/buffer-view.c b/src/common/buffer-view.c index 4e84b0335..6053501ef 100644 --- a/src/common/buffer-view.c +++ b/src/common/buffer-view.c @@ -20,6 +20,14 @@ #include #include +LTTNG_HIDDEN +struct lttng_buffer_view lttng_buffer_view_init( + const char *src, size_t offset, ptrdiff_t len) +{ + struct lttng_buffer_view view = { .data = src + offset, .size = len }; + return view; +} + LTTNG_HIDDEN struct lttng_buffer_view lttng_buffer_view_from_view( const struct lttng_buffer_view *src, size_t offset, diff --git a/src/common/buffer-view.h b/src/common/buffer-view.h index d2b18f663..878b845bc 100644 --- a/src/common/buffer-view.h +++ b/src/common/buffer-view.h @@ -29,6 +29,21 @@ struct lttng_buffer_view { size_t size; }; +/** + * Return a buffer view referencing a subset of the memory referenced by a raw + * pointer. + * + * @src Source buffer to reference + * @offset Offset to apply to the source memory buffer + * @len Length of the memory contents to reference. + * + * Note that a buffer view never assumes the ownership of the memory it + * references. + */ +LTTNG_HIDDEN +struct lttng_buffer_view lttng_buffer_view_init( + const char *src, size_t offset, ptrdiff_t len); + /** * Return a buffer view referencing a subset of the memory referenced by another * view.