Add lttng_buffer_view util
[lttng-tools.git] / src / common / buffer-view.h
1 /*
2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #ifndef LTTNG_BUFFER_VIEW_H
19 #define LTTNG_BUFFER_VIEW_H
20
21 #include <stddef.h>
22 #include <stdint.h>
23
24 struct lttng_dynamic_buffer;
25
26 struct lttng_buffer_view {
27 const char *data;
28 size_t size;
29 };
30
31 /**
32 * Return a buffer view referencing a subset of the memory referenced by another
33 * view.
34 *
35 * @src Source view to reference
36 * @offset Offset to apply to the source memory content
37 * @len Length of the memory contents to reference. Passing -1 will
38 * cause the view to reference the whole view from the offset
39 * provided.
40 *
41 * Note that a buffer view never assumes the ownership of the memory it
42 * references.
43 */
44 struct lttng_buffer_view lttng_buffer_view_from_view(
45 const struct lttng_buffer_view *src, size_t offset,
46 ptrdiff_t len);
47
48 /**
49 * Return a buffer view referencing a subset of the memory referenced by a
50 * dynamic buffer.
51 *
52 * @src Source dynamic buffer to reference
53 * @offset Offset to apply to the source memory content
54 * @len Length of the memory contents to reference. Passing -1 will
55 * cause the view to reference the whole dynamic buffer from the
56 * offset provided.
57 *
58 * Note that a buffer view never assumes the ownership of the memory it
59 * references.
60 */
61 struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer(
62 const struct lttng_dynamic_buffer *src, size_t offset,
63 ptrdiff_t len);
64
65 #endif /* LTTNG_BUFFER_VIEW_H */
This page took 0.032221 seconds and 6 git commands to generate.