common: compile libconfig as C++
[lttng-tools.git] / src / common / buffer-view.h
CommitLineData
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
7966af57
SM
16#ifdef __cplusplus
17extern "C" {
18#endif
19
01dc0eed
JG
20struct lttng_dynamic_buffer;
21
22struct lttng_buffer_view {
23 const char *data;
24 size_t size;
25};
26
b35aac84
JG
27/**
28 * Return a buffer view referencing a subset of the memory referenced by a raw
29 * pointer.
30 *
31 * @src Source buffer to reference
32 * @offset Offset to apply to the source memory buffer
33 * @len Length of the memory contents to reference.
34 *
35 * Note that a buffer view never assumes the ownership of the memory it
36 * references.
37 */
b35aac84
JG
38struct lttng_buffer_view lttng_buffer_view_init(
39 const char *src, size_t offset, ptrdiff_t len);
40
3e6e0df2
JG
41/**
42 * Checks if a buffer view is safe to access.
43 *
44 * After calling the buffer view creation functions, callers should verify
45 * if the resquested length (if any is explicitly provided) could be mapped
46 * to a new view.
b2530e4d
JG
47 *
48 * @view Buffer view to validate
3e6e0df2 49 */
3e6e0df2
JG
50bool lttng_buffer_view_is_valid(const struct lttng_buffer_view *view);
51
01dc0eed
JG
52/**
53 * Return a buffer view referencing a subset of the memory referenced by another
54 * view.
55 *
56 * @src Source view to reference
57 * @offset Offset to apply to the source memory content
58 * @len Length of the memory contents to reference. Passing -1 will
59 * cause the view to reference the whole view from the offset
60 * provided.
61 *
62 * Note that a buffer view never assumes the ownership of the memory it
63 * references.
64 */
65struct lttng_buffer_view lttng_buffer_view_from_view(
66 const struct lttng_buffer_view *src, size_t offset,
67 ptrdiff_t len);
68
69/**
70 * Return a buffer view referencing a subset of the memory referenced by a
71 * dynamic buffer.
72 *
73 * @src Source dynamic buffer to reference
74 * @offset Offset to apply to the source memory content
75 * @len Length of the memory contents to reference. Passing -1 will
76 * cause the view to reference the whole dynamic buffer from the
77 * offset provided.
78 *
79 * Note that a buffer view never assumes the ownership of the memory it
80 * references.
81 */
82struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer(
83 const struct lttng_dynamic_buffer *src, size_t offset,
84 ptrdiff_t len);
85
67d8e2ef
SM
86/**
87 * Verify that `buf` contains a string starting at `str` of length
88 * `len_with_null_terminator`.
89 *
90 * @buf The buffer view
91 * @str The start of the string
92 * @len_with_null_terminator Expected length of the string, including the
93 * NULL terminator.
94 */
67d8e2ef
SM
95bool lttng_buffer_view_contains_string(const struct lttng_buffer_view *buf,
96 const char *str,
97 size_t len_with_null_terminator);
98
7966af57
SM
99#ifdef __cplusplus
100}
101#endif
102
01dc0eed 103#endif /* LTTNG_BUFFER_VIEW_H */
This page took 0.039342 seconds and 4 git commands to generate.