Move actions source files to src/common/actions directory
[lttng-tools.git] / src / common / buffer-view.c
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#include <common/buffer-view.h>
9#include <common/dynamic-buffer.h>
01dc0eed
JG
10#include <common/error.h>
11#include <assert.h>
12
b35aac84
JG
13LTTNG_HIDDEN
14struct lttng_buffer_view lttng_buffer_view_init(
15 const char *src, size_t offset, ptrdiff_t len)
16{
17 struct lttng_buffer_view view = { .data = src + offset, .size = len };
18 return view;
19}
20
ff28f865 21LTTNG_HIDDEN
01dc0eed
JG
22struct lttng_buffer_view lttng_buffer_view_from_view(
23 const struct lttng_buffer_view *src, size_t offset,
24 ptrdiff_t len)
25{
26 struct lttng_buffer_view view = { .data = NULL, .size = 0 };
27
28 assert(src);
29
30 if (offset > src->size) {
31 ERR("Attempt to create buffer view with invalid offset");
32 goto end;
33 }
34
35 if (len != -1 && len > (src->size - offset)) {
36 ERR("Attempt to create buffer view with invalid length");
37 goto end;
38 }
39
40 view.data = src->data + offset;
41 view.size = len == -1 ? (src->size - offset) : len;
42end:
43 return view;
44}
45
ff28f865 46LTTNG_HIDDEN
01dc0eed
JG
47struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer(
48 const struct lttng_dynamic_buffer *src, size_t offset,
49 ptrdiff_t len)
50{
51 struct lttng_buffer_view view = { .data = NULL, .size = 0 };
52
53 assert(src);
54
55 if (offset > src->size) {
56 ERR("Attempt to create buffer view with invalid offset");
57 goto end;
58 }
59
60 if (len != -1 && len > (src->size - offset)) {
61 ERR("Attempt to create buffer view with invalid length");
62 goto end;
63 }
64
65 view.data = src->data + offset;
66 view.size = len == -1 ? (src->size - offset) : len;
67end:
68 return view;
69}
This page took 0.049196 seconds and 4 git commands to generate.