Backport: lttng_buffer_view_is_valid, lttng_buffer_view_contains_string
[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
11#include <stddef.h>
12#include <stdint.h>
ff28f865 13#include <common/macros.h>
179ad61c 14#include <stdbool.h>
01dc0eed
JG
15
16struct lttng_dynamic_buffer;
17
18struct 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 */
34LTTNG_HIDDEN
35struct lttng_buffer_view lttng_buffer_view_init(
36 const char *src, size_t offset, ptrdiff_t len);
37
179ad61c
JR
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 * @view Buffer view to validate
46 */
47bool lttng_buffer_view_is_valid(const struct lttng_buffer_view *view);
48
01dc0eed
JG
49/**
50 * Return a buffer view referencing a subset of the memory referenced by another
51 * view.
52 *
53 * @src Source view to reference
54 * @offset Offset to apply to the source memory content
55 * @len Length of the memory contents to reference. Passing -1 will
56 * cause the view to reference the whole view from the offset
57 * provided.
58 *
59 * Note that a buffer view never assumes the ownership of the memory it
60 * references.
61 */
ff28f865 62LTTNG_HIDDEN
01dc0eed
JG
63struct lttng_buffer_view lttng_buffer_view_from_view(
64 const struct lttng_buffer_view *src, size_t offset,
65 ptrdiff_t len);
66
67/**
68 * Return a buffer view referencing a subset of the memory referenced by a
69 * dynamic buffer.
70 *
71 * @src Source dynamic buffer to reference
72 * @offset Offset to apply to the source memory content
73 * @len Length of the memory contents to reference. Passing -1 will
74 * cause the view to reference the whole dynamic buffer from the
75 * offset provided.
76 *
77 * Note that a buffer view never assumes the ownership of the memory it
78 * references.
79 */
ff28f865 80LTTNG_HIDDEN
01dc0eed
JG
81struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer(
82 const struct lttng_dynamic_buffer *src, size_t offset,
83 ptrdiff_t len);
84
179ad61c
JR
85/**
86 * Verify that `buf` contains a string starting at `str` of length
87 * `len_with_null_terminator`.
88 *
89 * @buf The buffer view
90 * @str The start of the string
91 * @len_with_null_terminator Expected length of the string, including the
92 * NULL terminator.
93 */
94bool 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 */
This page took 0.038246 seconds and 4 git commands to generate.