Fix: possible null dereference
[lttng-tools.git] / src / common / buffer-view.h
1 /*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_BUFFER_VIEW_H
9 #define LTTNG_BUFFER_VIEW_H
10
11 #include <stddef.h>
12 #include <stdint.h>
13 #include <common/macros.h>
14
15 struct lttng_dynamic_buffer;
16
17 struct lttng_buffer_view {
18 const char *data;
19 size_t size;
20 };
21
22 /**
23 * Return a buffer view referencing a subset of the memory referenced by a raw
24 * pointer.
25 *
26 * @src Source buffer to reference
27 * @offset Offset to apply to the source memory buffer
28 * @len Length of the memory contents to reference.
29 *
30 * Note that a buffer view never assumes the ownership of the memory it
31 * references.
32 */
33 LTTNG_HIDDEN
34 struct lttng_buffer_view lttng_buffer_view_init(
35 const char *src, size_t offset, ptrdiff_t len);
36
37 /**
38 * Return a buffer view referencing a subset of the memory referenced by another
39 * view.
40 *
41 * @src Source view to reference
42 * @offset Offset to apply to the source memory content
43 * @len Length of the memory contents to reference. Passing -1 will
44 * cause the view to reference the whole view from the offset
45 * provided.
46 *
47 * Note that a buffer view never assumes the ownership of the memory it
48 * references.
49 */
50 LTTNG_HIDDEN
51 struct lttng_buffer_view lttng_buffer_view_from_view(
52 const struct lttng_buffer_view *src, size_t offset,
53 ptrdiff_t len);
54
55 /**
56 * Return a buffer view referencing a subset of the memory referenced by a
57 * dynamic buffer.
58 *
59 * @src Source dynamic buffer to reference
60 * @offset Offset to apply to the source memory content
61 * @len Length of the memory contents to reference. Passing -1 will
62 * cause the view to reference the whole dynamic buffer from the
63 * offset provided.
64 *
65 * Note that a buffer view never assumes the ownership of the memory it
66 * references.
67 */
68 LTTNG_HIDDEN
69 struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer(
70 const struct lttng_dynamic_buffer *src, size_t offset,
71 ptrdiff_t len);
72
73 #endif /* LTTNG_BUFFER_VIEW_H */
This page took 0.029585 seconds and 4 git commands to generate.