Commit | Line | Data |
---|---|---|
01dc0eed | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
01dc0eed | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
01dc0eed | 5 | * |
01dc0eed JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_BUFFER_VIEW_H | |
9 | #define LTTNG_BUFFER_VIEW_H | |
10 | ||
67d8e2ef SM |
11 | #include <common/macros.h> |
12 | #include <stdbool.h> | |
01dc0eed JG |
13 | #include <stddef.h> |
14 | #include <stdint.h> | |
15 | ||
16 | struct lttng_dynamic_buffer; | |
17 | ||
18 | struct lttng_buffer_view { | |
19 | const char *data; | |
20 | size_t size; | |
21 | }; | |
22 | ||
b35aac84 JG |
23 | /** |
24 | * Return a buffer view referencing a subset of the memory referenced by a raw | |
25 | * pointer. | |
26 | * | |
27 | * @src Source buffer to reference | |
28 | * @offset Offset to apply to the source memory buffer | |
29 | * @len Length of the memory contents to reference. | |
30 | * | |
31 | * Note that a buffer view never assumes the ownership of the memory it | |
32 | * references. | |
33 | */ | |
34 | LTTNG_HIDDEN | |
35 | struct lttng_buffer_view lttng_buffer_view_init( | |
36 | const char *src, size_t offset, ptrdiff_t len); | |
37 | ||
3e6e0df2 JG |
38 | /** |
39 | * Checks if a buffer view is safe to access. | |
40 | * | |
41 | * After calling the buffer view creation functions, callers should verify | |
42 | * if the resquested length (if any is explicitly provided) could be mapped | |
43 | * to a new view. | |
44 | */ | |
45 | LTTNG_HIDDEN | |
46 | bool lttng_buffer_view_is_valid(const struct lttng_buffer_view *view); | |
47 | ||
01dc0eed JG |
48 | /** |
49 | * Return a buffer view referencing a subset of the memory referenced by another | |
50 | * view. | |
51 | * | |
52 | * @src Source view 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 view from the offset | |
56 | * provided. | |
57 | * | |
58 | * Note that a buffer view never assumes the ownership of the memory it | |
59 | * references. | |
60 | */ | |
ff28f865 | 61 | LTTNG_HIDDEN |
01dc0eed JG |
62 | struct lttng_buffer_view lttng_buffer_view_from_view( |
63 | const struct lttng_buffer_view *src, size_t offset, | |
64 | ptrdiff_t len); | |
65 | ||
66 | /** | |
67 | * Return a buffer view referencing a subset of the memory referenced by a | |
68 | * dynamic buffer. | |
69 | * | |
70 | * @src Source dynamic buffer to reference | |
71 | * @offset Offset to apply to the source memory content | |
72 | * @len Length of the memory contents to reference. Passing -1 will | |
73 | * cause the view to reference the whole dynamic buffer from the | |
74 | * offset provided. | |
75 | * | |
76 | * Note that a buffer view never assumes the ownership of the memory it | |
77 | * references. | |
78 | */ | |
ff28f865 | 79 | LTTNG_HIDDEN |
01dc0eed JG |
80 | struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer( |
81 | const struct lttng_dynamic_buffer *src, size_t offset, | |
82 | ptrdiff_t len); | |
83 | ||
67d8e2ef SM |
84 | /** |
85 | * Verify that `buf` contains a string starting at `str` of length | |
86 | * `len_with_null_terminator`. | |
87 | * | |
88 | * @buf The buffer view | |
89 | * @str The start of the string | |
90 | * @len_with_null_terminator Expected length of the string, including the | |
91 | * NULL terminator. | |
92 | */ | |
93 | LTTNG_HIDDEN | |
94 | bool lttng_buffer_view_contains_string(const struct lttng_buffer_view *buf, | |
95 | const char *str, | |
96 | size_t len_with_null_terminator); | |
97 | ||
01dc0eed | 98 | #endif /* LTTNG_BUFFER_VIEW_H */ |