common: add lttng_dynamic_array_set_count()
[lttng-tools.git] / src / common / sessiond-comm / payload-view.c
1 /*
2 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #include <common/buffer-view.h>
9 #include "payload-view.h"
10 #include "payload.h"
11 #include <stddef.h>
12
13 LTTNG_HIDDEN
14 struct lttng_payload_view lttng_payload_view_from_payload(
15 const struct lttng_payload *payload, size_t offset,
16 ptrdiff_t len)
17 {
18 return (struct lttng_payload_view) {
19 .buffer = lttng_buffer_view_from_dynamic_buffer(
20 &payload->buffer, offset, len),
21 ._fds = payload->_fds,
22 };
23 }
24
25 LTTNG_HIDDEN
26 struct lttng_payload_view lttng_payload_view_from_view(
27 struct lttng_payload_view *view, size_t offset,
28 ptrdiff_t len)
29 {
30 return (struct lttng_payload_view) {
31 .buffer = lttng_buffer_view_from_view(
32 &view->buffer, offset, len),
33 ._fds = view->_fds,
34 ._iterator.p_fds_position = &view->_iterator.fds_position,
35 };
36 }
37
38 LTTNG_HIDDEN
39 struct lttng_payload_view lttng_payload_view_from_dynamic_buffer(
40 const struct lttng_dynamic_buffer *buffer, size_t offset,
41 ptrdiff_t len)
42 {
43 return (struct lttng_payload_view) {
44 .buffer = lttng_buffer_view_from_dynamic_buffer(
45 buffer, offset, len)
46 };
47 }
48
49 LTTNG_HIDDEN
50 int lttng_payload_view_pop_fd(struct lttng_payload_view *view)
51 {
52 int ret = 0;
53 size_t fd_count;
54 size_t *pos;
55
56 if (!view) {
57 ret = -1;
58 goto end;
59 }
60
61 fd_count = lttng_dynamic_array_get_count(&view->_fds);
62 pos = view->_iterator.p_fds_position ? view->_iterator.p_fds_position :
63 &view->_iterator.fds_position;
64
65 if (*pos >= fd_count) {
66 ret = -1;
67 goto end;
68 }
69
70 ret = *((int *) lttng_dynamic_array_get_element(
71 &view->_fds, *pos));
72 (*pos)++;
73 end:
74 return ret;
75 }
This page took 0.060456 seconds and 4 git commands to generate.